Skip to content

Commit

Permalink
Feature selection using RFE #1831
Browse files Browse the repository at this point in the history
  • Loading branch information
nonunicorn committed Dec 16, 2022
1 parent 579c35b commit 5c4a54e
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions python-scikit-learn/feature-selection-using-rfe.md
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]
```

0 comments on commit 5c4a54e

Please sign in to comment.