Visual Interpretation
๐ Purpose¶
This visual guide is designed to help analysts evaluate and explain the performance of classification models using intuitive and effective plots. It complements the Advanced Classifier Modeling Guidebook by focusing on diagnostics, interpretability, stakeholder communication, and visual storytelling.
๐งฎ 1. Confusion Matrix¶
๐ฏ Purpose:¶
Break down actual vs predicted class counts. Ideal for communicating results in simple binary or multiclass settings.
โ Visual Tips:¶
- Add count and percentage labels.
- Use heatmaps with color emphasis on misclassifications.
- Normalize by rows (recall) or columns (precision) based on goal.
from sklearn.metrics import ConfusionMatrixDisplay
ConfusionMatrixDisplay.from_predictions(y_test, y_pred, cmap="Blues", normalize=None)
๐ Use Cases:¶
- Binary classification summary
- Error audit for multiclass models
๐ 2. ROC Curve & AUC¶
๐ฏ Purpose:¶
Evaluate the modelโs ability to rank positive instances above negatives.
โ Interpretation:¶
- AUC = 1.0: Perfect ranking
- AUC = 0.5: Random guessing
- ROC closer to top-left = better classifier
from sklearn.metrics import roc_curve, roc_auc_score
fpr, tpr, _ = roc_curve(y_test, y_proba)
plt.plot(fpr, tpr, label=f"AUC = {roc_auc_score(y_test, y_proba):.2f}")
๐ Use Cases:¶
- Binary classifiers with probabilistic output
- High-stakes classification where ranking matters
๐ฟ 3. Precision-Recall Curve¶
๐ฏ Purpose:¶
More informative than ROC when classes are highly imbalanced.
โ Interpretation:¶
- Shows how precision changes as recall increases
- Area under PR curve (PR-AUC) valuable in imbalance-sensitive tasks
from sklearn.metrics import precision_recall_curve
precision, recall, _ = precision_recall_curve(y_test, y_proba)
plt.plot(recall, precision)
๐ Use Cases:¶
- Fraud detection, churn modeling, medical diagnosis
๐ 4. Calibration Curve¶
๐ฏ Purpose:¶
Assess how well predicted probabilities match actual observed outcomes.
โ Interpretation:¶
- Diagonal = perfect calibration
- Above = underconfident, below = overconfident
from sklearn.calibration import calibration_curve
prob_true, prob_pred = calibration_curve(y_test, y_proba, n_bins=10)
plt.plot(prob_pred, prob_true, marker='o')
๐ Use Cases:¶
- Risk modeling
- Post-hoc probability tuning
๐ช 5. Feature Importance Plots¶
๐ฏ Purpose:¶
Show which features most influence model predictions.
โ Tools:¶
.feature_importances_
from tree models- Permutation-based importance
- SHAP values for global or local importance
from sklearn.inspection import permutation_importance
results = permutation_importance(model, X_test, y_test)
๐ Use Cases:¶
- Model transparency in regulated domains
- Feature selection
๐ 6. SHAP Plots¶
๐ฏ Purpose:¶
Explain individual predictions or global feature patterns.
โ Plot Types:¶
- Summary plot (global importance)
- Dependence plot (interactions)
- Force plot (local explanation)
import shap
explainer = shap.TreeExplainer(model)
shap_values = explainer.shap_values(X_test)
shap.summary_plot(shap_values, X_test)
๐ Use Cases:¶
- Production explainability (black-box models)
- Trust-building in model audits
๐ผ๏ธ 7. Class Confidence Visualization¶
๐ฏ Purpose:¶
Visualize the confidence distribution of classifier predictions.
โ Plot Ideas:¶
- Histogram of
y_proba
- Bar chart of top-N class probabilities for individual predictions
- Misclassification overlay with low-confidence highlight
plt.hist(y_proba, bins=20)
plt.xlabel("Predicted Probability")
plt.ylabel("Frequency")
๐ Use Cases:¶
- Threshold tuning
- Model uncertainty audit
๐ 8. Visual Flow Template¶
Use Case | Recommended Visuals |
---|---|
Binary classification | Confusion matrix, ROC, PR curve |
Imbalanced classes | PR curve, calibration plot, confidence histogram |
Probabilistic models | Calibration curve, log-loss distribution |
Tree/ensemble models | SHAP summary, permutation importances |
Multiclass models | ROC-AUC (OvR), per-class confusion heatmap |
๐ TODO¶
- [ ] Add matplotlib/seaborn templates for each plot type
- [ ] Add multiclass PR curve and ROC-AUC demo
- [ ] Add visual glossary for presentations and stakeholders
- [ ] Build overlay toolkit: c