Metrics & Evaluationbeginnermust-know4 min

Precision, Recall & F1

Understanding the difference between catching every positive case and avoiding false alarms.

Precision measures how often your model is right when it flags something as positive. Recall measures how many of the actual positive cases your model managed to find. Raising precision usually lowers recall and vice versa. Choosing which metric matters most comes down to understanding which type of mistake causes more real world harm.

Metrics & Evaluationbeginnermust-know4 min

Why Accuracy Lies

Why 99 percent accuracy can trick you into keeping a completely useless machine learning model.

The accuracy trap happens when you use simple accuracy to judge a model on unbalanced datasets. In a rare disease dataset where 99 percent of people are healthy, a simple guessing model that predicts healthy for everyone achieves 99 percent accuracy while missing every single sick person. Solving this problem requires switching to metrics like precision, recall, and cost matrices.

Metrics & Evaluationintermediatemust-know4 min

ROC-AUC vs PR-AUC

With 0.1% positives, ROC-AUC of 0.97 can mean a useless model.

ROC-AUC plots true positive rate against false positive rate across all thresholds and equals the probability the model ranks a random positive above a random negative. It is threshold-free and prevalence-independent — which is exactly its weakness. Because FPR's denominator is the huge negative class, thousands of false positives barely move it. PR-AUC uses precision, whose denominator is what you flagged, so it collapses honestly when the positive class is rare. Use PR-AUC for imbalanced problems.

Metrics & Evaluationintermediatemust-know4 min

Data Leakage

0.99 AUC in the notebook, 0.61 in production. Every time, it's leakage.

Leakage is any information in training that will not be available at prediction time. It comes in three flavours: target leakage (a feature is a consequence of the label), train–test contamination (preprocessing or duplicate rows cross the split), and temporal leakage (training on the future). The symptom is performance that looks too good and collapses in production. The defences are a strict per-fold pipeline, point-in-time correct feature joins, and asking of every feature "would I have known this then?"

Metrics & Evaluationintermediatemust-know4 min

Slice-Based & Subgroup Evaluation

Why evaluating global aggregate metrics masks severe model failures on critical sub-populations and demographic slices.

Slice-Based Evaluation (Subgroup Analysis) evaluates model performance independently across critical data subsets (e.g. device types, user cohorts, rare categories). A model with 95% global accuracy may suffer a catastrophic 40% failure rate on low-end Android phones or minority demographic slices. Best practices require defining key slices upfront, running automated slicing frameworks (DataSlice, SliceFinder), and enforcing minimum performance floors per slice.

Metrics & Evaluationintermediatemust-know5 min

Mapping Model Metrics to Business Metrics

Translating mathematical loss functions and offline AUC into bottom-line revenue, conversion, and user retention.

Machine learning models optimize offline mathematical surrogate losses (Log Loss, MSE, Cross-Entropy), whereas businesses care about online KPIs (Revenue, Conversion Rate, Customer Acquisition Cost, User Retention). Aligning model metrics to business outcomes requires mapping offline error thresholds to dollar utility functions, calibrating output probabilities, and running controlled A/B experiment loops.

Metrics & Evaluationbeginner5 min

Reading a Confusion Matrix

Interpreting True Positives, False Positives, True Negatives, and False Negatives in classification evaluation grids.

Reading a Confusion Matrix is a fundamental skill for evaluating classification models. A Confusion Matrix is a grid comparing predicted class labels against true ground truth labels across True Positives, False Positives, True Negatives, and False Negatives. It reveals specific error types, forming the foundation for calculating Precision, Recall, Specificity, and F1 score.

Metrics & Evaluationbeginner5 min

MSE, MAE, RMSE, R²

Evaluating continuous numeric predictions using Mean Squared Error, Mean Absolute Error, Root Mean Squared Error, and R-squared.

Regression Metrics evaluate continuous numeric prediction models. Mean Absolute Error (MAE) measures average error magnitude robustly against outliers. Mean Squared Error (MSE) and Root Mean Squared Error (RMSE) penalize large prediction errors heavily due to squaring. R-squared (Coefficient of Determination) measures the proportion of target variance explained by the model compared to a simple mean baseline.

Metrics & Evaluationbeginner4 min

Splitting Data Without Cheating

Building leak-free data splits that accurately reflect real-world model deployment conditions.

Partitioning data into Training, Validation, and Test sets is the first defense against overfitting and data leakage. Standard Random Splits work for independent i.i.d. samples. Stratified Splits preserve class distribution ratios for imbalanced data. Group Splits (GroupKFold) prevent data leakage when multiple rows originate from the same user/patient. Temporal Splits (TimeSeriesSplit) enforce chronological ordering for time-dependent data.

Metrics & Evaluationintermediate5 min

Choosing a Decision Threshold

Selecting decision probability thresholds to balance Precision, Recall, and business financial loss.

Choosing a Decision Threshold tunes binary classification predictions for specific business objectives. By default, classification models assign positive labels when predicted probability exceeds 0.50. Adjusting this threshold allows engineers to trade Precision for Recall, optimizing metrics using Precision-Recall Curves, Receiver Operating Characteristic curves, or financial cost matrices.

Metrics & Evaluationintermediate5 min

F-beta & Weighting Errors

Balancing Precision and Recall using a weighted harmonic mean parameter to prioritize specific classification errors.

The F-beta score generalizes the standard F1 score by introducing a weight parameter beta to balance Precision and Recall. When beta equals 1, F-beta simplifies to the standard balanced F1 score. Setting beta greater than 1 weights Recall more heavily, which is critical for medical screening and fraud detection, while setting beta less than 1 weights Precision more heavily for spam filtering and search engine results.

Metrics & Evaluationintermediate5 min

Macro vs Micro vs Weighted Averaging

Aggregating precision, recall, and F1 scores across multiple classes in multi-class classification tasks.

Macro, Micro, and Weighted Averaging aggregate evaluation metrics across multi-class classification models. Macro Averaging calculates metrics independently for each class and takes an unweighted arithmetic mean, treating all classes equally. Micro Averaging pools total true positives, false positives, and false negatives globally across all classes, reflecting overall instance accuracy. Weighted Averaging weights per-class metrics by class support volume, accounting for class imbalance.

Metrics & Evaluationintermediate5 min

MAPE, SMAPE & Forecast Metrics

Evaluating time series and business forecasting models using relative percentage error metrics like MAPE and SMAPE.

MAPE, SMAPE, and relative forecast metrics evaluate time series predictions in relative percentage terms. Mean Absolute Percentage Error (MAPE) calculates relative errors scaled against true target magnitudes. Symmetric MAPE (SMAPE) fixes scale asymmetry issues in standard MAPE, while Weighted MAPE (WMAPE) prevents division by zero issues on sparse zero sales targets.

Metrics & Evaluationintermediate5 min

Precision@k, Recall@k & NDCG

Evaluating top K recommendation and search results using Precision at K, Recall at K, and Normalized Discounted Cumulative Gain.

Ranking Metrics evaluate ordered lists generated by search engines and recommendation systems. Precision at K measures the proportion of relevant items in top K slots, while Recall at K measures the fraction of all relevant items captured. Normalized Discounted Cumulative Gain (NDCG) measures multi-level graded relevance quality, applying logarithmic position discounting to penalize relevant items placed further down the list.

Metrics & Evaluationintermediate4 min

Building a Golden Evaluation Set

Building immutable, high-quality reference evaluation sets that serve as the source of truth for regression testing.

A Golden Evaluation Set is a curated, high-precision benchmark dataset used to evaluate ML models, LLMs, and RAG pipelines before production deployment. Unlike messy training data, golden sets are rigorously human-audited, frozen, and cover edge cases, adversarial inputs, and critical business sub-populations. Maintaining a golden dataset requires strict versioning, preventing data contamination, and handling distribution shifts.

Metrics & Evaluationadvanced5 min

Probability Calibration

Aligning raw model prediction scores with true empirical probabilities for downstream decision making and ad auctions.

Probability Calibration ensures predicted probability scores match true observed empirical frequencies. Uncalibrated models output over-confident or under-confident probabilities that distort ad auction pricing, risk scoring, and threshold decisions. Techniques like Platt Scaling and Isotonic Regression post-process raw model outputs to align predictions with true real-world frequencies.

Metrics & Evaluationadvanced5 min

Brier Score & Proper Scoring Rules

Evaluating probability accuracy and calibration simultaneously using Mean Squared Error over binary predictions.

The Brier Score measures the accuracy of probabilistic predictions using Mean Squared Error. Strictly Proper Scoring Rules incentivize probability models to output true honest probabilities rather than gaming evaluation metrics. Brier Score decomposes into Reliability (calibration error), Resolution (discrimination power), and Uncertainty (inherent task noise).

Metrics & Evaluationadvanced5 min

Is Model A Really Better Than B?

Determining whether Model A's 0.5% offline metric gain over Model B is statistically significant or random sampling noise.

Comparing two ML models requires statistical hypothesis testing to prove that Model A's performance gain over Model B is statistically significant. Standard Student's t-test violates independence assumptions when run on overlapping cross-validation folds (Dietterich, 1998). Recommended techniques include 5x2-fold Cross-Validation Paired t-test, McNemar's Test (for paired binary classification outputs), and Non-Parametric Bootstrap Resampling to construct confidence intervals around metric differences.

SCROLL · SAVE · TAP TO GO DEEPER