Reproduce the insurance-claims comparison: predict the claim frequency (claims per policy-year) of motor policies observed for different lengths of time (the exposure, in years).
Inputs: a numeric design matrix X_train (no intercept column; add your own), claim counts claims, exposures exposure, and X_test. The observed frequency is .
fit_frequency_models(X_train, claims, exposure, X_test, ridge_lam=1.0, poisson_lam=1e-6, n_iter=30) returns a dict of predicted frequencies on X_test:
"dummy": the constant for every row."ridge": linear regression of on with sample weights = exposure, minimizing (intercept not penalized)."poisson": a Poisson GLM with log link, , fitted by Newton/IRLS for exactly n_iter iterations starting from , , minimizing the negative log-likelihood plus (intercept not penalized).evaluate(y_freq, pred, exposure) returns the list [mse, mae, deviance, total_pred, n_nonpos]:
pred against y_freq;total_pred , the predicted number of claims;n_nonpos, the number of rows with (as an int).