【问题标题】:split() missing 1 required positional argument: 'y'split() 缺少 1 个必需的位置参数:'y'
【发布时间】:2020-01-06 16:26:25
【问题描述】:

我正在尝试预测塑料流体的粘度,我使用随机森林回归器和 K-Fold 交叉验证来训练我的数据。

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() missing 1 required positional argument: 'y'

【问题讨论】:

    标签: python machine-learning scikit-learn


    【解决方案1】:

    正如错误所暗示的,StratifiedKFoldsplit 方法需要训练数据中的 Xy 以生成验证集和测试集:

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

    【讨论】:

    • 当我添加 y 时,我收到了这条消息:
    • ValueError: 支持的目标类型是:('binary', 'multiclass')。改为“连续”。
    • 不确定没有更多细节/数据@sb ...希望这有助于你从这里继续。不要忘记您可以投票和接受:)
    猜你喜欢
    • 2020-11-15
    • 2017-05-28
    • 2021-10-19
    • 1970-01-01
    • 2020-10-12
    • 2022-01-18
    • 2019-06-07
    • 2019-02-04
    • 1970-01-01
    相关资源
    最近更新 更多