I would like to use formulas to specify a "baseline" model for some models fitting using statsmodels For example, I'd like to be able to specify a formula to pass to a olm or Logit model that simply predicts the mean of the observed dependent variable for all observations. I know that I can get these numbers simply by calculating the mean of the observations for the dependent variable, but I would like to have a model that produces these results (e.g. so I can use its methods). Is there a patsy syntax for accomplishing this?
If you use a formula with only the intercept term, then you will get the mean/average of the dependent variable:
import statsmodels.formula.api as smf
data={'y': [1,5,9], # mean(y) == 5
'X': [[2013], [0.001], [19.99]] # doesn't matter
}
model = smf.ols('y ~ 1', data=data).fit()
model.predict(3.14) # ==> 5
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