1

Is there a python equivalent for this R function:

stepAIC(model, direction="both")

It should be compatible with statsmodels GLM (I use sm.families.NegativeBinomial())

I found this but only forward direction is supported: https://qiita.com/mytk0u0/items/aa2e3f5a66fe9e2895fa (Python equivalent for R StepAIC for Logistic Regression (direction='Backwards'))

EDIT: I could use mytk0u0s solution for a backward implementation. But I don't know how to implement "both".

The direction argument of stepAIC controls the mode of the stepwise model search:

  • "backward": removes predictors sequentially from the given model. It produces a sequence of models of decreasing complexity until attaining the optimal one.
  • "forward": adds predictors sequentially to the given model, using the available ones in the data argument of lm. It produces a sequence of models of increasing complexity until attaining the optimal one.
  • "both" (default): a forward-backward search that, at each step, decides whether to include or exclude a predictor. Differently from the previous modes, a predictor that was excluded/included previously can be later included/excluded.

(https://bookdown.org/egarpor/PM-UC3M/lm-ii-modsel.html)

FLX
  • 301
  • 3
  • 12
  • Wrote the code but I don't know if I can publish it because it partly based on mytk0u0s solution. – FLX Jul 08 '22 at 13:24

0 Answers0