【问题标题】:Random forest prediction values随机森林预测值
【发布时间】:2021-03-21 04:36:57
【问题描述】:

拥有这样的数据集:

         y     x    size    type    total_neighbours    res
113040  29  1204      15       3                   2      0
66281   52   402       9       3                   3      0
32296   21  1377      35       0                   3      0
48367    3   379     139       0                   4      0
33501    1    66      17       0                   3      0
... ... ... ... ... ... ...
131230  39  1002     439       3                   4      6
131237  40  1301      70       1                   2      1
131673  26  1124     365       1                   2      1
131678  27  1002     629       3                   3      6
131684  28  1301      67       1                   2      1

我想用随机森林算法来预测res的值(res列只能取[0-6]之间的整数值)

我是这样做的:

labels = np.array(features['res'])
features= features.drop('res', axis = 1)
features = np.array(features)

train_features, test_features, train_labels, test_labels = train_test_split(features, labels, test_size = 0.25,
                                                                           random_state = 42)

rf = RandomForestRegressor(n_estimators= 1000, random_state=42)

rf.fit(train_features, train_labels);
predictions = rf.predict(test_features)

我得到的预测如下:

array([1.045e+00, 4.824e+00, 4.608e+00, 1.200e-01, 5.982e+00, 3.660e-01,
       4.659e+00, 5.239e+00, 5.982e+00, 1.524e+00])

我没有这方面的经验,所以我不太了解预测。

  1. 我如何解释它们?
  2. 有没有办法将预测限制在 res 列值([0-6] 之间的整数)?

谢谢

【问题讨论】:

  • 你想做多类分类,而不是回归。使用RandomForestClassifier
  • 您也可以只对值进行四舍五入,这也可能有意义。

标签: python-3.x scikit-learn random-forest


【解决方案1】:

正如@MaxNoe 所说,我对模型有误解。我使用回归来预测离散变量

RandomForestClassifier 给出了预期的输出。

【讨论】:

    猜你喜欢
    • 2014-08-07
    • 2019-07-22
    • 2019-05-04
    • 2019-07-10
    • 2021-06-23
    • 2019-02-19
    • 2016-04-09
    • 2014-03-23
    相关资源
    最近更新 更多