models extra: pip install "relativities[models]".
Prepare the experience
A frequency model reads one row per risk: its level of each rating factor, its earned exposure and its claim count. This page simulates five years of collision experience with a seeded generator, so the example runs alone. The simulated frequency is higher than the current factors in urban territories and lower elsewhere:Simulate the experience
Simulate the experience
truth and the simulation are ordinary Python and pandas:Fit the relativities
Fit a Poisson frequency model with territory as its factor and Los Angeles urban as the base level:lower and upper bound its 95% interval, and weight is its earned exposure. The model sums the rows into one cell per combination of levels before it fits, so a book of millions of rows fits in seconds.
Add more columns to factors to fit several rating factors together. offset names a column of multipliers to hold fixed, such as the current relativities of the other factors. The fit then measures what they leave unexplained. For claim severity, use family="gamma" with one row per claim and its amount as the target.
A level with zero claims would get a relativity of zero, so fit stops and names each such level. Group it with a neighboring level and fit again.
Build the proposed program
table gives one factor’s relativities as exact Decimals, rounded half up, with the base at exactly 1. Levels keep their type from the data, and a rater’s table keys are text, so convert numeric levels such as territory codes with astype(str) first:
with_tables compiles the edited table, so every key the rater looks up stays covered. Compare programs with a market rates current and proposed on the same book and shows each policy’s change. To keep total premium at the indicated level, search the collision base rate with search_lever, as Model a commercial book shows for a class rate.