split() 缺少一个必需的位置参数: ‘y’

我正在尝试预测塑料流体的粘度,我使用了随机森林回归器和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'

回答:

正如错误提示所示,StratifiedKFoldsplit方法期望从训练数据中同时获得Xy,以便生成验证和测试集:

split(self, X, y, groups=None)

Related Posts

在使用k近邻算法时,有没有办法获取被使用的“邻居”?

我想找到一种方法来确定在我的knn算法中实际使用了哪些…

Theano在Google Colab上无法启用GPU支持

我在尝试使用Theano库训练一个模型。由于我的电脑内…

准确性评分似乎有误

这里是代码: from sklearn.metrics…

Keras Functional API: “错误检查输入时:期望input_1具有4个维度,但得到形状为(X, Y)的数组”

我在尝试使用Keras的fit_generator来训…

如何使用sklearn.datasets.make_classification在指定范围内生成合成数据?

我想为分类问题创建合成数据。我使用了sklearn.d…

如何处理预测时不在训练集中的标签

已关闭。 此问题与编程或软件开发无关。目前不接受回答。…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注