Regression evaluation
Compare regression predictions with observed continuous targets.
Scikit-Learn · Function
Computes mean absolute error, a non-negative regression loss based on absolute differences between true and predicted targets. It can weight samples and either preserve or aggregate errors across multiple outputs.
The function compares each predicted target with its corresponding true target, takes the absolute error, and averages it. For multiple outputs, it can return one error per output or aggregate outputs uniformly or with supplied weights; sample weights can also affect the averaging.
sklearn.metrics.mean_absolute_error(y_true, y_pred, *, sample_weight=None, multioutput='uniform_average')| Name | Type | Description |
|---|---|---|
y_true | array-like | Ground-truth target values; array-like with shape (n_samples,) or (n_samples, n_outputs). |
y_pred | array-like | Estimated target values; array-like with shape (n_samples,) or (n_samples, n_outputs). |
sample_weight | array-like or None | Sample weights; array-like with shape (n_samples,), default None. |
multioutput | {'raw_values', 'uniform_average'} or array-like | Output aggregation mode: 'raw_values', 'uniform_average', or an array-like of output weights; default 'uniform_average'. |
float or array of floats. raw_values returns one error per output; uniform aggregation or an output-weight array returns a weighted average. The result is non-negative, with 0.0 as the best value.
y_true.y_pred.multioutput argument controls how errors from several target columns are combined.raw_values when you need an error for every output instead of one aggregate score.multioutput must represent output-combination weights, not per-sample weights.from sklearn.metrics import mean_absolute_error
y_true = [3, -0.5, 2, 7]
y_pred = [2.5, 0.0, 2, 8]
mae = mean_absolute_error(y_true, y_pred)
print(mae) # 0.5This computes the scalar MAE for four regression predictions.
Compare regression predictions with observed continuous targets.
Measure error when absolute deviations are easier to interpret than squared deviations.
Evaluate models that predict several target columns.
Give selected observations more influence in the metric.
It is a regression loss that returns a non-negative floating-point value. A perfect prediction has a score of 0.0.
Follow-up: How can multiple outputs be handled? Use raw_values for separate output errors, or use uniform aggregation or an output-weight array for one combined result.
y_true contains the correct target values and y_pred contains estimated target values. Both may be one-dimensional or shaped for multiple outputs.
Follow-up: How would sample-level importance be represented? Pass an array of sample weights through sample_weight.
With multioutput='raw_values', the function returns an error for each output. With the default uniform aggregation or an output-weight array, it returns one weighted average.
Follow-up: What does sample_weight control? It supplies weights used when averaging the sample errors.
mean_squared_errormean_absolute_percentage_errormedian_absolute_errorroot_mean_squared_error