python
16 lines · 1 tab
Dr. Elena Vasquez
Apr 2026
1 tab
import numpy as np
from sklearn.metrics import confusion_matrix
probabilities = model.predict_proba(X_valid)[:, 1]
thresholds = np.linspace(0.1, 0.9, 9)
for threshold in thresholds:
predictions = (probabilities >= threshold).astype(int)
tn, fp, fn, tp = confusion_matrix(y_valid, predictions).ravel()
print({
'threshold': round(float(threshold), 2),
'tp': int(tp),
'fp': int(fp),
'fn': int(fn),
'tn': int(tn),
})
1 file · python
Explain with highlit
Thresholds are policy decisions disguised as numbers. I use confusion matrices to make those tradeoffs concrete for stakeholders: how many risky accounts we block, how many fraud attempts slip through, and how much manual review load is created. This is often where model work turns into operational design.
Related snips
python
from sklearn.metrics import (
average_precision_score,
classification_report,
precision_recall_curve,
roc_auc_score,
)
Classification metrics beyond accuracy for imbalanced problems
classification-metrics
imbalanced-data
evaluation
by Dr. Elena Vasquez
1 tab
python
from sklearn.model_selection import StratifiedKFold, train_test_split, cross_validate
from sklearn.pipeline import Pipeline
from sklearn.impute import SimpleImputer
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
Train test split and stratified cross validation done properly
cross-validation
evaluation
scikit-learn
by Dr. Elena Vasquez
1 tab
python
from sklearn.ensemble import RandomForestClassifier, HistGradientBoostingClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import roc_auc_score
from sklearn.pipeline import Pipeline
from sklearn.impute import SimpleImputer
Baseline classifiers in scikit-learn for fast benchmark setting
scikit-learn
classification
baselines
by Dr. Elena Vasquez
1 tab
Share this code
Here's the card — post it anywhere.