feature-engineering-and-data-transformations/using-toy-exmaples/feature_selection/filter_method.py
def univariate_mse(X_train,y_train,X_test,y_test,threshold):
   
    """
    First, it builds one decision tree per feature, to predict the target
    Second, it makes predictions using the decision tree and the mentioned feature
    Third, it ranks the features according to the machine learning metric (roc-auc or mse)
    It selects the highest ranked features

    """
    mse_values = []
    for feature in X_train.columns:
        clf = DecisionTreeRegressor()
        clf.fit(X_train[feature].to_frame(), y_train)
        y_scored = clf.predict(X_test[feature].to_frame())
        mse_values.append(mean_squared_error(y_test, y_scored))
    mse_values = pd.Series(mse_values)
    mse_values.index = X_train.columns
    print(mse_values.sort_values(ascending=False))
    print(len(mse_values[mse_values > threshold]),'out of the %s featues are kept'% len(X_train.columns))
    keep_col = mse_values[mse_values > threshold]
    return keep_col

    First, it builds one decision tree per feature, to predict the target
    Second, it makes predictions using the decision tree and the mentioned feature
    Third, it ranks the features according to the machine learning metric (roc-auc or mse)
    It selects the highest ranked features

    
First, it builds one decision tree per feature, to predict the target
Second, it makes predictions using the decision tree and the mentioned feature
Third, it ranks the features according to the machine learning metric (roc-auc or mse)
It selects the highest ranked features
First it builds one decision tree per feature to predict the target Second it makes predictions using the decision tree and the mentioned feature Third it ranks the features according to the machine learning metric ( roc - auc or mse ) It selects the highest ranked features
def univariate_mse(X_train,y_train,X_test,y_test,threshold):
    mse_values = []
    for feature in X_train.columns:
        clf = DecisionTreeRegressor()
        clf.fit(X_train[feature].to_frame(), y_train)
        y_scored = clf.predict(X_test[feature].to_frame())
        mse_values.append(mean_squared_error(y_test, y_scored))
    mse_values = pd.Series(mse_values)
    mse_values.index = X_train.columns
    print(mse_values.sort_values(ascending=False))
    print(len(mse_values[mse_values > threshold]),'out of the %s featues are kept'% len(X_train.columns))
    keep_col = mse_values[mse_values > threshold]
    return keep_col
def univariate_mse ( X_train , y_train , X_test , y_test , threshold ) : mse_values = [ ] for feature in X_train . columns : clf = DecisionTreeRegressor ( ) clf . fit ( X_train [ feature ] . to_frame ( ) , y_train ) y_scored = clf . predict ( X_test [ feature ] . to_frame ( ) ) mse_values . append ( mean_squared_error ( y_test , y_scored ) ) mse_values = pd . Series ( mse_values ) mse_values . index = X_train . columns print ( mse_values . sort_values ( ascending = False ) ) print ( len ( mse_values [ mse_values > threshold ] ) , 'out of the %s featues are kept' % len ( X_train . columns ) ) keep_col = mse_values [ mse_values > threshold ] return keep_col
First, it builds one decision tree per feature, to predict the target
Second, it makes predictions using the decision tree and the mentioned feature
Third, it ranks the features according to the machine learning metric (roc-auc or mse)
It selects the highest ranked features
First it builds one decision tree per feature to predict the target Second it makes predictions using the decision tree and the mentioned feature Third it ranks the features according to the machine learning metric ( roc - auc or mse ) It selects the highest ranked features
"""
    First, it builds one decision tree per feature, to predict the target
    Second, it makes predictions using the decision tree and the mentioned feature
    Third, it ranks the features according to the machine learning metric (roc-auc or mse)
    It selects the highest ranked features

    """
X_train
y_train
X_test
y_test
threshold