You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于scikit-learn中neg_root_mean_squared_error转RMSE的疑问

问题:将负RMSE转换为正值表述是否正确?

我在评估模型时,把scoring参数设为neg_root_mean_squared_error,得到的结果确实是负值,这符合预期。但我习惯用正值的RMSE(值越小模型越好),请问把模型的RMSE表述为+0.0725是否正确?

代码示例

crossvalidation_Decision_Trees = KFold(n_splits=4, random_state=0,shuffle=True) 
model2 = new_model.fit(X_normalized, y_for_normalized)
scores_D_Trees = cross_val_score(model2, X_normalized,y_for_normalized, scoring='neg_root_mean_squared_error', cv=crossvalidation_Decision_Trees,
 n_jobs=1)
    

print("\n\nDecision Trees"+": RMSE for every fold: " + str(scores_D_Trees))
print('\033[1m'"Decision Trees"+'\033[1m'": Average RMSE for all the folds: " + str(np.mean(scores_D_Trees)) + '\033[0m'+ ", STD: " + str(np.std(scores_D_Trees)))

输出结果

Decision Trees: RMSE for every fold: [-0.0413202  -0.08435709 -0.08474064 -0.07967769]
Decision Trees: Average RMSE for all the folds: -0.07252390274931717, STD: 0.01812540303759248

回答

完全正确。scikit-learn里的neg_root_mean_squared_error本质就是取RMSE的负值,目的是适配sklearn中"分数越高模型越好"的评估逻辑——因为RMSE本身是越小越好,取负之后就变成越大越好,符合cross_val_score的排序规则。

你只需要把得到的负值结果取绝对值,就能得到常规意义上的正值RMSE。比如你得到的平均结果是-0.0725,转换成+0.0725完全没问题,这就是标准的RMSE数值,同样满足"值越小模型性能越好"的解读逻辑。

如果想直接得到正值结果,也可以在计算时对scores取绝对值,比如:

mean_rmse = np.mean(np.abs(scores_D_Trees))

这样输出的就是直接可用的正值RMSE了。


内容的提问来源于stack exchange,提问作者MK70

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 19:10:33