Error loading data into Stepwise regression model

Viewed 18

I am using Python and trying fit a stepwise backward logistic regression on a dataset of several IVs and one DV. I found the below code on Kaggle, but cannot seem to figure out how to load my dataset into the model.

https://www.kaggle.com/code/talhahascelik/automated-stepwise-backward-and-forward-selection/script

I have my data set up like so:

df = pd.read_csv('CNF_acute_cases.csv')

X = df[[ 'SC_1','SC_2','SC_3','SC_4','SC_5','SC_6','SC_7','TC_8','TC_9','TC_10']] #continous measurments
y =  df[[ 'Acute_CNF',]] #binary case v control 

#....Link has the full code....
## Fitting backwards selection

__backwardSelectionRaw__(X,y, model_type ="logistic",elimination_criteria = "aic", sl=0.05)


Unfortunately this gives me the error:

PatsyError: model is missing required outcome variables

The attached guidance implies X and y on pandas data frames should be fine. But reading up on the error, it seems I should load my data like this:

f1 = 'Acute_CNF ~ SC_1+SC_2+SC_3+SC_4+SC_5+SC_6+SC_7+TC_8+TC_9+TC_10'

If that's true - how can I load the above arrangement into the backwardSelectionRaw function? The code explicitly asks for an X and y pandas dataframe..

Apologies I'm sure this is super basic stuff. I'm clinical and have been getting by using mostly the simpler elements of Statsmodels. Some elements of Python have been tricky to figure out...

Many thanks for any advice!

Mak

0 Answers
Related