You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This module provides comprehensive calibration analysis tools for fraud detection models in the AstroML framework. Calibration curves help assess whether predicted fraud probabilities accurately reflect the true likelihood of fraudulent behavior.
🎯 Why Calibration Matters
Business Impact
Risk Assessment: Accurate probabilities enable better risk-based decisions
Regulatory Compliance: Many regulations require well-calibrated risk scores
# Apply temperature scaling for calibration improvementtemperature=1.5y_prob_calibrated=1/ (1+np.exp((np.log(y_prob/ (1-y_prob)) /temperature)))
# Compare before and aftermodels_data= {
'Before Calibration': (y_true, y_prob),
'After Calibration': (y_true, y_prob_calibrated)
}
fig=analyzer.plot_multiple_models(models_data)
plt.show()
📈 Visualization Components
1. Main Calibration Curve
X-axis: Mean predicted probability per bin
Y-axis: Actual fraud rate per bin
Perfect Calibration: Diagonal line (y = x)
Model Performance: Deviation from diagonal
2. Prediction Distribution
Green histogram: Legitimate transactions
Red histogram: Fraudulent transactions
Overlap: Model discrimination ability
3. Reliability Diagram
Bars: Calibration per bin
Color intensity: Sample count per bin
Reference line: Perfect calibration
4. Metrics Summary
Comprehensive calibration metrics
Sample statistics
Interpretation guidelines
🔍 Interpretation Guide
Calibration Curve Patterns
Pattern
Interpretation
Action
Close to diagonal
Well-calibrated
No action needed
Above diagonal
Underconfident
Apply temperature scaling
Below diagonal
Overconfident
Apply Platt scaling
S-shaped curve
Systematic bias
Consider isotonic regression
Common Issues & Solutions
Overconfidence
# Symptoms: High overconfidence metric, curve below diagonal# Solution: Temperature scaling with T > 1temperature=1.5y_prob_calibrated=1/ (1+np.exp((np.log(y_prob/ (1-y_prob)) /temperature))
Underconfidence
# Symptoms: High underconfidence metric, curve above diagonal # Solution: Temperature scaling with T < 1temperature=0.7y_prob_calibrated=1/ (1+np.exp((np.log(y_prob/ (1-y_prob)) /temperature))
Guo, C., et al. "On Calibration of Modern Neural Networks"
Naeini, M. P., et al. "Obtaining Well Calibrated Probabilities Using Bayesian Binning"
Kull, M., et al. "Beyond Temperature Scaling: Obtaining Well-Calibrated Multi-Class Probabilities"
🚀 Getting Started
Installation
# Calibration module is part of AstroML validation
from astroml.validation import calibration
Quick Start
# Run the complete example suitepythonexamples/calibration_example.py
Custom Analysis
# Create your own calibration analysisfromastroml.validation.calibrationimportCalibrationAnalyzeranalyzer=CalibrationAnalyzer()
fig=analyzer.plot_calibration_curve(y_true, y_prob, "My Model")
plt.show()
This calibration visualization system provides comprehensive tools for ensuring your fraud detection models produce reliable, trustworthy probability estimates that align with real-world outcomes.