Missing intercepts of OLS Regression models in Python statsmodels

前端 未结 2 1388
悲哀的现实
悲哀的现实 2020-12-12 05:52

I am running a rolling for example of 100 window OLS regression estimation of the dataset found in this link (https://drive.google.com/drive/folders/0B2Iv8dfU4f

2条回答
  •  佛祖请我去吃肉
    2020-12-12 06:31

    Ok so I prepared this small example so you can visualize what a Poisson regression could do.

    import statsmodels as sm
    import matplotlib.pyplot as plt
    poi_model = sm.discrete.discrete_model.Poisson
    
    x = np.random.uniform(0, 20,1000)
    s = np.random.poisson( x*(0.5) , 1000)
    plt.bar(x,s)
    plt.show()
    

    This generates random poisson counts.

    Now the way to fit a poisson regression to the data is the following:

    my_model = poi_model(endog=s, exog=x)
    my_model = my_model.fit()
    my_model.summary()
    

    The summary displays a number of statistics but if you want to compute the mean square error you could do that like so:

    preds = my_model.predict()
    mse = np.mean(np.square(preds - s))
    

    If you want to predict new values do the following:

    my_model.predict(exog=new_value)
    

提交回复
热议问题