評價迴歸模型的好壞需要計算真實值與預測值之間的誤差關係,sklearn爲我們提供了6種迴歸模型的評估規則,分別是
1.可釋方差分數(explain variance score)
2.平均絕對誤差(mean absolute error)
3.均方誤差(mean squared error)
4.均方對數誤差(mean squared logarithmic error),適用於具有指數增長的趨勢的目標。
5.中值絕對誤差(median absolute error),該函數不支持多輸出。
6.決定係數分數( score)
通常,函數以
_score
結尾返回一個值來最大化,越高越好。函數
_error
或_loss
結尾返回一個值來 minimize (最小化),越低越好。
假設共有n個樣本,真實值是,預測值是
1.可釋方差分數(explain variance score)
explained_variance_score(y_true, y_pred, sample_weight=None, multioutput='uniform_average')
其中 multioutput : 有兩個取值,分別是 ['raw_values', 'uniform_average']
“raw_values”:在多輸出的情況下返回每個輸出的誤差集合。
“uniform_average”:在多輸出的情況下返回所有輸出的誤差均值。
最佳模型的可釋方差分數值爲1,模型越差值越小。
2.平均絕對誤差(mean absolute error)
mean_absolute_error(y_true, y_pred, sample_weight=None, multioutput='uniform_average')
平均絕對誤差是非負值,模型越好MAE越接近零。
3.均方誤差(mean squared error)
mean_squared_error(y_true, y_pred, sample_weight=None, multioutput='uniform_average')
注意:區別於均方差(標準差)!!!標準差,也稱均方差,定義爲方差的算術平方根,反映組內個體間的離散程度。
均方誤差是非負值,模型越好MSE越接近零。
4.均方對數誤差(mean squared logarithmic error)
mean_squared_log_error(y_true, y_pred, sample_weight=None, multioutput='uniform_average')
均方對數誤差是非負值,模型越好MSLE越接近零。
5.中值絕對誤差(median absolute error)
median_absolute_error(y_true, y_pred)
中值絕對誤差是非負值,模型越好MSE越接近零。
6.決定係數分數((coefficient of determination) score)
r2_score(y_true, y_pred, sample_weight=None, multioutput='uniform_average')
最佳模型的決定係數分數值爲1,常數模型值爲0,模型越差值越小。