Open links in new tab
  1. Mean Absolute Error (MAE) is a metric used to measure the average magnitude of errors in a set of predictions, without considering their direction. It is the average over the test sample of the absolute differences between prediction and actual observation where all individual differences have equal weight.

    Definition and Calculation

    MAE is calculated as: [ \text{MAE} = \frac{1}{n} \sum_{i=1}^{n} |y_i - \hat{y}_i| ] where ( y_i ) is the actual value and ( \hat{y}_i ) is the predicted value.

    Using scikit-learn to Calculate MAE

    The mean_absolute_error function from the sklearn.metrics module can be used to calculate MAE in Python. Here is an example:

    from sklearn.metrics import mean_absolute_error

    # Actual values
    y_true = [3, -0.5, 2, 7]

    # Predicted values
    y_pred = [2.5, 0.0, 2, 8]

    # Calculate MAE
    mae = mean_absolute_error(y_true, y_pred)
    print(mae) # Output: 0.5
    Copied!

    Parameters

    • y_true: array-like of shape (n_samples,) or (n_samples, n_outputs). These are the ground truth (correct) target values.

    • y_pred: array-like of shape (n_samples,) or (n_samples, n_outputs). These are the estimated target values.

    • sample_weight: array-like of shape (n_samples,), default=None. These are the sample weights.

    • multioutput: {‘raw_values’, ‘uniform_average’} or array-like of shape (n_outputs,), default=’uniform_average’. This defines the aggregating of multiple output values.

  1. mean_absolute_error — scikit-learn 1.8.0 documentation

    Array-like value defines weights used to average errors. Returns a full set of errors in case of multioutput input. Errors of all outputs are averaged with uniform weight. If multioutput is ‘raw_values’, then mean …

  2. How to Calculate Mean Absolute Error in Python?

    May 27, 2025 · The sklearn.metrics module in Python provides various tools to evaluate the performance of machine learning models. One of the methods available is mean_absolute_error(), …

  3. How to Calculate Mean Absolute Error (MAE) in Python - datagy

    Feb 21, 2022 · In this tutorial, you’ll learn how to calculate the mean absolute error, or MAE, in Python. The mean absolute error can help measure the accuracy of a given machine learning model.

  4. How to Calculate Mean Absolute Error in Python - Statology

    Jan 8, 2021 · This tutorial explains how to calculate the mean absolute error in Python, including several examples.

  5. Mean Absolute Error Explained: Measuring Model Accuracy

    Aug 8, 2025 · In this article, we’ll focus on one common one that you need to know as a data scientist: mean absolute error (MAE). As you will see, MAE offers a straightforward view of prediction accuracy …

  6. Understanding Mean Absolute Error (MAE) in Regression: A ... - Medium

    Aug 24, 2023 · To better understand MAE, let’s work through a sample Jupyter Notebook using Python and the scikit-learn library. In this example, we’ll create a simple linear regression model and then...

  7. People also ask
  8. Python Tutorial: Calculate Mean Absolute Error (MAE) in Python

    Aug 28, 2023 · Learn how to use MAE, a metric to measure the average absolute difference between predicted and actual values, in Python programs. See examples, formulas, and tips to reduce MAE in …

  9. Mastering Mean Absolute Error in Python: A Comprehensive Guide for …

    Jun 19, 2025 · This comprehensive guide will delve deep into the intricacies of MAE, exploring its implementation in Python, and demonstrating how it can be leveraged to elevate your machine …

  10. How To Calculate MAE In Python? - The Friendly Statistician

    We will guide you through the manual calculation of MAE in Python, step by step.

  11. python - How can I calculate the MAE (mean absolute error) in pandas ...

    Dec 5, 2022 · I have to calculate the MAE error (mean absolute error) 𝑋 , 𝑋′ : MAE: 1/𝑛𝑑*∑𝑑𝑗=1∑𝑛𝑖=1∣𝑥𝑖𝑗−𝑥′𝑖𝑗∣. 𝑅 , 𝑅′ : MAE-corr: 1/𝑑2*∑𝑑𝑗=1∑𝑛𝑖=1∣𝑟𝑖𝑗−𝑟′𝑖𝑗∣. The dataframes that are needed to solve this exercise I already have them …