码迷,mamicode.com
首页 > 其他好文 > 详细

sklearn 中的 r2_score

时间:2020-11-25 12:34:00      阅读:5      评论:0      收藏:0      [点我收藏+]

标签:learn   mat   ssi   div   eps   sre   spl   average   reg   

\(R^2\)不止一种定义方式,这里是scikit-learn中所使用的定义。

As such variance is dataset dependent, R2 may not be meaningfully comparable across different datasets. Best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a R2 score of 0.0.

As such variance is dataset dependent, R2 may not be meaningfully comparable across different datasets. Best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a R2 score of 0.0.

\[R^2(y, \hat{y}) = 1 - \frac{\sum_{i=1}^{n} (y_i - \hat{y}_i)^2}{\sum_{i=1}^{n} (y_i - \bar{y})^2} \]

\[\bar{y} = \frac{1}{n} \sum_{i=1}^{n} y_i \]

\[\sum_{i=1}^{n} (y_i - \hat{y}_i)^2 = \sum_{i=1}^{n} \epsilon_i^2 \]

from sklearn.metrics import r2_score
y_true = [3, -0.5, 2, 7]
y_pred = [2.5, 0.0, 2, 8]
r2_score(y_true, y_pred)

y_true = [[0.5, 1], [-1, 1], [7, -6]]
y_pred = [[0, 2], [-1, 2], [8, -5]]
r2_score(y_true, y_pred, multioutput=‘variance_weighted‘)

y_true = [[0.5, 1], [-1, 1], [7, -6]]
y_pred = [[0, 2], [-1, 2], [8, -5]]
r2_score(y_true, y_pred, multioutput=‘uniform_average‘)

r2_score(y_true, y_pred, multioutput=‘raw_values‘)

r2_score(y_true, y_pred, multioutput=[0.3, 0.7])

sklearn 中的 r2_score

标签:learn   mat   ssi   div   eps   sre   spl   average   reg   

原文地址:https://www.cnblogs.com/yaos/p/14016352.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!