Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a 'patsy' formula syntax for specifying "baseline" models for 'statsmodels'

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?

like image 970
orome Avatar asked Feb 22 '26 13:02

orome


1 Answers

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
like image 123
elyase Avatar answered Feb 24 '26 02:02

elyase



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!