0
点赞
收藏
分享

微信扫一扫

预测二手车的残值

海牙秋天 2022-02-18 阅读 245
  1. 残值(二手车)预估(24个)

估值因素 :

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

    1. 农业机械
      1. 履带式拖拉机
      2. 大轮拖
      3. 中拖
      4. 小麦机
      5. 玉米机
      6. 免耕播种机
      7. 打捆机
      8. 旋耕机
      9. 深松机
      10. 液压翻转犁          
    2. 特专车辆
      1. 洗扫车
      2. 压缩式垃圾车
      3. 绿化喷洒车
      4. 多功能吸尘扫路车
      5. 车厢可卸式垃圾车
      6. 自卸式垃圾车
      7. 压缩式垃圾车
      8. 车厢可卸式垃圾车
      9. 压缩式对接垃圾车
      10. 洒水车
      11. 清洗车
      12. 抑尘车
      13. 摆臂式垃圾车
      14. 吸尘车
import h2o
import numpy as np
from h2o.estimators import H2OGradientBoostingEstimator

h2o.init()
from flask import Flask, request, jsonify
app = Flask(__name__)
from h2o.estimators.glm import H2OGeneralizedLinearEstimator
from 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()
举报

相关推荐

0 条评论