Last active
August 6, 2016 10:16
-
-
Save zaffnet/04bfbbba23d2f9e3589f7aad022cf733 to your computer and use it in GitHub Desktop.
scikit learn Recursive Feature Elimination
This file contains hidden or 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
| # Feature Importance | |
| from sklearn import datasets | |
| from sklearn import metrics | |
| from sklearn.ensemble import ExtraTreesClassifier | |
| # load the iris datasets | |
| dataset = datasets.load_iris() | |
| # fit an Extra Trees model to the data | |
| model = ExtraTreesClassifier() | |
| model.fit(dataset.data, dataset.target) | |
| # display the relative importance of each attribute | |
| print(model.feature_importances_) |
This file contains hidden or 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
| # Recursive Feature Elimination | |
| from sklearn import datasets | |
| from sklearn.feature_selection import RFE | |
| from sklearn.linear_model import LogisticRegression | |
| # load the iris datasets | |
| dataset = datasets.load_iris() | |
| # create a base classifier used to evaluate a subset of attributes | |
| model = LogisticRegression() | |
| # create the RFE model and select 3 attributes | |
| rfe = RFE(model, 3) | |
| rfe = rfe.fit(dataset.data, dataset.target) | |
| # summarize the selection of the attributes | |
| print(rfe.support_) | |
| print(rfe.ranking_) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment