【问题标题】:ValueError: Found array with dim 3. Estimator expected <= 2. when using numpy arraysValueError:找到暗淡3的数组。估计器预期<= 2。使用numpy数组时
【发布时间】:2022-01-16 14:35:46
【问题描述】:

我有两个 numpy 数组

import numpy as np

temp_1 = np.array([['19.78018766'],
 ['19.72487359'],
 ['19.70280336'],
 ['19.69589641'],
 ['19.69746018']])

temp 2 = np.array([['43.8'],
 ['43.9'],
 ['44'],
 ['44.1'],
 ['44.2']])

我正在准备X = np.stack((temp_1,temp_2), axis=-1) 看起来像这样

 X = [[['19.78018766' '43.8']]
 [['19.72487359' '43.9']]
 [['19.70280336' '44']]
 [['19.69589641' '44.1']]
 [['19.69746018' '44.2']]]

我还有另一个变量 Y,它也是一个 numpy 数组

Y = np.array([['28.78'],
     ['32.72'],
     ['15.70'],
     ['32.69'],
     ['55.69']])

我正在尝试运行 RandomforestRegressor 模型

在哪里

from sklearn.ensemble import RandomForestRegressor
clf = RandomForestRegressor()
clf.fit(X,Y)

但是,它给了我这个错误

ValueError: Found array with dim 3. Estimator expected <= 2.

【问题讨论】:

    标签: python numpy scikit-learn random-forest


    【解决方案1】:

    这是因为XY 的形状不同(5, 1, 2) != (5,1)

    只需将您的 X 数据重塑为您拥有的样本数量

    # In this example 5 samples
    X = X.reshape(5, 2)
    

    【讨论】:

      猜你喜欢
      • 2019-06-01
      • 2016-11-28
      • 2021-04-16
      • 2019-07-19
      • 2018-01-16
      • 2020-07-10
      • 2016-04-30
      • 2020-10-04
      • 2016-04-24
      相关资源
      最近更新 更多