CertSafari
    Snowflake SnowPro Advanced: Data Scientist (DSA-C03)· Lessons

    Domain 3 · Lesson 12/16

    Validating classification and regression models: metrics, thresholds and residuals

    Validate a data science model.

    21 min read
    6.2% of exam
    8 sources
    Published 20 Oct 2026
    Docs as of 4 Oct 2026

    What you will be able to do

    • Read a confusion matrix and derive accuracy, precision, recall and F1 from its four cells
    • Explain why accuracy misleads on imbalanced classes and pick the metric that matches the costly error
    • Calculate the expected payout of a classifier and choose its operating threshold from the ROC trade-off
    • Compare MAE, MSE, RMSE and R² for a regression model and read a residual plot for bias and missed patterns
    • Use Snowflake ML evaluation methods whose metrics come from held-out rows

    Key concept

    Confusion matrix — A count of held-out predictions split by actual class and predicted class. For a binary model that gives four cells: true positives, false positives, false negatives and true negatives. Every classification metric is a ratio of these cells, and when you price each cell the matrix also gives you the model's payout.

    1.Where validation numbers come from

    Validation tells you how well a model predicts rows it has never seen. That is the only question the business cares about, so every metric on this page has to be computed on held-out data: a hold-out split or cross-validation folds. Both are covered in Train/validation hold-out and cross-validation. Score a model on its own training rows and every metric looks better than it really is, because the model is being graded on answers it has already memorised.

    Snowflake's ML Functions follow this rule automatically. A classification model created with evaluation enabled takes a random sample out of the input, trains a separate model without those rows, and then predicts on the sample. The test_fraction key in EVALUATION_CONFIG sets how big that sample is. Every evaluation method labels its output with dataset_type = EVAL, which marks the numbers as held-out results. Forecasting models do the same with time-series cross-validation: they train on subsets of the history and predict the withheld periods.

    The four evaluation methods of a SNOWFLAKE.ML.CLASSIFICATION modelsql
    CALL <model_name>!SHOW_EVALUATION_METRICS();
    CALL <model_name>!SHOW_GLOBAL_EVALUATION_METRICS();
    CALL <model_name>!SHOW_THRESHOLD_METRICS();
    CALL <model_name>!SHOW_CONFUSION_MATRIX();

    Each method answers a different question. SHOW_EVALUATION_METRICS returns precision, recall and F1 for each class. SHOW_GLOBAL_EVALUATION_METRICS averages those per-class figures into one model-wide number, using macro averaging. SHOW_THRESHOLD_METRICS returns counts and rates at each probability threshold, which is the raw material for an ROC curve. SHOW_CONFUSION_MATRIX returns the cell counts that everything else is built from.

    Checkpoint 1 of 9· Fill the gap

    You want to plot an ROC curve for a SNOWFLAKE.ML.CLASSIFICATION model so you can compare operating thresholds. Which method completes the call?

    CALL <model_name>! ? ();

    Sources1234

    2.Reading the confusion matrix: accuracy, precision, recall and F1

    A confusion matrix has a cell for every pair of actual class and predicted class. Correct predictions sit on the diagonal and errors sit off it, so a good model piles its counts on the diagonal. In a binary model, call one class positive. A true positive (TP) is a positive the model caught. A false positive (FP) is a negative it wrongly flagged. A false negative (FN) is a positive it missed. A true negative (TN) is a negative it correctly passed.

    SHOW_CONFUSION_MATRIX output for a binary model, evaluated on held-out rowstext
    +--------------+--------------+-----------------+-------+------+
    | DATASET_TYPE | ACTUAL_CLASS | PREDICTED_CLASS | COUNT | LOGS |
    |--------------+--------------+-----------------+-------+------|
    | EVAL         | false        | false           |    37 | NULL |
    | EVAL         | false        | true            |     1 | NULL |
    | EVAL         | true         | false           |     0 | NULL |
    | EVAL         | true         | true            |    22 | NULL |
    +--------------+--------------+-----------------+-------+------+
    Classification metrics as ratios of the four cells
    MetricComputed asQuestion it answers
    accuracy(TP + TN) / all predictionsHow often is any prediction right?
    precisionTP / (TP + FP)Of the rows flagged positive, how many really are?
    recall (sensitivity, tpr)TP / (TP + FN)Of the real positives, how many were caught?
    fprFP / (FP + TN)Of the real negatives, how many were wrongly flagged?
    f1harmonic mean of precision and recallIs the model balanced between the two?
    supportTP + FNHow many actual instances of the class exist?

    Accuracy can mislead badly when one class is rare. Picture 1,000 transactions, 10 of them fraud, and a model that never flags anything. It scores 990 correct out of 1,000, which is 99% accuracy, yet its recall is zero and it catches no fraud at all. The majority class swamps the figure. This is why each class gets its own precision, recall and F1, and why support is reported next to them: it shows how many rows each per-class number rests on.

    Pick the metric whose denominator holds the error you care about. Recall is the metric for a disease screen: a missed case (FN) is catastrophic and a false alarm only costs a cheap follow-up test, and recall falls with every FN. Precision is the metric when acting on a flag is expensive, because it falls with every FP. Specificity is the share of real negatives correctly cleared, which equals 1 − FPR. It is the wrong focus when the danger lies in the positives you miss. F1 is the harmonic mean of precision and recall, so it stays low unless both are reasonable.

    Checkpoint 2 of 9· Check yourself

    A loan-default model is scored on 2,000 held-out applications. Only 20 of them defaulted. The evaluation reports 99% accuracy. What should the reviewer conclude?

    Checkpoint 3 of 9· Exam question

    A hospital builds a screening model for a serious disease that treatment can cure if caught early. A follow-up test for a false alarm is cheap, but a missed case is catastrophic. Which metric should the data scientist prioritize when validating candidate models?

    Sources15

    3.Decision thresholds, ROC curves and AUC

    A classifier outputs a probability, and the threshold turns that probability into a label. A row is labelled positive when its predicted probability exceeds the threshold. Lower the threshold and more rows get flagged: recall rises, but more negatives slip through as false positives, so precision usually drops. Raise it and the reverse happens. Every confusion matrix belongs to one particular threshold.

    SHOW_THRESHOLD_METRICS lays out that trade-off. For each class it returns rows with a threshold running from 0 to 1, and for each threshold the tp, fp, tn and fn counts plus precision, recall, f1, tpr and fpr. In these rows, every instance outside the class being scored counts as negative, so a multi-class model is evaluated one class against the rest.

    The ROC curve plots tpr on the y-axis against fpr on the x-axis, with one point per threshold. The top-left corner (TPR 1, FPR 0) is a perfect model. The diagonal, where TPR equals FPR, is what random guessing gives you. AUC is the area under the curve: one number summarising performance across every threshold. That makes it useful for comparing two candidate models. It is no help in picking an operating point, because it describes all the thresholds at once.

    High AUC can still mean poor alerts. If positives are 0.1% of rows, even a small FPR applied to the huge negative class produces far more false positives than true positives. Precision collapses while the ROC curve looks excellent, because the ROC axes ignore class prevalence. For rare positives, plot the precision-recall curve from the same threshold rows. AUC also rewards ranking only: it measures whether positives score higher than negatives, not whether a predicted 0.3 really means a 30% chance. LogLoss, which Snowflake reports for the model as a whole, penalises probabilities that are confidently wrong.

    Checkpoint 4 of 9· Check yourself

    On held-out data, a fraud model scores an ROC AUC of 0.97. Fraud is 0.1% of transactions. After go-live, analysts find that most alerts are legitimate transactions. What is the best explanation and next step?

    Sources1

    4.Calculating expected payout and choosing the threshold

    Expected payout puts a business value on the confusion matrix. Give each cell a value per row: usually a gain for TP, a cost for FP and FN, and often zero for TN. Multiply each count by its value and add up all four. Costs go in as negative numbers. The common mistake is dropping a cell, most often the FN cost, which is invisible because the model never acted on those rows.

    Worked case: a held-out sample of 10,000 claims scored at one threshold gives TP = 50, FP = 200, FN = 30 and TN = 9,720. A caught bad claim saves $300, a wrongful investigation costs $10, a missed bad claim costs $400, and a correct pass is worth $0. Payout = 50 × 300 − 200 × 10 − 30 × 400 + 9,720 × 0 = 15,000 − 2,000 − 12,000 = $1,000. Leave out the FN term and you would report $13,000, overstating the model's value thirteen times over.

    Choosing a threshold means repeating the payout calculation at every candidate. With N rows and prevalence p, each threshold's TPR and FPR give the expected cell counts: TP = N·p·TPR, FN = N·p·(1 − TPR), FP = N·(1 − p)·FPR and TN = N·(1 − p)·(1 − FPR). Price them, add them up, and take the threshold with the highest total. The tp, fp, fn and tn columns of SHOW_THRESHOLD_METRICS already hold these counts for the evaluation sample, so you can price them directly.

    The shortcuts fail for a clear reason. The point nearest the top-left corner treats a missed positive and a false alarm as equally bad. When a miss costs ten times more, the best threshold sits further right on the curve, accepting extra false positives to catch more positives. The TPR = FPR point lies on the random-guess diagonal. A fixed 0.5 cut-off has no link to the cost matrix, and a high AUC cannot vouch for any particular threshold.

    Checkpoint 5 of 9· Check yourself

    A claims team has a SNOWFLAKE.ML.CLASSIFICATION model with evaluation enabled. A caught bad claim saves $300, a wrongful investigation costs $10, a missed bad claim costs $400 and a correct pass is worth $0. How should they choose the operating threshold?

    Checkpoint 6 of 9· Exam question

    A bank's fraud model scored 10,000 held-out transactions at a 0.5 threshold, giving TP=80, FP=120, FN=20 and TN=9,780. Each caught fraud nets $450 after recovery, each false alert costs $15 of analyst time, each missed fraud loses $500, and a correct pass is $0. What is the expected net payout on this sample?

    Checkpoint 7 of 9· Exam question

    A churn team plots the ROC curve for a gradient-boosted model. A missed churner costs the business about ten times more than an unnecessary retention offer, and about 8% of customers churn. How should the operating threshold be chosen from the ROC curve?

    Sources15

    5.Regression metrics: MAE, MSE, RMSE and R²

    Regression models predict a number, so validation measures how far each prediction lands from the actual value. In production that comparison is usually done by a model monitor: a Snowflake object that tracks one Model Registry model version over time. The monitor keeps monitoring logs in a table holding an ID, a timestamp, the features, the predictions and the observed ground truth, and computes quality metrics from them. For a regression model it accepts 'RMSE', 'MAE', 'MAPE' and 'MSE', and each needs a prediction_score column (the model's predicted number) and an actual_score column (the observed value). The forecasting function's evaluation reports MAE, MSE, MAPE and related error metrics, computed out of sample.

    Regression error metrics compared
    MetricHow it is builtWhen it is the better choice
    MAEmean of absolute errors, in the target's unitsEvery unit of error costs the same; robust to a few large misses
    MSEmean of squared errors, in squared unitsLarge errors are disproportionately harmful; also a common training loss
    RMSEsquare root of MSE, back in the target's unitsYou want MSE's penalty on big misses but a figure a stakeholder can read
    MAPEmean of absolute percentage errorsTargets span very different scales and relative error matters
    Forecasting evaluation metrics computed on withheld datatext
    +--------+--------------------------+--------------+--------------------+------+
    | SERIES | ERROR_METRIC             | METRIC_VALUE | STANDARD_DEVIATION | LOGS |
    +--------+--------------------------+--------------+--------------------+------+
    | NULL   | "MAE"                    |         2.49 |                NaN | NULL |
    | NULL   | "MAPE"                   |        0.084 |                NaN | NULL |
    | NULL   | "MDA"                    |         0.99 |                NaN | NULL |
    | NULL   | "MSE"                    |        8.088 |                NaN | NULL |
    | NULL   | "SMAPE"                  |        0.077 |                NaN | NULL |
    | NULL   | "WINKLER_ALPHA=0.05"     |       12.101 |                NaN | NULL |
    | NULL   | "COVERAGE_INTERVAL=0.95" |            1 |                NaN | NULL |
    +--------+--------------------------+--------------+--------------------+------+

    The gap between RMSE and MAE says something about the errors. In the output above, MSE is 8.088, so RMSE is about 2.84, a little above the MAE of 2.49. RMSE can never fall below MAE, and the wider the gap, the more the error total comes from a few large misses rather than many small ones. STANDARD_DEVIATION is NaN here because the default of one split produces a single validation set, so there is nothing to spread across.

    R² measures the share of the target's variance the model explains: 1 is perfect, and 0 is no better than always predicting the mean. On training data, adding features almost never lowers R², even when the features are noise. A rise in training R² paired with worse validation error is overfitting, not progress. Compute R² on held-out rows, as the snippet below does on test_df.

    Computing MSE and R² on a held-out test split for a Snowpark ML XGBRegressorpython
    from sklearn.metrics import mean_squared_error, r2_score
    
    predictions = regressor.predict(test_df)
    predictions_pd = predictions.to_pandas()
    
    mse = mean_squared_error(predictions_pd["ETA_MINUTES"], predictions_pd["predicted_eta"])
    r2 = r2_score(predictions_pd["ETA_MINUTES"], predictions_pd["predicted_eta"])

    Checkpoint 8 of 9· Match them up

    Match each regression error metric to how it is built and when it is the better choice.

    Tap a term, then the definition that fits it.

    Sources6783

    6.Reading residual plots in context

    A residual is the actual value minus the predicted value for one held-out row: actual_score minus prediction_score. Error metrics boil residuals down to a single number. A residual plot keeps every point, usually against the predicted value or against time, so you can see where the model goes wrong as well as how much.

    A healthy residual plot is a shapeless band centred on zero. Each departure from that has a specific reading:

    • A band shifted above or below zero is bias: the model under- or over-predicts across the board, which the mean residual shows directly.
    • A curve, such as positive residuals at both ends and negative in the middle, means a relationship the model treats as straight is really bent.
    • A funnel that widens as predictions grow means errors scale with the target's size, so a single RMSE understates the error on large values.
    • Runs of same-signed residuals over time, especially ones that repeat on a calendar cycle, are seasonality or trend the model has not captured. The fix is to add the missing seasonal or trend features and validate again.

    Interpret the plot in the target's own units and against the business decision. A residual of ±3 minutes is noise for a taxi ETA but serious for an ambulance dispatch model. Bias that sits only in the high-value region can matter more than a higher RMSE spread evenly across every row. The low RMSE in the weekly sales case does not rescue the model: the repeating runs mean its errors are predictable, and predictable errors are signal the model failed to learn.

    Checkpoint 9 of 9· Check yourself

    To see where a regression model's errors occur, and not just how big they are overall, an analyst wants a residual plot built from the data in its model monitor. Which approach gives them that plot?

    Sources63

    Practise it for real

    Evaluate a binary SNOWFLAKE.ML.CLASSIFICATION model and turn its held-out results into a payout-based threshold choice

    1. 1.Run CALL <model_name>!SHOW_CONFUSION_MATRIX(); on a classification model created with evaluation enabled.

      Why: The four cell counts are the basis of every metric and of the payout.

      You should see: Rows with DATASET_TYPE EVAL, one per combination of ACTUAL_CLASS and PREDICTED_CLASS, each with a COUNT.

    2. 2.Run CALL <model_name>!SHOW_EVALUATION_METRICS(); and check that its precision and recall for the positive class match your hand calculation from the matrix.

      Why: Confirms you are reading TP, FP and FN from the right cells.

      You should see: Per-class rows with ERROR_METRIC names such as Precision, Recall and F1 and their METRIC_VALUE.

    3. 3.Run CALL <model_name>!SHOW_THRESHOLD_METRICS(); and keep the rows for the positive class.

      Why: Each row holds the counts at one threshold: the ROC trade-off as data.

      You should see: Rows with threshold, tpr, fpr, tp, fp, tn and fn for each threshold between 0 and 1.

    4. 4.For each threshold row, compute tp × gain + fp × FP cost + fn × FN cost + tn × TN value using your business's cost matrix, and select the threshold with the highest total.

      Why: The operating threshold should maximise expected payout, not follow 0.5 or the top-left corner.

      You should see: A single threshold, usually not 0.5, plus the payout it earns on the evaluation sample.

    Stuck? Get a nudge

    If the best threshold sits at the very edge of the range, re-check the signs: costs must enter as negative values.

    Sources

    (8)

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “A new model is trained without these rows, and then the rows are used as inference input.”
      ↩︎ Where validation numbers come from
      “The random sample portion can be configured using the test_fraction key in the EVALUATION_CONFIG object.”
      ↩︎ Where validation numbers come from
      “The objective is to maximize the number of instances on the diagonal of the matrix while minimizing the number of off-diagonal instances.”
      ↩︎ Reading the confusion matrix: accuracy, precision, recall and F1
      “This metric can be misleading in unbalanced cases.”
      ↩︎ Reading the confusion matrix: accuracy, precision, recall and F1
      “Recall (Sensitivity): The ratio of true positives to the total actual positives.”
      ↩︎ Reading the confusion matrix: accuracy, precision, recall and F1
      “Precision: The ratio of true positives to the total predicted positives.”
      ↩︎ Reading the confusion matrix: accuracy, precision, recall and F1
      “F1 Score: The harmonic mean of precision and recall.”
      ↩︎ Reading the confusion matrix: accuracy, precision, recall and F1
      “The sample is classified as belonging to a class if the predicted probability of being in that class exceeds the specified threshold.”
      ↩︎ Decision thresholds, ROC curves and AUC
      “True positive rate (TPR): The proportion of actual positive instances that the model correctly identifies (equivalent to Recall).”
      ↩︎ Decision thresholds, ROC curves and AUC
      “False positive rate (FPR): The proportion of actual negative instances that were incorrectly predicted as positive.”
      ↩︎ Decision thresholds, ROC curves and AUC
      “considering the negative class as every instance that does not belong to the class being considered”
      ↩︎ Decision thresholds, ROC curves and AUC
      “Logistic Loss (LogLoss) is calculated for the model as a whole.”
      ↩︎ Decision thresholds, ROC curves and AUC
      “This can be used to plot ROC and PR curves or do threshold tuning if desired.”
      ↩︎ Calculating expected payout and choosing the threshold
      “comparing predicted and actual values and evaluating its ability to correctly identify positive and negative instances”
      ↩︎ Key concept
      “This metric can be misleading in unbalanced cases.”
      ↩︎ Exam trap 1
      “This can be used to plot ROC and PR curves or do threshold tuning if desired.”
      ↩︎ Exam trap 2
      “A new model is trained without these rows, and then the rows are used as inference input.”
      ↩︎ Exam trap 4
      “an overall measure of how well the model is performing. This metric can be misleading in unbalanced cases.”
      ↩︎ Checkpoint
      “This can be used to plot ROC and PR curves or do threshold tuning if desired.”
      ↩︎ Checkpoint
    2. 3.
      “Those models are then used to predict your target metric on the withheld data”
      ↩︎ Where validation numbers come from
      “When n_splits is 1 (the default), the standard deviation for evaluation metric values is NULL, as only a validation dataset is used.”
      ↩︎ Regression metrics: MAE, MSE, RMSE and R²
      “allowing the function to compare those predictions to actual values in your historical data.”
      ↩︎ Reading residual plots in context
    3. 4.
      “The method of aggregation used to calculate overall metrics from the individual class metrics, currently MACRO.”
      ↩︎ Where validation numbers come from
    4. 5.
      “The support (true positives plus false negatives) for the given class.”
      ↩︎ Reading the confusion matrix: accuracy, precision, recall and F1
      “Threshold used to generate predictions.”
      ↩︎ Calculating expected payout and choosing the threshold
      “Total count of false negatives in the given class.”
      ↩︎ Exam trap 3
    5. 6.
      “Valid values if the model monitor is attached to a regression model: 'RMSE' 'MAE' 'MAPE' 'MSE'”
      ↩︎ Regression metrics: MAE, MSE, RMSE and R²
      “RMSE: Requires the prediction_score and actual_score columns”
      ↩︎ Regression metrics: MAE, MSE, RMSE and R²
      “RMSE: Requires the prediction_score and actual_score columns”
      ↩︎ Reading residual plots in context
    6. 7.
      “The monitoring logs are stored in a table that contains an ID, a timestamp, features, predictions, and a ground truth label”
      ↩︎ Regression metrics: MAE, MSE, RMSE and R²
      “Each model version can have exactly one monitor, and each monitor can monitor exactly one model version”
      ↩︎ Regression metrics: MAE, MSE, RMSE and R²
    7. 8.
      “Returns out-of-sample evaluation metrics generated using time-series cross validation.”
      ↩︎ Regression metrics: MAE, MSE, RMSE and R²
      “MAE: Mean Absolute Error. MAPE: Mean Absolute Percentage Error. MDA: Mean Directional Accuracy. MSE: Mean Squared Error.”
      ↩︎ Checkpoint

    Ready to test yourself?

    Practise the 22 questions on this subdomain.

    Spotted a mistake, or was something unclear? Tell us.