Skip to content
elevatedevco

Machine Learning

Model evaluation and metrics (advanced)

Learn Model evaluation and metrics (advanced): 34 practice questions and answers with an interactive quiz — from the offline AI Learning app.

Professional34 questions34 quiz questions

Questions & Answers

Tap a question to reveal its answer. Written for self-study and interview preparation.

Why can a model with high AUC-ROC still perform poorly in a highly imbalanced fraud-detection setting, and what metric better reflects ranking quality there?

AUC-ROC measures the probability that a random positive ranks above a random negative, but because the false-positive rate uses the large negative count as denominator, even thousands of false positives barely move it under heavy imbalance. AUC-PR (average precision) is far more sensitive because precision directly reflects the proportion of true positives among predicted positives, exposing degradation that ROC hides.

What is the key difference between calibration and discrimination, and can a model be perfectly calibrated yet useless?

Discrimination is the ability to rank positives above negatives (measured by AUC), while calibration is whether predicted probabilities match observed frequencies. A model that always outputs the base rate p (e.g., 0.1) is perfectly calibrated but has no discrimination (AUC=0.5), so it is useless for ranking or decision-making.

How does the Expected Calibration Error (ECE) work, and what is a known weakness of it?

ECE bins predictions by confidence, computes the absolute gap between average confidence and average accuracy in each bin, and takes a sample-weighted average of those gaps. Its weaknesses are sensitivity to the number/placement of bins and that it can mask compensating over- and under-confidence within a bin, so adaptive binning or proper scores (Brier, log loss) are often preferred.

import numpy as np
def ece(probs, labels, n_bins=10):
    bins = np.linspace(0,1,n_bins+1)
    e = 0.0
    for i in range(n_bins):
        m = (probs>bins[i]) & (probs<=bins[i+1])
        if m.sum()==0: continue
        acc = labels[m].mean(); conf = probs[m].mean()
        e += m.mean()*abs(acc-conf)
    return e
Why is log loss (cross-entropy) called a 'proper scoring rule' and what behavior does that property guarantee?

A proper scoring rule is minimized in expectation when the model reports its true belief about the probability, so it cannot be gamed by hedging. Log loss is strictly proper, meaning the unique optimum is reporting the true conditional probability, which incentivizes honest, well-calibrated probabilistic forecasts (unlike accuracy, which only depends on the argmax).

In multi-class classification, what is the difference between macro, micro, and weighted F1, and when would macro and micro diverge most?

Micro-F1 pools TP/FP/FN across all classes (dominated by frequent classes and, in single-label multiclass where each instance gets exactly one prediction, equals overall accuracy), macro-F1 averages per-class F1 with equal class weight, and weighted-F1 averages weighting by class support. Macro and micro diverge most under class imbalance when minority classes perform poorly, since macro penalizes that heavily while micro hides it.

What does the Brier score decompose into via the Murphy decomposition, and what does each component mean?

The Brier score decomposes into reliability (calibration error, lower is better), resolution (how much bin predictions vary from the base rate, higher is better), and uncertainty (irreducible variance of the outcome, p(1-p) at the base rate). Brier = Reliability - Resolution + Uncertainty, so a good model minimizes reliability while maximizing resolution.

When evaluating a ranking/recommendation system, what advantage does NDCG have over MAP?

NDCG incorporates graded (multi-level) relevance and applies a logarithmic position discount, normalizing by the ideal ranking so scores are comparable across queries. MAP assumes binary relevance and averages precision at relevant positions, so NDCG is preferred when relevance is graded (e.g., 0-5 ratings) and position-sensitive utility matters.

Why can optimizing for a single threshold-based metric like accuracy be misleading, and what does the Matthews Correlation Coefficient (MCC) add?

Accuracy can be high simply by predicting the majority class and ignores the confusion-matrix balance. MCC is a correlation between predicted and actual labels using all four cells (TP, TN, FP, FN), ranging from -1 to +1; it only yields a high score when the model does well on both classes, making it robust to imbalance.

What is the difference between BLEU and chrF for evaluating generated text, and why is chrF often preferred for morphologically rich languages?

BLEU is a word/token-level n-gram precision metric with a brevity penalty, while chrF is an F-score combining character n-gram precision and recall. chrF is preferred for morphologically rich or agglutinative languages because character n-grams capture partial word matches and inflectional variation that word-level BLEU misses entirely.

Why are embedding-based metrics like BERTScore considered improvements over BLEU/ROUGE, and what is a major limitation?

BERTScore matches candidate and reference tokens via contextual-embedding cosine similarity, capturing semantic equivalence and paraphrase that surface n-gram overlap metrics miss. Its limitations are dependence on the chosen encoder (domain/language coverage), sensitivity to embedding biases, higher compute cost, and that it still relies on references and can reward fluent-but-wrong text.

In LLM-as-a-judge evaluation, what biases must be controlled, and name two mitigation techniques.

Common biases include position bias (favoring the first/second response), verbosity bias (preferring longer answers), self-enhancement bias (favoring its own outputs), and formatting bias. Mitigations include randomizing/swapping the order and averaging both orders, using a rubric with reference answers, calibrating against human labels, and using a stronger or ensemble judge.

What is the purpose of a bootstrap confidence interval for a metric, and how does the paired bootstrap improve model comparison?

Bootstrapping resamples the test set with replacement many times to estimate the sampling distribution of a metric, giving a confidence interval without strong distributional assumptions. The paired bootstrap resamples the same instances for both models on each replicate and looks at the per-replicate difference, controlling for instance-level variance and yielding tighter, more powerful tests of whether one model truly beats another.

import numpy as np
def paired_bootstrap(metric, y, p1, p2, n=2000):
    n_obs=len(y); diffs=[]
    for _ in range(n):
        idx=np.random.randint(0,n_obs,n_obs)
        diffs.append(metric(y[idx],p1[idx])-metric(y[idx],p2[idx]))
    lo,hi=np.percentile(diffs,[2.5,97.5])
    return np.mean(diffs),(lo,hi)
How does threshold-moving differ from cost-sensitive learning, and how do you pick an optimal threshold for an asymmetric cost matrix?

Threshold-moving keeps the trained probabilistic model fixed and shifts the decision cutoff post hoc, while cost-sensitive learning bakes misclassification costs into the training objective (e.g., reweighting). For an asymmetric cost matrix (with zero cost for correct decisions) the Bayes-optimal threshold on a calibrated probability is t* = C_FP / (C_FP + C_FN), choosing positive when p > t*.

What is the difference between Platt scaling and isotonic regression for calibration, and when is each appropriate?

Platt scaling fits a parametric sigmoid (logistic) to map scores to probabilities, assuming a specific sigmoidal distortion, and works well with limited calibration data. Isotonic regression fits a non-parametric monotonic step function, is more flexible for arbitrary monotone miscalibration, but needs more data and risks overfitting on small sets.

Why is temperature scaling popular for calibrating deep neural networks, and what does it leave unchanged?

Temperature scaling divides the logits by a single learned scalar T before softmax, optimized on a validation set to minimize NLL; it is the simplest accuracy-preserving calibration method. Because it is a monotonic transform of all logits by the same factor, it leaves the argmax (and thus accuracy and ROC/AUC ranking) unchanged while improving confidence calibration.

What is the multiple-comparisons problem in model evaluation, and how does it inflate false discoveries when picking the 'best' of many models?

When you evaluate many models/hyperparameters on the same validation set, the maximum observed score is an optimistically biased estimate because some models look good by chance. This is winner's-curse / multiple-testing inflation; remedies include a held-out test set used once, nested cross-validation, and correction procedures (Bonferroni, Benjamini-Hochberg) when reporting significance.

Why should you use stratified or grouped/time-series cross-validation instead of plain k-fold in certain scenarios?

Plain random k-fold can leak information or distort class balance: stratified k-fold preserves class proportions in each fold (important for imbalance), grouped k-fold keeps all rows of a group (e.g., a patient) in one fold to prevent leakage, and time-series splits respect temporal order so the model never trains on the future. Choosing the wrong scheme produces optimistic, non-generalizable estimates.

What does it mean for a regression metric to be scale-dependent versus scale-independent, and give an example of each plus a pitfall of MAPE.

Scale-dependent metrics (MAE, RMSE) are in the target's units and not comparable across datasets of different scales, while scale-independent metrics (MAPE, R^2) are dimensionless. MAPE's pitfall is that it is undefined or explodes when actual values are near zero and asymmetrically penalizes over- vs under-prediction, often making sMAPE or MASE better choices.

Why does RMSE penalize large errors more than MAE, and what does the gap between them tell you about the error distribution?

RMSE squares errors before averaging and square-rooting, so large residuals dominate, whereas MAE weights all errors linearly. Because RMSE >= MAE always, a large RMSE/MAE ratio indicates high variance in error magnitudes (a few large outlier errors), while a ratio near 1 indicates uniformly sized errors.

What is a reliability diagram, and how do you read overconfidence from it?

A reliability diagram plots mean predicted probability (x) against observed accuracy (y) per confidence bin, with the diagonal representing perfect calibration. Points falling below the diagonal mean predicted confidence exceeds actual accuracy (overconfidence), while points above indicate underconfidence; modern deep nets typically show the curve sagging below the diagonal at high confidence.

When comparing two classifiers on the same test set, why might McNemar's test be preferred over comparing accuracies directly?

McNemar's test focuses on the discordant pairs, the items where the two models disagree (one correct, one wrong), testing whether those off-diagonal counts are symmetric. This controls for the shared difficulty of commonly correct/wrong items and gives a valid significance test on paired predictions, which a raw accuracy difference cannot provide.

In retrieval-augmented generation (RAG) evaluation, what do 'faithfulness' and 'answer relevance' measure, and why are both needed?

Faithfulness (groundedness) measures whether the generated answer's claims are supported by the retrieved context, detecting hallucination, while answer relevance measures whether the answer actually addresses the user's question. Both are needed because an answer can be faithful to context yet off-topic, or on-topic yet unsupported, so they capture orthogonal failure modes alongside retrieval metrics like context precision/recall.

What is the difference between context precision and context recall in RAG retrieval evaluation?

Context recall measures whether all the information needed to answer (the ground-truth supporting facts) is present in the retrieved chunks, while context precision measures whether the retrieved/ranked chunks are actually relevant and ranked highly (low noise). High recall but low precision means relevant info is buried among distractors; both jointly diagnose retriever quality.

How does Cohen's kappa adjust raw agreement, and why can it be paradoxically low even with high observed agreement?

Cohen's kappa subtracts the agreement expected by chance from observed agreement and normalizes: kappa = (p_o - p_e)/(1 - p_e). Under highly skewed marginal distributions p_e becomes very high, so even ~95% observed agreement can yield a low kappa; this 'kappa paradox' is why prevalence-adjusted indices or Gwet's AC1 are sometimes used.

Why is R^2 alone insufficient for evaluating regression models, and what does adjusted R^2 fix?

In-sample R^2 never decreases when you add predictors, so it rewards complexity and can be high even with overfitting or spurious features; on out-of-sample data it can even be negative. Adjusted R^2 penalizes the number of predictors p relative to sample size n, only increasing if a new feature improves fit beyond what chance predicts, making it better for model comparison.

What is the difference between AIC and BIC for model selection, and how do their penalties differ asymptotically?

Both trade off log-likelihood against parameter count, but AIC uses a penalty of 2k while BIC uses k*ln(n). Because ln(n) > 2 for n > 7, BIC penalizes complexity more heavily and is consistent (selects the true model as n grows, if it is in the candidate set) whereas AIC is asymptotically efficient for prediction and tends to select larger models.

In a precision-recall tradeoff, what is the F-beta score and how does beta change the emphasis?

F-beta is the weighted harmonic mean of precision and recall: F_beta = (1+beta^2)*P*R / (beta^2*P + R). Beta > 1 (e.g., F2) weights recall more heavily, suitable when missing positives is costly (medical screening), while beta < 1 (e.g., F0.5) emphasizes precision when false positives are costly.

What is prediction/data drift versus concept drift, and which evaluation strategy detects concept drift?

Prediction/data drift is a change in the input or output distribution P(X) or P(y-hat), whereas concept drift is a change in the relationship P(y|X) so the same inputs map to different labels. Detecting concept drift requires labeled feedback to monitor metric degradation over time (e.g., rolling AUC, ADWIN/DDM tests), since input-only monitoring cannot see the changed decision boundary.

Why is PSI (Population Stability Index) used in production, and what thresholds typically signal concern?

PSI quantifies the shift in a variable's (or score's) distribution between a reference and a current period by summing (actual%-expected%)*ln(actual%/expected%) over bins. Common rules of thumb: PSI < 0.1 indicates no significant shift, 0.1-0.25 moderate shift warranting investigation, and > 0.25 a major population change likely requiring model recalibration or retraining.

What are group fairness metrics like demographic parity and equalized odds, and why can they be mutually unsatisfiable?

Demographic parity requires equal positive-prediction rates across groups, while equalized odds requires equal TPR and FPR across groups. An impossibility theorem shows that when base rates differ across groups, you generally cannot simultaneously satisfy calibration, equalized odds, and demographic parity, forcing an explicit tradeoff choice based on the application's harms.

How does a gain/lift chart help evaluate a model for targeted marketing, and what does a lift of 3 in the top decile mean?

A lift chart sorts instances by predicted score, bins them into deciles, and compares the response rate in each bin to the overall average. A lift of 3 in the top decile means that targeting that decile captures responders at three times the base rate, quantifying the model's business value for resource allocation independent of a fixed threshold.

What is the difference between online and offline evaluation, and why can offline metric gains fail to translate to online wins?

Offline evaluation scores a model on logged historical data, while online evaluation (A/B test) measures real user behavior on live traffic. Offline gains can fail online due to feedback loops, distribution shift from the new policy's actions, proxy-metric misalignment with business KPIs, and presentation/position effects that logged data cannot capture, which is why A/B tests remain the gold standard.

Why is perplexity an imperfect metric for evaluating modern LLMs, and what does it actually measure?

Perplexity is the exponentiated average negative log-likelihood per token, measuring how well the model predicts held-out text under its own tokenizer. It is imperfect for evaluating LLMs because it is tokenizer- and corpus-dependent (not comparable across models with different vocabularies), correlates only loosely with downstream task quality, and says nothing about instruction-following, factuality, or helpfulness.

When using top-k accuracy versus top-1 accuracy for large-label-space tasks, what does a large gap between them indicate?

Top-k accuracy counts a prediction correct if the true label is among the k highest-scored classes, while top-1 requires the single argmax to be right. A large top-5 minus top-1 gap indicates the model ranks the correct class highly but is confused among a few close competitors, suggesting the errors are 'near misses' rather than gross failures, common in fine-grained classification.

Put it into practice with AI Learning

This topic — and hundreds more — comes from our free, offline AI Learning app. Practice Q&A, quizzes and cheat sheets anywhere, no account needed.

  • Free
  • No account
  • Works offline
Coming soon toGoogle Play