P e x c e r a

Evaluating Regression: Mean Absolute Error (MAE)

Mean Absolute Error (MAE) measures the average magnitude of prediction errors in the original units of the target — it is intuitive, interpretable, and robust to outliers.


Computing MAE

MAE = (1/n) \u03a3 |y\u1d62 - \u0177\u1d62|. Because it uses absolute values rather than squares, each error contributes proportionally — a prediction off by 10 contributes exactly 10 times more than one off by 1.

MAE in scikit-learn

<pre><code class="language-python">from sklearn.metrics import mean_absolute_error from sklearn.linear_model import LinearRegression from sklearn.datasets import fetch_california_housing from sklearn.model_selection import train_test_split data = fetch_california_housing() X_tr, X_te, y_tr, y_te = train_test_split( data.data, data.target, test_size=0.2, random_state=42 ) model = LinearRegression().fit(X_tr, y_tr) y_pred = model.predict(X_te) mae = mean_absolute_error(y_te, y_pred) print(f"MAE: {mae:.4f} (in units of the target)")</pre>

Interpreting and Comparing MAE

MAE is expressed in the same units as the target variable, making it directly meaningful to domain experts.

MAE vs. MSE: Robustness

MAE treats all errors equally regardless of size, so a single large outlier does not disproportionately inflate the metric. MSE squares errors, causing large outliers to dominate. If your application can tolerate occasional large errors but cares about average performance, MAE is the more representative metric.

Normalised MAE

To compare MAE across datasets with different scales, compute MAPE (Mean Absolute Percentage Error) or normalise MAE by the range or standard deviation of the target. This gives a unit-free measure of average relative error.