Machine LearningClassification Evaluation

How do you choose a classification threshold?

Choose a classification threshold based on the cost of wrong decisions and the performance you need on unseen data—not automatically at 0.5. The threshold converts a model's probability or score into a final positive/negative decision.

What does the threshold do?

For a probability-based binary classifier:

Predict positive if P(positive | x) >= threshold
Otherwise predict negative

A threshold of 0.5 is a common starting point, but not universally optimal. Lowering it tends to catch more positive cases while creating more alerts; raising it generally reduces alerts but can miss positives.

Worked example: deciding which fraud alerts to investigate

Suppose 100 transactions are scored by a fraud model. Consider two candidate thresholds:

  • Threshold 0.70: TP=20, FP=5, FN=10, TN=65.
  • Threshold 0.40: TP=27, FP=15, FN=3, TN=55.

Assume each missed fraud costs ₹1,000, while each false alert costs ₹100 in investigation effort.

Cost at 0.70 = 10 * ₹1,000 + 5 * ₹100
             = ₹10,500

Cost at 0.40 = 3 * ₹1,000 + 15 * ₹100
             = ₹4,500

Threshold 0.40 is preferable under these assumed costs, despite producing more false alerts. If the relative costs changed, the preferred threshold might change too. These examples are hypothetical—not universal business-cost estimates.

How should you select a threshold?

  1. Define your positive class and operational goal. Is a missed fraud worse than a false alarm? Are investigators limited to a certain number of cases per day?
  2. Pick a metric or cost rule. Examples include minimizing expected misclassification cost, maximizing F1, or achieving at least 95% recall while keeping alert volume manageable.
  3. Collect validation predictions. Use out-of-sample probabilities or decision scores; avoid selecting a threshold on the same examples used to fit the classifier.
  4. Evaluate several candidate thresholds. For each, calculate TP, FP, FN, TN and the relevant metric or total cost.
  5. Choose the threshold using validation data only, then evaluate the selected model and threshold once on a separate, untouched test set.
  6. Monitor after deployment. Class prevalence, model calibration, and error costs may shift over time.

Python example: tune the threshold with cross-validation

PYTHON
from sklearn.datasets import make_classification from sklearn.linear_model import LogisticRegression from sklearn.model_selection import train_test_split, TunedThresholdClassifierCV from sklearn.metrics import make_scorer, f1_score from sklearn.pipeline import make_pipeline from sklearn.preprocessing import StandardScaler X, y = make_classification( n_samples=500, n_features=6, n_informative=4, n_redundant=0, weights=[0.85, 0.15], random_state=42 ) X_train, X_test, y_train, y_test = train_test_split( X, y, test_size=0.25, stratify=y, random_state=42 ) base_model = make_pipeline(StandardScaler(), LogisticRegression()) tuned = TunedThresholdClassifierCV( estimator=base_model, scoring=make_scorer(f1_score, pos_label=1), cv=5, ) tuned.fit(X_train, y_train) print("Chosen threshold:", round(tuned.best_threshold_, 3)) print("Held-out F1:", round(f1_score(y_test, tuned.predict(X_test)), 3))

TunedThresholdClassifierCV searches thresholds using cross-validation. Its default 5-fold approach avoids directly optimizing a threshold on the very same examples used to train each fold's underlying classifier. The final test set remains separate.

Important cautions

  • A better threshold does not improve underlying ranking quality: changing only the cutoff does not change ROC-AUC for unchanged scores.
  • Probabilities and decision scores differ: 0.5 is a probability cutoff, while some models' decision functions use 0 as the standard cutoff.
  • Calibration matters for probability-based cost rules: poorly calibrated probabilities may undermine theoretically justified cost thresholds.
  • Avoid tuning against test labels or reusing training predictions: either leaks information and can overstate performance.

In short: choose a threshold that matches the cost of false positives and false negatives or a clear performance constraint, tune it on validation data, and verify it on untouched test data.

References

#how to choose classification threshold#cost sensitive threshold tuning#binary classifier decision threshold example#TunedThresholdClassifierCV python#threshold selection validation dataset#machine-learning#classification-evaluation#decision-threshold#threshold-tuning#cost-sensitive-classification

Learning Sequence

Machine Learning Curriculum

78% Completed
Up NextMachine Learning

What is macro averaging in multiclass evaluation?

Explore Related Questions

Deepen your understanding across related Machine Learning topics.

Machinoai Logo
Machinoai

Your edge in the AI era. Deep dives into machine learning concepts, paper explainers, verified industry jobs, and developer tools.

© 2026 Machinoai. All rights reserved.