我正在尝试预测塑料流体的粘度,我使用了随机森林回归器和K折交叉验证来训练我的数据。
RFR = RandomForestRegressor(n_estimators = 2000,max_depth = 20, n_jobs=-1, random_state = 0)scores = []Kfold = StratifiedKFold(n_splits=10, random_state = 0, shuffle=True)for i in range(10): result = next(Kfold.split(X_train), None) input_train = df.iloc[result[0]] input_test = df.iloc[result[1]] output_train = y.iloc[result[0]] output_test = y.iloc[result[1]] model = RFR.fit(input_train,output_train) predictions = RFR.predict(input_test) scores.append(model.score(input_test,output_test))print('Scores from each Iteration: ', scores)print('Average K-Fold Score :' , np.mean(scores))
我想对我的模型进行10折交叉验证的训练,但得到了以下错误信息:
TypeError: split() 缺少一个必需的位置参数: 'y'
回答:
正如错误提示所示,StratifiedKFold
的split
方法期望从训练数据中同时获得X
和y
,以便生成验证和测试集:
split(self, X, y, groups=None)