Skip to content
v0.1.3latest release121 skills4 categories6 sub-categories247 tested scripts397 reference docsContact us

Regression and Forecast Metrics

Reference for ml-success-metric-selector · 89 lines

AI & Machine Learning / Classical Machine Learningv1.0.0Updated OCT 25 20264 references2 scripts

Notation: e = ŷ − y, n rows.

Point-error metrics

MetricFormulaMinimised byUseMisleads when
MAEmeanemedian
RMSEsqrt(mean e²)meanlarge errors costlyoutliers are noise
MedAEmediane-
Bias (ME)mean e-guardrail for systematic over/underused alone
R²1 − SSE/SSTmeanmodel comparison on one datasetcomparing datasets; reporting to business
MAPEmeane/ya value below the median (favours under-forecasts)
sMAPEmean 2e/(y
WAPEΣe/ Σy
RMSLEsqrt(mean (log1p ŷ − log1p y)²)geometric-mean-likerelative errors, positive skewed targetsunder-prediction penalised less

Deviance metrics (for GLM-style targets)

TargetMetricsklearn
Countsmean Poisson deviancemean_poisson_deviance
Positive, skewed (claim size)mean Gamma deviancemean_gamma_deviance
Zero-inflated positive (insurance loss)mean Tweedie deviance, power 1 < p < 2mean_tweedie_deviance(power=1.5)

Use the deviance that matches the training objective; report MAE alongside for interpretability.

Forecast metrics

MASE

text
MASE = mean|e_t| / ( (1/(T−m)) Σ_{t=m+1..T} |y_t − y_{t−m}| )      # denominator on the training data

Scale-free, defined with zeros, < 1 means better than in-sample seasonal naive (m = season length; m = 1 for non-seasonal naive). Average MASE across series for global comparison.

RMSSE

Squared version of MASE (used in the M5 competition), weighted by series revenue.

Pinball (quantile) loss

text
L_q(y, ŷ) = q·(y − ŷ) if y ≥ ŷ else (1 − q)·(ŷ − y)

Average across quantiles approximates CRPS. Report with coverage: share of actuals inside the [q_low, q_high] interval, which should match the nominal level (80% interval -> ~80%).

Bias for forecasts

text
bias% = Σ(ŷ − y) / Σ y

Tracking signal = cumulative error / MAD; |TS| > 4 flags a biased forecast.

Loss and metric alignment

You reportTrain with
MAEabsolute error / L1, or quantile 0.5
RMSEsquared error
Quantile qpinball loss at q
MAPEsample weights 1/
WAPEL1
Poisson deviancePoisson objective
RMSLEsquared error on log1p(y)

Training on log1p(y) with squared error then reporting MAE in original units estimates the median times a bias factor; for sums (total revenue) correct with a smearing factor.

Slicing

Report MAE/bias by segment (product size, region, horizon). A small overall error can hide a large systematic under-prediction for the biggest customers (see metric_report.py --segment).

scikit-learn calls

python
from sklearn.metrics import (mean_absolute_error, mean_absolute_percentage_error, mean_pinball_loss,
                             mean_poisson_deviance, mean_squared_error, mean_squared_log_error,
                             mean_tweedie_deviance, median_absolute_error, r2_score, root_mean_squared_error)

root_mean_squared_error(y, p)                         # sklearn >= 1.4
mean_pinball_loss(y, p_q90, alpha=0.9)
mean_tweedie_deviance(y, p, power=1.5)
wape = abs(y - p).sum() / abs(y).sum()

mean_absolute_percentage_error returns a fraction (0.12 = 12%) and does not skip zeros: it divides by max(|y|, eps), so a single zero actual produces an enormous value.

More in Classical Machine Learning

anomaly-detection-model-builder

Build and evaluate anomaly detection for tabular, sensor and transaction data with few or no labels: define the anomaly type (point, contextual, collective), choose detectors (robust z-score/MAD and IQR rules, Mahalanobis with robust covariance, k-NN distance, LOF, Isolation Forest, one-class SVM, PCA reconstruction / autoencoders, forecasting residuals for time series), combine them by rank, explain each alert by its deviating features, set thresholds from an alert budget or the score distribution, and evaluate with precision@k, PR-AUC and recall on known incidents, or detector agreement when no labels exist. Includes pure-Python detectors (robust z, Mahalanobis, kNN, Isolation Forest, ensemble) and an evaluation script.

catboost-model-builder

Build CatBoost models that use its strengths correctly: raw categorical columns as cat_features (ordered target statistics, no manual encoding), text_features, Pool construction with NaN-safe categories, ordered boosting and has_time for temporal data, symmetric (oblivious) trees, overfitting detector with eval_set and use_best_model, losses for classification, regression (Quantile, Poisson, Tweedie) and ranking (YetiRank), class weights, monotone constraints, feature importance (PredictionValuesChange, LossFunctionChange) and SHAP values, GPU training and model export. Plans cat/text/numeric columns from a CSV and generates a runnable training script, and checks parameter sets for the conflicts CatBoost rejects (iterations vs n_estimators, Bayesian bootstrap with subsample, multiple class-weight options, depth > 16, use_best_model without eval_set).

categorical-encoding-selector

Choose and implement the right encoding for every categorical column given the model family and the data: one-hot (with infrequent-level grouping and handle_unknown), ordinal with an explicit order, cross-fitted target encoding (scikit-learn TargetEncoder, CatBoost ordered statistics, category_encoders inside CV), frequency/count encoding, feature hashing, native categorical support in LightGBM, HistGradientBoosting, XGBoost and CatBoost, prefix levels for codes (zip3, NAICS-2), and embeddings. Measures cardinality, rare-level share, unseen-level rate on a time-ordered holdout and target signal per column, emits the ColumnTransformer, and quantifies target-encoding leakage (in-sample vs out-of-fold vs holdout AUC).

classification-model-selector

Choose the right classification algorithm for tabular, text or mixed data and prove the choice with a fair bake-off: logistic regression (L2, L1, elastic net), linear SVM, naive Bayes, k-NN, RBF SVM, decision trees, random forest, extra trees, HistGradientBoosting, LightGBM, XGBoost, CatBoost, explainable boosting machines (EBM/GAM), points scorecards and MLPs, matched to data size, width, categorical and high-cardinality share, missingness, class imbalance, text, and constraints such as interpretability, monotonic constraints, calibrated probabilities, latency budgets and tiny deployable models. Ranks candidates with starting hyperparameters and cautions, then generates a bake-off script running every candidate on identical CV folds with per-fold metrics, fit time and prediction latency.

clustering-algorithm-selector

Choose the right clustering algorithm and check that clustering makes sense at all: cluster tendency (Hopkins statistic with a correlated-features caveat, nearest-neighbour isolation), then k-means / MiniBatchKMeans, Gaussian mixtures with BIC, agglomerative (Ward, average, complete, single) with dendrograms, DBSCAN, HDBSCAN, OPTICS, spectral clustering, BIRCH, mean shift, k-prototypes and k-modes for mixed or categorical data, and Gower distance, matched to data size, expected shapes, noise, varying density, known k, soft memberships, hierarchy and streaming. Covers preprocessing (scaling, encoding, dimensionality, distance metrics), validation (internal indices, bootstrap stability, external labels, business profiling) and assigning new points.

collaborative-filtering-implementer

Implement collaborative filtering recommenders that beat popularity: item-based kNN with cosine, Jaccard or asymmetric similarity, shrinkage, neighbourhood size, positive-only or mean-centred rating signals and 'because you liked X' explanations; implicit ALS with confidence weighting, BPR pairwise ranking and the closed-form EASE model in plain NumPy, tuned on a temporal validation split by recall@k and NDCG@k and refit on all data; plus user-kNN, explicit matrix factorisation, the implicit/LightFM libraries, hyperparameter ranges, cold-start fallbacks, scaling with sparse matrices and approximate nearest neighbours. Produces top-k lists in the format of the recommendation evaluator.