sklearn.metrics.mean_absolute_error?
sklearn.metrics.mean_absolute_error(y_true, y_pred, *, sample_weight=None, multioutput='uniform_average')
平均絕對誤差回歸損失
在用戶指南中閱讀更多內容。
參數 | 說明 |
---|---|
y_true | array-like of shape (n_samples,) or (n_samples, n_outputs) 真實目標值。 |
y_pred | array-like of shape (n_samples,) or (n_samples, n_outputs) 預測目標值。 |
sample_weight | array-like of shape (n_samples,), optional 樣本權重。 |
multioutput | string in [‘raw_values’, ‘uniform_average’] or array-like of shape (n_outputs) 定義多個輸出值的匯總。類似數組的值定義了用于平均誤差的權重。 - ‘raw_values’: 如果是多輸出格式的輸入,則返回完整的錯誤集。 - ‘uniform_average’: 所有輸出的誤差均以相同的權重平均。 |
返回值 | 說明 |
---|---|
loss | float or ndarray of floats 如果多輸出為‘raw_values’,則分別為每個輸出返回均值絕對錯誤。如果多輸出是‘uniform_average’或權重的ndarray,則將返回所有輸出錯誤的加權平均值。 MAE輸出為非負浮點。最佳值為0.0。 |
示例
>>> 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...