Overview of metrics in sysidentpy.metrics
mainThe sysidentpy.metrics module provides 13 public functions for evaluating regression and forecasting errors by comparing observed values (y) with predicted values (yhat).
Metrics are categorized by their mathematical properties:
- Signed error:
forecast_error,mean_forecast_error. Useful for detecting bias/direction. - Squared error:
mean_squared_error,root_mean_squared_error. Penalizes large errors heavily. - Normalized squared error:
normalized_root_mean_squared_error,root_relative_squared_error. Dimensionless; used for scale comparison. - Absolute error:
mean_absolute_error,median_absolute_error. Direct interpretation; less sensitive to outliers. - Scaled absolute error:
mean_absolute_scaled_error. Compares MAE against a naive forecast from training data. - Logarithmic/Percentage error:
mean_squared_log_error,symmetric_mean_absolute_percentage_error. Assesses relative differences. - Goodness of fit:
explained_variance_score,r2_score. Compares error to output variability.
import numpy as np
from sysidentpy.metrics import (
explained_variance_score,
forecast_error,
mean_absolute_error,
mean_absolute_scaled_error,
mean_forecast_error,
mean_squared_error,
mean_squared_log_error,
median_absolute_error,
normalized_root_mean_squared_error,
r2_score,
root_mean_squared_error,
root_relative_squared_error,
symmetric_mean_absolute_percentage_error,
)
y = np.array([3.0, -0.5, 2.0, 7.0])
yhat = np.array([2.5, 0.0, 2.0, 8.0])
y_train = np.array([1.0, 2.0, 3.0, 4.0])
# Example usage of various metrics
errors = forecast_error(y, yhat)
bias = mean_forecast_error(y, yhat)
mse = mean_squared_error(y, yhat)
rmse = root_mean_squared_error(y, yhat)
nrmse = normalized_root_mean_squared_error(y, yhat)
rrse = root_relative_squared_error(y, yhat)
mae = mean_absolute_error(y, yhat)
median_ae = median_absolute_error(y, yhat)
mase = mean_absolute_scaled_error(y, yhat, y_train)
msle = mean_squared_log_error(y, yhat)
smape = symmetric_mean_absolute_percentage_error(y, yhat)
evs = explained_variance_score(y, yhat)
r2 = r2_score(y, yhat)