【问题标题】:ValueError: error_score must be the string 'raise' or a numeric value. (Hint: if using 'raise', please make sure that it has been spelled correctly.)ValueError:error_score 必须是字符串“raise”或数值。 (提示:如果使用“raise”,请确保拼写正确。)
【发布时间】:2020-11-24 07:29:08
【问题描述】:

我正在研究 Python 中的决策树回归。

遇到一个奇怪的错误:

ValueError: error_score must be the string 'raise' or a numeric value. (Hint: if using 'raise', please make sure that it has been spelled correctly.)

我的数据框大约有 330000 * 91 列。

我的代码如下所示:

# Read data
y = my_train2.iloc[:,0]
x = my_train2.iloc[:, 1:93]

(x_train, x_test, y_train, y_test) = cv.train_test_split(x, y, test_size=.20)
# Instantiate dt
dt = DecisionTreeRegressor(# max_depth = 8,
                       min_samples_leaf = 1,
                       random_state = 1)

# Fit dt to the training set
dt.fit(x_train, y_train)

下面这个块给出一个错误

from sklearn.model_selection import cross_val_score
# Compute the array containing the 10-folds CV MSEs
MSE_CV_scores = - cross_val_score(dt, x_train, y_train, cv=10, 
                              scoring='neg_mean_squared_error', 
                              n_jobs=-1) 

# Compute the 10-folds CV RMSE
RMSE_CV = (MSE_CV_scores.mean())**(1/2)

# Print RMSE_CV
print('CV RMSE: {:.2f}'.format(RMSE_CV))

如果需要,我可以在这里打印每列的类。

谢谢!

【问题讨论】:

    标签: python scikit-learn decision-tree


    【解决方案1】:

    可能与您的 scikit-learn 的版本有关。我猜这个错误出现在 0.22。也许...降级到0.21再试一次

    【讨论】:

      猜你喜欢
      • 2019-07-07
      • 2020-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-18
      • 2019-10-15
      • 2021-11-13
      • 2022-07-14
      相关资源
      最近更新 更多