A calibration curve for rate predictions sorts policies by predicted frequency, cuts them into groups, and compares the average predicted frequency with the average observed frequency in each group.
Implement:
count_calibration(pred_freq, obs_freq, exposure, n_bins):
pred_freq in increasing order (use a stable sort so ties keep their input order).n_bins consecutive groups of nearly equal size: with rows, the first groups get rows and the rest get .Return (centers, mean_pred, mean_obs) as arrays of length n_bins, where centers[k] is the bin's position on the "fraction of samples sorted by prediction" axis. Assume .
total_claims(pred_freq, obs_freq, exposure): return (predicted, observed) total claim counts, and .