1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Find the sum of the residuals

Discussão em 'Python' iniciado por Stack, Dezembro 1, 2025.

  1. Stack

    Stack Membro Participativo

    I am doing a hands on exercise of Poissons Regression of Stats with Python in Fresco Play. Problem statement is like: Load the R dataset Insurance from the MASS package. Capture the data as a pandas dataframe. Build a Poisson regression model with a log of an independent variable Holders, and dependent variable Claims. Fit the model with data, and find the sum of the residuals.

    I am stuck with the last line i.e. Sum of Residuals

    I used np.sum(model.resid). But answer is not accepted

    Here is my code

    import statsmodels.api as sm
    import statsmodels.formula.api as smf
    import numpy as np

    INS_data = sm.datasets.get_rdataset('Insurance','MASS').data
    model = smf.poisson('Claims ~ np.log(Holders)', INS_data).fit()
    print(np.sum(model.resid))

    Continue reading...

Compartilhe esta Página