Regression Metrics
Mean Squared Error: (1/n) Σᵢ (yᵢ − ŷᵢ)². Penalizes large errors quadratically. The most common regression metric.
Root Mean Squared Error: √MSE. Same units as the target variable, making it more interpretable than MSE.
Mean Absolute Error: (1/n) Σᵢ |yᵢ − ŷᵢ|. More robust to outliers than MSE. Linear penalty for errors.
Coefficient of determination: R² = 1 − SS_res / SS_tot. 1.0 = perfect prediction, 0.0 = predicting the mean, negative = worse than mean.
Adjusted R² that penalizes for number of features. Useful for comparing models with different numbers of predictors.
Mean Absolute Percentage Error: (100/n) Σᵢ |yᵢ − ŷᵢ| / |yᵢ|. Percentage-based, scale-independent. Undefined when true values are zero.
Median of absolute errors. Extremely robust to outliers.
Fraction of variance in y explained by predictions. Similar to R² but does not penalize for bias.
Maximum absolute error: max |yᵢ − ŷᵢ|. Captures the worst-case prediction error.
MSE
Where:
- ŷᵢ = Predicted value
R²
Where:
- ȳ = Mean of true values
import { mse, rmse, mae, r2Score } from "deepbox/metrics";import { tensor } from "deepbox/ndarray";const yTrue = tensor([3.0, -0.5, 2.0, 7.0]);const yPred = tensor([2.5, 0.0, 2.1, 7.8]);mse(yTrue, yPred); // ~0.375rmse(yTrue, yPred); // ~0.612mae(yTrue, yPred); // 0.425r2Score(yTrue, yPred); // ~0.948