欢迎您访问365答案网,请分享给你的朋友!
生活常识 学习资料

预测二手车的残值

时间:2023-05-18
残值(二手车)预估(24个)

估值因素 :

包括公里数、使用年数、出场时间、维修次数…

农业机械 履带式拖拉机大轮拖中拖小麦机玉米机免耕播种机打捆机旋耕机深松机液压翻转犁          特专车辆 洗扫车压缩式垃圾车绿化喷洒车多功能吸尘扫路车车厢可卸式垃圾车自卸式垃圾车压缩式垃圾车车厢可卸式垃圾车压缩式对接垃圾车洒水车清洗车抑尘车摆臂式垃圾车吸尘车

import h2oimport numpy as npfrom h2o.estimators import H2OGradientBoostingEstimatorh2o.init()from flask import Flask, request, jsonifyapp = Flask(__name__)from h2o.estimators.glm import H2OGeneralizedLinearEstimatorfrom h2o.estimators.deeplearning import H2ODeepLearningEstimator# dataset_url = 'E:/PyCharm_workspace/demo/h2o/regression/cars.csv'# trained_model = 'E:/tmp/mymodel/usedCar_GBM_model'# http://127.0.0.1:5000/model/usedCar/?dataset_url=E:/PyCharm_workspace/demo/h2o/regression/cars.csv&trained_model=E:/tmp/mymodel/usedCar_GBM_model@app.route('/model/usedCar/')def classification_example(): dataset_url = request.args.get('dataset_url') trained_model = request.args.get('trained_model') cars = h2o.import_file(dataset_url) r = cars[0].runif() train = cars[r > .2] valid = cars[r <= .2] response_col = "economy" distribution = "gaussian" # 根据车的“名称”、“生产年份”、“重量”、”加速度“、”马力“ ===》”车当前的价值(economy)“ predictors = ["name","year","weight","acceleration","power"] ########################### 训练过程 ############################################################## # # 可以选择的算法有:梯度提升机(GBM)、深度学习 # # gbm = H2OGradientBoostingEstimator(nfolds=3, distribution=distribution, fold_assignment="Random") # gbm = H2ODeepLearningEstimator(adaptive_rate=True, epochs=800) # # train_model =gbm.train(x=predictors, y=response_col, training_frame=train, validation_frame=valid) # gbm.plot(timestep="AUTO", metric="AUTO",save_plot_path='/temp') # # # # 保存模型 # model_path = h2o.save_model(model=train_model, path="/tmp/mymodel", force=True) # # 打印出保存模型的路径: # print("模型保存在:", model_path) ########################### 应用过程 ############################################################## # load the model,加载模型,要注意模型的位置是/而不是 saved_model = h2o.load_model(trained_model) # saved_model = h2o.load_model("E:/tmp/mymodel/GBM_model_python_1645102695969_1") train_model= saved_model test_file = 'cars_test.csv' test_prostate = h2o.import_file(test_file) # predict using the model and the testing dataset predict = train_model.predict(test_prostate) ## Creating list array from h2o frame column residual_value = np.array(h2o.as_list(predict['predict'])).tolist() # View a summary of the prediction # head()返回对象的前n行 print(predict.head(100)) print(residual_value) t = { 'code': 200, 'residual_value': residual_value } return jsonify(t)if __name__ == "__main__": app.run()

Copyright © 2016-2020 www.365daan.com All Rights Reserved. 365答案网 版权所有 备案号:

部分内容来自互联网,版权归原作者所有,如有冒犯请联系我们,我们将在三个工作时内妥善处理。