Created
February 24, 2015 23:03
-
-
Save zachguo/d3b7a28a90a14ce77978 to your computer and use it in GitHub Desktop.
LR feature selection and show support for selected features
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
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