Skip to content

Instantly share code, notes, and snippets.

@evu
Created August 20, 2021 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evu/370e2322f5e32913ea49a4de7bfea0ec to your computer and use it in GitHub Desktop.
Save evu/370e2322f5e32913ea49a4de7bfea0ec to your computer and use it in GitHub Desktop.
Poisson regression in python
import statsmodels.api as sm
from patsy import dmatrices
import numpy as np
y, X = dmatrices("time_s ~ cloud + model + sensor", data=df)
# Note that offset is in 100s of square miles
offset = np.asarray(df["sq_mi"]) / 100
m = sm.Poisson(y, X, offset=offset)
fitted = m.fit()
fitted.summary()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment