Using exhaustive feature selection
If your results from forward and backward selection are unpersuasive, and you do not mind running a model while you go out for coffee or lunch, you can try exhaustive feature selection. Exhaustive feature selection trains a given model on all possible combinations of features and selects the best subset of features. But it does this at a price. As the name suggests, this procedure might exhaust both system resources and your patience.
Let's use exhaustive feature selection for our model of bachelor's degree completion:
- We start by loading the required libraries, including the
RandomForestClassifier
andLogisticRegression
modules fromscikit-learn
andExhaustiveFeatureSelector
frommlxtend
. We also import theaccuracy_score
module so that we can evaluate a model with the selected features:import pandas as pd from feature_engine.encoding import OneHotEncoder from sklearn.model_selection import train_test_split from sklearn.preprocessing...