the data can be obtained as explained in section or from statsmodels in the following waybwt sm datasets get_rdataset (birthwt ","mass"data here is some information about the explanatory variables that we will investigate agemother' age in years lwtmother' weight in lbs racemother' race ( white black othersmokesmoking status during pregnancy ( no yesptlno of previous premature labors hthistory of hypertension ( no yesuipresence of uterine irritability ( no yesftvno of physician visits during first trimester bwtbirth weight in grams we can see the structure of the variables via bwt info(check yourself that all variables are defined as quantitative (int howeverthe variables racesmokehtand ui should really be interpreted as qualitative (factorsto fix thiswe could redefine them with the method astypesimilar to what we did in alternativelywe could use the (construction in statsmodels formula to let the program know that certain variables are factors we will use the latter approach for binary features it does not matter whether the variables are interpreted as factorial or numerical as the numerical and summary results are identical we consider the explanatory variables lwtageuismokehtand two recoded binary variables ftv and ptl we define ftv if there was at least one visit to physicianand ftv otherwise similarlywe define ptl if there is at least one preterm birth in the family historyand ptl otherwise ftv (bwt['ftv '>= astype (intptl (bwt['ptl '>= astype (int forward selection forward selection and backward elimination the forward selection method is an iterative method for variable selection in the first iteration we consider which feature is the most significant in terms of its -value in the models bwt~ with {lwtagethis feature is then selected into the model in the second iterationthe feature that has the smallest -value in the models bwt~ + is selectedwhere and so on usually only features are selected that have pvalue of at most the following python program automates this procedure instead of selecting on the -value one could select on the aic or bic value