feature-engineering-and-data-transformations/using-toy-exmaples/feature_selection/filter_method.py
def constant_feature_detect(data,threshold=0.98):
    """ detect features that show the same value for the 
    majority/all of the observations (constant/quasi-constant features)
    
    Parameters
    ----------
    data : pd.Dataframe
    threshold : threshold to identify the variable as constant
        
    Returns
    -------
    list of variables names
    """
    
    data_copy = data.copy(deep=True)
    quasi_constant_feature = []
    for feature in data_copy.columns:
        predominant = (data_copy[feature].value_counts() / np.float(
                      len(data_copy))).sort_values(ascending=False).values[0]
        if predominant >= threshold:
            quasi_constant_feature.append(feature)
    print(len(quasi_constant_feature),' variables are found to be almost constant')    
    return quasi_constant_feature
 detect features that show the same value for the 
    majority/all of the observations (constant/quasi-constant features)
    
    Parameters
    ----------
    data : pd.Dataframe
    threshold : threshold to identify the variable as constant
        
    Returns
    -------
    list of variables names
    
detect features that show the same value for the
majority/all of the observations (constant/quasi-constant features)

Parameters

data : pd.Dataframe
threshold : threshold to identify the variable as constant

Returns

list of variables names
detect features that show the same value for the majority / all of the observations ( constant / quasi - constant features ) Parameters data : pd . Dataframe threshold : threshold to identify the variable as constant Returns list of variables names
def constant_feature_detect(data,threshold=0.98):
    data_copy = data.copy(deep=True)
    quasi_constant_feature = []
    for feature in data_copy.columns:
        predominant = (data_copy[feature].value_counts() / np.float(
                      len(data_copy))).sort_values(ascending=False).values[0]
        if predominant >= threshold:
            quasi_constant_feature.append(feature)
    print(len(quasi_constant_feature),' variables are found to be almost constant')    
    return quasi_constant_feature
def constant_feature_detect ( data , threshold = 0.98 ) : data_copy = data . copy ( deep = True ) quasi_constant_feature = [ ] for feature in data_copy . columns : predominant = ( data_copy [ feature ] . value_counts ( ) / np . float ( len ( data_copy ) ) ) . sort_values ( ascending = False ) . values [ 0 ] if predominant >= threshold : quasi_constant_feature . append ( feature ) print ( len ( quasi_constant_feature ) , ' variables are found to be almost constant' ) return quasi_constant_feature
detect features that show the same value for the
majority/all of the observations (constant/quasi-constant features)
detect features that show the same value for the majority / all of the observations ( constant / quasi - constant features )
""" detect features that show the same value for the 
    majority/all of the observations (constant/quasi-constant features)
    
    Parameters
    ----------
    data : pd.Dataframe
    threshold : threshold to identify the variable as constant
        
    Returns
    -------
    list of variables names
    """
data
threshold