当前位置 : 主页 > 手机开发 > ROM >

利用sklearn计算决定系数R2

来源:互联网 收集:自由互联 发布时间:2021-06-10
from sklearn.metrics import r2_score y_true = y_true = [3, -0.5, 2, 7 ] y_pred = [2.5, 0.0, 2, 8 ] r2_score(y_true, y_pred) # 结果:0.9486081370449679 r2_score(y_true, y_pred, multioutput= ‘ uniform_average ‘ ) # 结果:0.948608137

分享图片

分享图片

 

分享图片

from sklearn.metrics import r2_score
 y_true = y_true = [3, -0.5, 2, 7]
 y_pred = [2.5, 0.0, 2, 8]
 r2_score(y_true, y_pred)
 # 结果:0.9486081370449679
 r2_score(y_true, y_pred, multioutput= uniform_average)
 # 结果:0.9486081370449679
 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)
 # 结果:0.9382566585956417
 y_true = [1, 2, 3]
 y_pred = [1, 2, 3]
 r2_score(y_true, y_pred)
 # 结果: 1.0
 y_true = [1, 2, 3]
 y_pred = [2, 2, 2]
 r2_score(y_true, y_pred)
 # 结果:0.0
  y_true = [1, 2, 3] # bar{y} = (1+2+3)/ 3 = 2
  y_pred = [3, 2, 1] # y - hat{y}(即y_true - y_pred) = [-2, 0, 2]
  r2_score(y_true, y_pred)
  # 结果:-3.0
  y_true = [[0.5, 1], [-1, 1], [7, -6]]
  y_pred = [[0, 2], [-1, 2], [8, -5]]
  r2_score(y_true, y_pred, multioutput=raw_values)
  # 结果:array([0.96543779, 0.90816327])
网友评论