sklearn.metrics.mean_absolute_error


  • 注意多維數組 MAE 的計算方法 *
>>> from sklearn.metrics import mean_absolute_error
>>> y_true = [3, -0.5, 2, 7]
>>> y_pred = [2.5, 0.0, 2, 8]
>>> mean_absolute_error(y_true, y_pred)
0.5
>>> y_true = [[0.5, 1], [-1, 1], [7, -6]]
>>> y_pred = [[0, 2], [-1, 2], [8, -5]]
>>> mean_absolute_error(y_true, y_pred)
0.75
>>> mean_absolute_error(y_true, y_pred, multioutput='raw_values')
array([0.5, 1. ])
>>> mean_absolute_error(y_true, y_pred, multioutput=[0.3, 0.7])
... 
0.85...
In [34]: y_true = np.array([1,2,3,4,5,0,0,0,0,0])                                                          

In [35]: y_pred = np.array([1.1,2.2,3.1,4.1,5.1,0,0,0,0,0])                                                

In [36]: mean_absolute_error(y_true,y_pred)                                                                
Out[36]: 0.05999999999999996

In [37]: y_pred = np.array([1.1,2.2,3.1,4.1,5.1])                                                          

In [38]: y_true = np.array([1,2,3,4,5])                                                                    

In [39]: mean_absolute_error(y_true,y_pred)                                                                
Out[39]: 0.11999999999999993
  • multioutput='raw_values' 給出的是每列的 MAE
  • multioutput=[0.3, 0.7] 給出的是加了不同權重的每列的MAE


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM