Skip to content

Instantly share code, notes, and snippets.

@zachguo
Created February 24, 2015 23:03
Show Gist options
  • Save zachguo/d3b7a28a90a14ce77978 to your computer and use it in GitHub Desktop.
Save zachguo/d3b7a28a90a14ce77978 to your computer and use it in GitHub Desktop.
LR feature selection and show support for selected features
def feature_selection(X_train, y_train, X_test):
feature_selector = LogisticRegression(C=0.1, penalty="l1", dual=False)
X_train = feature_selector.fit_transform(X_train, y_train)
X_test = feature_selector.transform(X_test)
return X_train, X_test, feature_selector
def get_support(feature_selector):
return list(set(np.where(feature_selector.coef_ != 0)[-1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment