(x, y, clf, this_round, cutoff, n_iterations, delta, silent)
return criteria, real_vars['feature']
Function to run through each
    :param x: Input dataframe - X
    :param y: Target variable
    :param clf: the fully specified classifier passed in by user
    :param this_round: Round so it can be printed to screen
    :return: tuple - stopping criteria and the variables to keep
Function to run through each
    :param x: Input dataframe - X
    :param y: Target variable
    :param clf: the fully specified classifier passed in by user
    :param this_round: Round so it can be printed to screen
    :return: tuple - stopping criteria and the variables to keep
Function to run through each : param x : Input dataframe - X : param y : Target variable : param clf : the fully specified classifier passed in by user : param this_round : Round so it can be printed to screen : return : tuple - stopping criteria and the variables to keep
def _reduce_vars_sklearn(x, y, clf, this_round, cutoff, n_iterations, delta, silent):
    """
    Function to run through each
    :param x: Input dataframe - X
    :param y: Target variable
    :param clf: the fully specified classifier passed in by user
    :param this_round: Round so it can be printed to screen
    :return: tuple - stopping criteria and the variables to keep
    """
    #Set up the parameters for running the model in XGBoost - split is on multi log loss

    for i in range(1, n_iterations+1):
        # Create the shadow variables and run the model to obtain importances
        new_x, shadow_names = _create_shadow(x)
        clf = clf.fit(new_x, np.ravel(y))

        if i == 1:
            df = pd.DataFrame({'feature': new_x.columns})
            df2 = df.copy()
            pass

        try:
            importance = clf.feature_importances_
            df2['fscore' + str(i)] = importance
        except ValueError:
            print("this clf doesn't have the feature_importances_ method.  Only Sklearn tree based methods allowed")

        # importance = sorted(importance.items(), key=operator.itemgetter(1))

        # df2 = pd.DataFrame(importance, columns=['feature', 'fscore'+str(i)])
        df2['fscore'+str(i)] = df2['fscore'+str(i)] / df2['fscore'+str(i)].sum()
        df = pd.merge(df, df2, on='feature', how='outer')
        if not silent:
            print("Round: ", this_round, " iteration: ", i)

    df['Mean'] = df.mean(axis=1)
    #Split them back out
    real_vars = df[~df['feature'].isin(shadow_names)]
    shadow_vars = df[df['feature'].isin(shadow_names)]

    # Get mean value from the shadows
    mean_shadow = shadow_vars['Mean'].mean() / cutoff
    real_vars = real_vars[(real_vars.Mean > mean_shadow)]

    #Check for the stopping criteria
    #Basically looking to make sure we are removing at least 10% of the variables, or we should stop
    if (len(real_vars['feature']) / len(x.columns)) > (1-delta):
        criteria = True
    else:
        criteria = False

    return criteria, real_vars['feature']
def _reduce_vars_sklearn ( x , y , clf , this_round , cutoff , n_iterations , delta , silent ) : #Set up the parameters for running the model in XGBoost - split is on multi log loss for i in range ( 1 , n_iterations + 1 ) : # Create the shadow variables and run the model to obtain importances new_x , shadow_names = _create_shadow ( x ) clf = clf . fit ( new_x , np . ravel ( y ) ) if i == 1 : df = pd . DataFrame ( { 'feature' : new_x . columns } ) df2 = df . copy ( ) pass try : importance = clf . feature_importances_ df2 [ 'fscore' + str ( i ) ] = importance except ValueError : print ( "this clf doesn't have the feature_importances_ method.  Only Sklearn tree based methods allowed" ) # importance = sorted(importance.items(), key=operator.itemgetter(1)) # df2 = pd.DataFrame(importance, columns=['feature', 'fscore'+str(i)]) df2 [ 'fscore' + str ( i ) ] = df2 [ 'fscore' + str ( i ) ] / df2 [ 'fscore' + str ( i ) ] . sum ( ) df = pd . merge ( df , df2 , on = 'feature' , how = 'outer' ) if not silent : print ( "Round: " , this_round , " iteration: " , i ) df [ 'Mean' ] = df . mean ( axis = 1 ) #Split them back out real_vars = df [ ~ df [ 'feature' ] . isin ( shadow_names ) ] shadow_vars = df [ df [ 'feature' ] . isin ( shadow_names ) ] # Get mean value from the shadows mean_shadow = shadow_vars [ 'Mean' ] . mean ( ) / cutoff real_vars = real_vars [ ( real_vars . Mean > mean_shadow ) ] #Check for the stopping criteria #Basically looking to make sure we are removing at least 10% of the variables, or we should stop if ( len ( real_vars [ 'feature' ] ) / len ( x . columns ) ) > ( 1 - delta ) : criteria = True else : criteria = False return criteria , real_vars [ 'feature' ]