I am going through a stats workbook with python, there is a practice hands on question on which i am stuck. Its related to Poisson regression and here is the problem statement:-
Perform the following tasks:
I am stuck with point 4 above. Can anyone help with this step?
Here is what i have done so far :-
import statsmodels.api as sm
import statsmodels.formula.api as smf
import numpy as np
df = sm.datasets.get_rdataset('Insurance', package='MASS', cache=False).data
poisson_model = smf.poisson('np.log(Holders) ~ -1 + Claims', df)
poisson_result = poisson_model.fit()
print(poisson_result.summary())

Now how to get sum of residuals?
np.sum(poisson_result.resid)
works fine
You have used the wrong variables to build the poisson model as pointed out by Karthikeyan. Use this instead,
poisson_model = smf.poisson('Claims ~ np.log(Holders)',df)
Try below code for Fresco play
import statsmodels.api as sm
import statsmodels.formula.api as smf
import pandas as pd
import numpy as np
df_insurance=sm.datasets.get_rdataset("Insurance","MASS")
df_data=df_insurance.data
insurance_model=smf.poisson('Claims ~ np.log(Holders)', df_data).fit()
print(np.cumsum(insurance_model.resid))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With