【发布时间】:2020-02-06 07:00:17
【问题描述】:
我目前正在尝试使用 RandomForest 进行预测,同时还使用 k 折交叉验证来最小化我对 min_samples_leaf 的交叉验证错误。我目前在设置代码时遇到问题,因为当我到达train_x = x[train_index] 时一直出错。我得到的错误如下所示。
from sklearn import model_selection
kf = model_selection.KFold(n_splits=5)
x = train
y = test
for m in range(0, 10): # vary min_samples_leaf
dtr = ensemble.RandomForestRegressor(n_estimators = 15, min_samples_leaf = m, max_features = 10, criterion = 'mse')
for train_index, test_index in kf.split(x):
print("TRAIN:", train_index, "TEST:", test_index)
train_x = x[train_index]
train_y = y[test_index]
regr = dtr.fit(train_x, train_y)
密钥错误:
None of [Int64Index([15546, 15547, 15548, 15549, 15550, 15551, 15552, 15553, 15554,\n 15555,\n ...\n 77718, 77719, 77720, 77721, 77722, 77723, 77724, 77725, 77726,\n 77727],\n dtype='int64', length=62182)] are in the [columns]
【问题讨论】:
标签: python machine-learning scikit-learn random-forest cross-validation