Notation: e = ŷ − y, n rows.
Point-error metrics
| Metric | Formula | Minimised by | Use | Misleads when |
|---|---|---|---|---|
| MAE | mean | e | median | |
| RMSE | sqrt(mean e²) | mean | large errors costly | outliers are noise |
| MedAE | median | e | - | |
| Bias (ME) | mean e | - | guardrail for systematic over/under | used alone |
| R² | 1 − SSE/SST | mean | model comparison on one dataset | comparing datasets; reporting to business |
| MAPE | mean | e/y | a value below the median (favours under-forecasts) | |
| sMAPE | mean 2 | e | /( | y |
| WAPE | Σ | e | / Σ | y |
| RMSLE | sqrt(mean (log1p ŷ − log1p y)²) | geometric-mean-like | relative errors, positive skewed targets | under-prediction penalised less |
Deviance metrics (for GLM-style targets)
| Target | Metric | sklearn |
|---|---|---|
| Counts | mean Poisson deviance | mean_poisson_deviance |
| Positive, skewed (claim size) | mean Gamma deviance | mean_gamma_deviance |
| Zero-inflated positive (insurance loss) | mean Tweedie deviance, power 1 < p < 2 | mean_tweedie_deviance(power=1.5) |
Use the deviance that matches the training objective; report MAE alongside for interpretability.
Forecast metrics
MASE
MASE = mean|e_t| / ( (1/(T−m)) Σ_{t=m+1..T} |y_t − y_{t−m}| ) # denominator on the training dataScale-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
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
bias% = Σ(ŷ − y) / Σ yTracking signal = cumulative error / MAD; |TS| > 4 flags a biased forecast.
Loss and metric alignment
| You report | Train with |
|---|---|
| MAE | absolute error / L1, or quantile 0.5 |
| RMSE | squared error |
| Quantile q | pinball loss at q |
| MAPE | sample weights 1/ |
| WAPE | L1 |
| Poisson deviance | Poisson objective |
| RMSLE | squared 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
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.
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.