Python3——sklearn中評價迴歸模型的六種方法
評價迴歸模型的好壞需要計算真實值與預測值之間的誤差關係,sklearn為我們提供了6種評價迴歸模型的方法,分別是
1.均方誤差(mean squared error),
2.平均絕對誤差(mean absolute error),
3.均方對數誤差(mean squared logarithmic error),
4.中值絕對誤差(median absolute error),
5.可釋方差分數(explain variance score),
6.決定係數分數( score)
假設共有n個樣本,真實值是,預測值是
1. 均方誤差(mean squared error)
注意:區別於均方差(標準差)!!!標準差,也稱均方差,定義為方差的算術平方根,反映組內個體間的離散程度。
mean_squared_error(y_true, y_pred, sample_weight=None, multioutput='uniform_average')
其中 multioutput : 有兩個取值,分別是 ['raw_values', 'uniform_average']
“raw_values”:
在多輸出的情況下返回每個輸出的誤差集合。
“uniform_average”:
在多輸出的情況下返回所有輸出的誤差均值。
均方誤差是非負值,模型越好MSE越接近零。
2.平均絕對誤差(mean absolute error)
mean_absolute_error(y_true, y_pred, sample_weight=None, multioutput='uniform_average')
平均絕對誤差是非負值,模型越好MAE越接近零。
3.均方對數誤差(mean squared logarithmic error)
mean_squared_log_error(y_true, y_pred, sample_weight=None, multioutput='uniform_average')
均方對數誤差是非負值,模型越好MSLE越接近零。
4.中值絕對誤差(median absolute error)
median_absolute_error(y_true, y_pred)
中值絕對誤差是非負值,模型越好MSE越接近零。
5.可釋方差分數(explain variance score)
explained_variance_score(y_true, y_pred, sample_weight=None, multioutput='uniform_average')
最佳模型的可釋方差分數值為1,模型越差值越小。
6.決定係數分數((coefficient of determination) score)
r2_score(y_true, y_pred, sample_weight=None, multioutput='uniform_average')
最佳模型的決定係數分數值為1,常數模型值為0,模型越差值越小。