【发布时间】:2017-12-14 17:50:13
【问题描述】:
我正在使用 cross_val_score 方法评估 desicion_tree_regressor 预测模型。问题是,分数似乎是负数,我真的不明白为什么。
这是我的代码:
all_depths = []
all_mean_scores = []
for max_depth in range(1, 11):
all_depths.append(max_depth)
simple_tree = DecisionTreeRegressor(max_depth=max_depth)
cv = KFold(n_splits=2, shuffle=True, random_state=13)
scores = cross_val_score(simple_tree, df.loc[:,'system':'gwno'], df['gdp_growth'], cv=cv)
mean_score = np.mean(scores)
all_mean_scores.append(np.mean(scores))
print("max_depth = ", max_depth, scores, mean_score, sem(scores))
结果:
max_depth = 1 [-0.45596988 -0.10215719] -0.2790635315340 0.176906344162
max_depth = 2 [-0.5532268 -0.0186984] -0.285962600541 0.267264196259
max_depth = 3 [-0.50359311 0.31992411] -0.0918345038141 0.411758610421 max_depth = 4 [-0.57305355 0.21154193] -0.180755811466 0.392297741456 max_depth = 5 [-0.58994928 0.21180425] -0.189072515181 0.400876761509 max_depth = 6 [-0.71730634 0.22139877] -0.247953784441 0.469352551213 max_depth = 7 [-0.60118621 0.22139877] -0.189893720551 0.411292487323 max_depth = 8 [-0.69635044 0.13976584] -0.278292298411 0.418058142228 max_depth = 9 [-0.78917478 0.30970763] -0.239733577455 0.549441204178 max_depth = 10 [-0.76098227 0.34512503] -0.207928623044 0.553053649792
我的问题如下:
1) 分数返回 MSE 对吗?如果是,怎么会是负数?
2) 我有约 40 个观察值和约 70 个变量的小样本。这可能是问题吗?
提前致谢。
【问题讨论】:
标签: python pandas machine-learning scikit-learn