Skip to content

Instantly share code, notes, and snippets.

@MLWhiz
Created July 27, 2019 16:58
Show Gist options
  • Save MLWhiz/c30af8e3867509613c55d159e99357d2 to your computer and use it in GitHub Desktop.
Save MLWhiz/c30af8e3867509613c55d159e99357d2 to your computer and use it in GitHub Desktop.
from sklearn.feature_selection import SelectFromModel
from sklearn.linear_model import LogisticRegression
embeded_lr_selector = SelectFromModel(LogisticRegression(penalty="l1"), max_features=num_feats)
embeded_lr_selector.fit(X_norm, y)
embeded_lr_support = embeded_lr_selector.get_support()
embeded_lr_feature = X.loc[:,embeded_lr_support].columns.tolist()
print(str(len(embeded_lr_feature)), 'selected features')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment