Created
July 15, 2020 14:08
-
-
Save Ayushijain09/09ddb8c31f22415915ec09819a914c16 to your computer and use it in GitHub Desktop.
Sequential Forward Selection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from mlxtend.feature_selection import SequentialFeatureSelector | |
sfs = SequentialFeatureSelector(LinearRegression(), # cv = k-fold cross validation, floating is another extension of SFS, not used here | |
k_features=10, | |
forward=True, | |
floating=False, | |
scoring='accuracy', | |
cv=2) | |
sfs = sfs.fit(X_train, y_train) | |
selected_features = x_train.columns[list(sfs.k_feature_idx_)] | |
print(selected_features) | |
# print the selected features. | |
selected_features = x_train.columns[list(sfs.k_feature_idx_)] | |
print(selected_features) | |
# final prediction score. | |
print(sfs.k_score_) | |
# transform to the newly selected features. | |
x_train_new = sfs.transform(X_train) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment