@@ -26,11 +26,13 @@ class ModelSelection(object):
2626 ***ATTRIBUTES***
2727 :_partition_dict: Dict with partitioned DFs X/Y train/selection/validation
2828 :_optimal_nvars: Optimal number of variables
29+ :positive_only: Whether all coeficients should be positivr
2930 ----------------------------------------------------
3031 '''
3132
32- def __init__ (self , verbose ):
33+ def __init__ (self , verbose , positive_only ):
3334 self .verbose = verbose
35+ self .positive_only = positive_only
3436
3537
3638 def fit (self , df_trans , df_unisel , modeling_nsteps , forced_vars , excluded_vars , name ):
@@ -93,7 +95,7 @@ def _getTrainSelectValidXY(self, df):
9395
9496 return dict_out
9597
96- def _forwardSelection (self , df_sel , forced_vars , excluded_vars , positive_only = True ):
98+ def _forwardSelection (self , df_sel , forced_vars , excluded_vars ):
9799 '''
98100 Method performs forward selection
99101 Returns DF with performance
@@ -121,6 +123,7 @@ def _forwardSelection(self, df_sel, forced_vars, excluded_vars, positive_only=Tr
121123 df_forward_selection = pd .DataFrame (None ,columns = [
122124 'step' ,
123125 'coef' ,
126+ 'intercept' ,
124127 'all_coefs_positive' ,
125128 'auc_train' ,
126129 'auc_selection' ,
@@ -178,6 +181,7 @@ def _forwardSelection(self, df_sel, forced_vars, excluded_vars, positive_only=Tr
178181 df_forward_selection .loc [row ] = [
179182 step , #Step
180183 logit .coef_ , #coef
184+ logit .intercept_ , #intercept
181185 all_coefs_positive , #all_coefs_positive
182186 AUC_train , #auc_train
183187 AUC_selection , #auc_selection
@@ -194,12 +198,14 @@ def _forwardSelection(self, df_sel, forced_vars, excluded_vars, positive_only=Tr
194198 row += 1
195199
196200 #Only positive coefs
197- if positive_only :
201+ if self . positive_only :
198202 all_coefs_negative = len (df_forward_selection [(df_forward_selection ['all_coefs_positive' ] == True ) & (df_forward_selection ['step' ] == step )]) == 0
199203
200204 if all_coefs_negative :
201205 if self .verbose :
202- print ('No models with only positive coefficients, step skipped.' )
206+
207+ print ('No models with only positive coefficients, following step skipped.' )
208+ print (df_forward_selection [(df_forward_selection ['all_coefs_positive' ] == True ) & (df_forward_selection ['step' ] == step )])
203209 #Skip the next steps and go the next iteration
204210 #The fitted models are not of interest if the user explicitly
205211 # says positive_only=True
0 commit comments