python
16 lines · 1 tab
Dr. Elena Vasquez
Apr 2026
1 tab
from sklearn.metrics import (
average_precision_score,
classification_report,
precision_recall_curve,
roc_auc_score,
)
probabilities = model.predict_proba(X_valid)[:, 1]
predictions = (probabilities >= 0.35).astype(int)
print('ROC AUC:', roc_auc_score(y_valid, probabilities))
print('PR AUC:', average_precision_score(y_valid, probabilities))
print(classification_report(y_valid, predictions, digits=3))
precision, recall, thresholds = precision_recall_curve(y_valid, probabilities)
print('threshold samples:', list(zip(thresholds[:5], precision[:5], recall[:5])))
1 file · python
Explain with highlit
Accuracy is a bad comfort metric when the positive class is rare. I care more about precision, recall, PR AUC, calibration, and how thresholding changes operational workload. The right metric depends on the cost of false negatives versus false positives, not on what is easiest to explain on a slide.
Share this code
Here's the card — post it anywhere.