# Measuring Error

A model's guesses are always a little off; the question is how far, and whether it beats a simple guess. Compute the error of each guess, then sum it up three ways: the mean absolute error, the root mean squared error and R squared, each by hand and with scikit-learn, and learn what each one hides. The running example is a delivery service's estimated minutes.

Updated: November 19, 2026

## [Error in One Number](https://www.ask-codey.com/courses/machine-learning-python/topics/ml-error-in-one-number)

1. [Errors and the Mean Absolute Error](https://www.ask-codey.com/lessons/ml-mean-absolute-error) (Apprentice): A guess's error, or residual, is the actual value minus the guess, and because errors above and below cancel out when they're averaged, the mean absolute error averages their sizes instead, giving how far off the guesses usually are in the label's own units, by hand or with scikit-learn's mean_absolute_error.
2. [Squared Errors and RMSE](https://www.ask-codey.com/lessons/ml-root-mean-squared-error) (Journeyman): Squaring each error before averaging makes big misses count much more, giving the mean squared error in squared units, and its square root, the root mean squared error (RMSE), puts it back in the label's units; RMSE is never smaller than the MAE, and a big gap between them says a few guesses are very wrong.
3. [R Squared: Better Than Guessing the Average?](https://www.ask-codey.com/lessons/ml-r-squared) (Journeyman): R squared compares a model's squared errors with those of always guessing the average of the values being scored, so 1 is perfect, 0 is no better than the average, and below 0 is worse, which can happen on test data; scikit-learn's r2_score computes it, and on its own it can't say whether the misses are small enough to use.

## [Is the Model Any Good?](https://www.ask-codey.com/courses/machine-learning-python/topics/ml-is-the-model-any-good)

1. [Baselines and Residual Plots](https://www.ask-codey.com/lessons/ml-regression-baselines-and-residual-plots) (Journeyman): A DummyRegressor that always guesses the training average is the baseline a model must beat on the same test set, and a predicted-versus-actual plot and a residual plot show where the misses are, while a pattern in the residuals says the model is missing something it could use.

## [Exercise: Delivery Time Errors](https://www.ask-codey.com/courses/machine-learning-python/topics/exercise-ml-delivery-time-errors)

1. [Exercise: Delivery Time Errors](https://www.ask-codey.com/lessons/exercise-ml-delivery-time-errors) (Journeyman): Write the mean absolute error, the root mean squared error, R squared and a check against the always-the-average baseline in plain Python for Pine Ridge Delivery's time estimates, and let pytest compare each one with scikit-learn's own function.

Source: https://www.ask-codey.com/courses/machine-learning-python/chapters/ml-measuring-error
