【问题标题】:ValueError: Found array with dim 3. Estimator expected <= 2. How to use it on Random Forest Regressor?ValueError: Found array with dim 3. Estimator expected <= 2. 如何在随机森林回归器上使用它?
【发布时间】:2020-11-27 22:01:42
【问题描述】:

我已通过 csv 文件上传并尝试从整个 csv 文件中进行预测。我使用的模型是随机森林回归器来预测。我无法预测整个 csv 文件遇到这个 ValueError: Found array with dim 3. Estimator expected

@app.route("/multiple",methods=["GET","POST"])
@cross_origin()
def multiple():
if request.method == 'POST':
    file=request.form["csvfile"]
    with open(file) as csvfile:
        csv_reader=csv.reader(csvfile,delimiter=",")
        next(csv_reader,None) 
        data=[]
        for line in csv_reader:
            data.append(line)
            mul_prediction=model.predict([(np.array(data))])
            result=round(mul_prediction[0])

【问题讨论】:

    标签: python csv flask prediction


    【解决方案1】:

    RandomForestRegressor.predict 需要一个二维数组。当您将数据数组放入model.predict([(np.array(data))]) 中的封闭列表中时,您将2 维数据隐式转换为3 维数组。相反,只需使用model.predict(np.array(data))

    【讨论】:

      猜你喜欢
      • 2020-09-07
      • 2019-12-02
      • 2020-06-30
      • 2018-10-05
      • 2019-12-06
      • 1970-01-01
      • 2023-03-14
      • 2014-08-11
      • 2017-06-26
      相关资源
      最近更新 更多