From Sums to Areas
Integration is the reverse of differentiation. While derivatives tell us the rate of change, integrals accumulate quantities over an interval. In ML, we use integrals to compute areas under curves like the ROC curve.
Riemann Sums
The area under a curve is approximated by summing rectangles. The height of each rectangle is the function value, and width is .
Left Riemann
Use left endpoint of each interval for height. Underestimates for increasing functions.
Right Riemann
Use right endpoint. Overestimates for increasing functions.
Midpoint Rule
Use midpoint. Generally more accurate than left or right.
Interactive Simulator
Adjust the number of rectangles and watch the Riemann sum converge to the true AUC as n increases.
Riemann Sum Simulator
Results
Why Integrate?
A single accuracy number can be misleading. Integration (AUC) summarizes performance across all specific thresholds.
As , the Riemann sum converges exactly to the AUC.
AUC-ROC: The Area Under the ROC Curve
The ROC (Receiver Operating Characteristic) curve plots True Positive Rate vs False Positive Rate at various classification thresholds. The Area Under this Curve (AUC) is a single number summarizing classifier performance.
AUC = 1.0
Perfect classifier. The curve hugs the top left corner.
AUC = 0.5
Random classifier. The curve is the diagonal line. No discrimination power.
Probabilistic Interpretation
AUC = P(classifier ranks a random positive higher than a random negative). If AUC = 0.8, given a random positive and negative sample, the model correctly ranks them 80% of the time.
Case Study: Bulb Defect Classifier
You train a model to detect defective bulbs. It outputs a probability score from 0 to 1. Let's compute the AUC step by step.
Example model outputs:
Step 1: Vary threshold from 0 to 1
At each threshold τ, predict "defective" if score ≥ τ. This gives different TPR/FPR pairs.
Step 2: Compute TPR and FPR at each threshold
True positives / All actual positives
False positives / All actual negatives
Step 3: Plot the ROC curve
Plot (FPR, TPR) for each threshold. Connect points to form curve from (0,0) to (1,1).
Step 4: Compute AUC using trapezoidal rule
For our example: AUC ≈ 0.94 (excellent discrimination)
Numerical Integration Methods
Trapezoidal Rule
Use trapezoids instead of rectangles. Error:
Simpson's Rule
Fit parabolas to three points. Error:
Monte Carlo Integration
Sample random points and average. Scales well to high dimensions unlike grid methods.
ML Applications
AUC-ROC
Threshold independent evaluation for binary classifiers. Used by sklearn.metrics.roc_auc_score.
AUC-PR
Precision Recall AUC. Better for imbalanced datasets where negatives dominate.
Expected Calibration Error
Integrate the gap between predicted probability and actual frequency. Uses binning (discrete integration).
ELBO in VAEs
The Evidence Lower Bound involves integrals over latent variables. Approximated via Monte Carlo sampling.