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