Table of Contents

    Regression Evaluation Metrics

    MACHINE LEARNING

    Regression Evaluation Metrics

    Measuring how well your regression model predicts continuous values.

    What are Regression Evaluation Metrics?

    Regression Evaluation Metrics are mathematical measures used to evaluate the performance of regression models by comparing the predicted values with the actual values.

    In simple words — These metrics tell us how close our model's predictions are to the real values.

    Why Are They Important?

    • Measure how accurate the predictions are.
    • Help compare different regression models.
    • Identify if the model is overfitting or underfitting.
    • Provide insights for improving model performance.
    • Help select the best model for deployment.
    Without evaluation metrics, we can't tell if our model is performing well or poorly.

    Notation Used

    • yᵢ = actual value
    • ŷᵢ = predicted value
    • ȳ = mean of actual values
    • n = total number of samples

    Popular Regression Evaluation Metrics

    1

    Mean Absolute Error (MAE)

    Average of the absolute differences between actual and predicted values.

    FORMULA
    $$ MAE = \frac{1}{n} \sum_{i=1}^{n} |y_i - \hat{y}_i| $$
    from sklearn.metrics import mean_absolute_error
    mae = mean_absolute_error(y_test, y_pred)
    print("MAE:", mae)
    Best For Easy interpretation — gives the average error in same units as target.
    Disadvantage Doesn't penalize large errors more.
    2

    Mean Squared Error (MSE)

    Average of the squared differences between actual and predicted values.

    FORMULA
    $$ MSE = \frac{1}{n} \sum_{i=1}^{n} (y_i - \hat{y}_i)^2 $$
    from sklearn.metrics import mean_squared_error
    mse = mean_squared_error(y_test, y_pred)
    print("MSE:", mse)
    Best For Penalizing larger errors heavily — useful when big errors are unacceptable.
    Disadvantage Units are squared, harder to interpret.
    3

    Root Mean Squared Error (RMSE)

    Square root of MSE — brings the error back to the same units as the target.

    FORMULA
    $$ RMSE = \sqrt{ \frac{1}{n} \sum_{i=1}^{n} (y_i - \hat{y}_i)^2 } $$
    import numpy as np
    rmse = np.sqrt(mse)
    print("RMSE:", rmse)
    Best For Most commonly used regression metric — easy to interpret.
    4

    R² Score (Coefficient of Determination)

    Measures how well the model explains the variance in the target variable.

    FORMULA
    $$ R^2 = 1 - \frac{\sum (y_i - \hat{y}_i)^2}{\sum (y_i - \bar{y})^2} $$

    Range: 0 → 1 (higher is better)

    from sklearn.metrics import r2_score
    r2 = r2_score(y_test, y_pred)
    print("R²:", r2)
    R² ValueMeaning
    1.0Perfect prediction
    0.9 - 0.99Excellent model
    0.7 - 0.9Good model
    0.5 - 0.7Average model
    0 - 0.5Poor model
    NegativeWorse than the mean baseline
    5

    Adjusted R² Score

    Improved version of R² that adjusts for the number of input features.

    FORMULA
    $$ Adjusted\ R^2 = 1 - \frac{(1 - R^2)(n - 1)}{n - p - 1} $$

    Where:

    • n = number of samples
    • p = number of features
    Best For Multiple Linear Regression — penalizes adding useless features.
    6

    Mean Absolute Percentage Error (MAPE)

    Expresses the prediction error as a percentage of actual values.

    FORMULA
    $$ MAPE = \frac{1}{n} \sum_{i=1}^{n} \left| \frac{y_i - \hat{y}_i}{y_i} \right| \times 100 $$
    import numpy as np
    
    def mape(y_true, y_pred):
        return np.mean(np.abs((y_true - y_pred) / y_true)) * 100
    
    print("MAPE:", mape(y_test, y_pred))
    Best For Easy interpretation as % error.
    Disadvantage Cannot be used when actual values contain 0.
    7

    Median Absolute Error (MedAE)

    Uses the median of absolute errors — robust to outliers.

    from sklearn.metrics import median_absolute_error
    medae = median_absolute_error(y_test, y_pred)
    print("MedAE:", medae)
    Best For Datasets with outliers.
    8

    Mean Squared Logarithmic Error (MSLE)

    Like MSE but uses logarithms — penalizes underestimation more than overestimation.

    FORMULA
    $$ MSLE = \frac{1}{n} \sum_{i=1}^{n} (\log(1 + y_i) - \log(1 + \hat{y}_i))^2 $$
    from sklearn.metrics import mean_squared_log_error
    msle = mean_squared_log_error(y_test, y_pred)
    print("MSLE:", msle)
    Best For Data with exponential growth (population, sales).

    Comparison of All Metrics

    Metric Range Outlier Sensitive? Best For
    MAE0 → ∞LowSimple error interpretation
    MSE0 → ∞HighPenalizing large errors
    RMSE0 → ∞HighCommon reporting metric
    −∞ → 1MediumVariance explanation
    Adjusted R²−∞ → 1MediumMultiple features
    MAPE0 → ∞ %Low% based interpretation
    MedAE0 → ∞Very LowRobust to outliers
    MSLE0 → ∞LowExponential trends

    Full Python Example

    Prerequisites: Python 3.x, pandas, numpy, scikit-learn.
    pip install pandas numpy scikit-learn
    import numpy as np
    from sklearn.linear_model import LinearRegression
    from sklearn.model_selection import train_test_split
    from sklearn.metrics import (
        mean_absolute_error, mean_squared_error,
        r2_score, median_absolute_error
    )
    
    # Sample dataset
    X = np.array([[1], [2], [3], [4], [5], [6], [7], [8], [9], [10]])
    y = np.array([10, 20, 25, 40, 45, 60, 70, 85, 90, 100])
    
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
    
    model = LinearRegression()
    model.fit(X_train, y_train)
    y_pred = model.predict(X_test)
    
    print("MAE:", mean_absolute_error(y_test, y_pred))
    print("MSE:", mean_squared_error(y_test, y_pred))
    print("RMSE:", np.sqrt(mean_squared_error(y_test, y_pred)))
    print("R²:", r2_score(y_test, y_pred))
    print("MedAE:", median_absolute_error(y_test, y_pred))
    Output You'll get a complete set of regression evaluation results to compare your model's performance.

    When to Use Which Metric?

    • Use MAE when you want a simple, interpretable metric.
    • Use MSE/RMSE when large errors are unacceptable.
    • Use to understand how well variance is explained.
    • Use Adjusted R² for multiple linear regression.
    • Use MAPE when reporting % errors to business teams.
    • Use MedAE when dataset contains outliers.
    • Use MSLE for exponentially growing data.

    Real-Life Analogy

    Evaluation Metrics = Exam Score

    Just like exam marks measure how well a student understood a subject, regression metrics measure how well a model has learned to predict. Different metrics highlight different aspects of performance.

    Common Mistakes to Avoid

    Mistake 1 Relying on only — it can be misleading when features are added.
    Mistake 2 Ignoring units of MAE and RMSE during reporting.
    Mistake 3 Using MAPE when actual values include 0.
    Mistake 4 Comparing models with different datasets using the same metric.

    Best Practices

    Quick Tips

    • Use multiple metrics instead of one.
    • Always test on unseen data.
    • Visualize predictions vs actual values.
    • Use cross-validation for stable results.
    • Track performance metrics across multiple runs.
    • Choose metric based on the business context.

    Importance of Regression Metrics

    Measure Accuracy

    • Compares predictions to reality
    • Tells how good the model is

    Compare Models

    • Find best performing model
    • Helps with model selection

    Detect Overfitting

    • Train vs test gap
    • Identifies weakness

    Business Insight

    • Helps communicate results
    • Supports data decisions

    Golden Rule

    REMEMBER
    Low Error + High R² = Good Regression Model

    Key Takeaway

    Regression Evaluation Metrics like MAE, MSE, RMSE, R², and MAPE are essential tools for measuring how well a regression model performs. Using the right combination of metrics gives you a clear understanding of your model's accuracy, reliability, and business value.