小编Nan*_*ain的帖子

Scikit-Learn 给出错误的 R 平方值

我正在 Python 上训练机器学习模型,并使用 Scikit Learn 中的 R 平方度量来评估它们。Id 决定使用 Scikit 的 r2_score 函数,为其提供一个与输入 y_true 值相同的随机数组,以及与 y_predict 略有不同但值相同的数组。当数组的输入长度为 10 或更大时,我得到任意大(负)值;当输入长度小于 10 时,我得到 0。

from sklearn.metrics import r2_score
r2_score([213.91666667,  213.91666667,  213.91666667,  213.91666667,  213.91666667, 
      213.91666667, 213.91666667,  213.91666667,  213.91666667,  213.91666667],
    [213,  214,  214,  214,  214,  214,  214,  214,  214,  214])

>>> -1.1175847590636849e+26

r2_score([213.91666667,  213.91666667,  213.91666667,  213.91666667, 
      213.91666667, 213.91666667,  213.91666667,  213.91666667,  213.91666667],
    [213,  214,  214,  214,  214,  214,  214,  214,  214])

>>> 0
Run Code Online (Sandbox Code Playgroud)

python statistics python-3.x scikit-learn

3
推荐指数
1
解决办法
3528
查看次数

标签 统计

python ×1

python-3.x ×1

scikit-learn ×1

statistics ×1