-
-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
579c35b
commit 5c4a54e
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,37 @@ | ||
# Feature selection using RFE | ||
|
||
```python | ||
from sklearn import datasets, svm, feature_selection | ||
|
||
X, y = datasets.make_friedman1(n_samples=50, n_features=10) | ||
|
||
selector = feature_selection.RFECV(svm.SVR(kernel="linear"), step=1, cv=5) | ||
selector = selector.fit(X, y) | ||
|
||
ranks = selector.ranking_ | ||
``` | ||
|
||
- `from sklearn import` - import module from [lib:scikit-learn](https://onelinerhub.com/python-scikit-learn/how-to-install-scikit-learn-using-pip) | ||
- `.make_friedman1(` - creates Friedman #1 regression dataset | ||
- `.RFECV(` - creates RFE feature selection model | ||
- `svm.SVR(` - we use SVR model as estimator for RFE | ||
- `.fit(` - train model | ||
- `selector.ranking_` - returns features rankings | ||
|
||
group: feature-selection | ||
|
||
## Example: | ||
```python | ||
from sklearn import datasets, svm, feature_selection | ||
|
||
X, y = datasets.make_friedman1(n_samples=50, n_features=10) | ||
|
||
selector = feature_selection.RFECV(svm.SVR(kernel="linear"), step=1, cv=5) | ||
selector = selector.fit(X, y) | ||
print(selector.ranking_) | ||
``` | ||
``` | ||
[1 1 3 1 1 1 1 2 1 1] | ||
``` | ||
|