随机森林预测值
Random forest prediction values
有这样的数据集:
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])
我没有这方面的经验,所以不太理解预测。
- 我该如何解释它们?
- 是否有任何方法可以将预测限制为 res 列值([0-6] 之间的整数)?
谢谢
正如@MaxNoe 所说,我对模型有误解。我正在使用 回归 来预测 离散变量 。
RandomForestClassifier 给出了预期的输出。
有这样的数据集:
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])
我没有这方面的经验,所以不太理解预测。
- 我该如何解释它们?
- 是否有任何方法可以将预测限制为 res 列值([0-6] 之间的整数)?
谢谢
正如@MaxNoe 所说,我对模型有误解。我正在使用 回归 来预测 离散变量 。
RandomForestClassifier 给出了预期的输出。