Having a dataset like this:
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
I would like to use random forest algorithm to predict the value of res column (res column can only take integer values between [0-6])
I'm doing it like this:
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)
The prediction I get are the following:
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])
I have no experience on this field so I don't quite understand the predictions.
Thanks
As @MaxNoe said, I had a misconception about the model. I was using a regression to predict a discrete variable .
RandomForestClassifier is giving the expected output.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.