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
原文地址:https://www.cnblogs.com/yaos/p/14014247.html