8000 DOC Add SelectFromModel example (#15194) · crankycoder/scikit-learn@1e77619 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1e77619

Browse files
DatenBergwerkerrth
authored andcommitted
DOC Add SelectFromModel example (scikit-learn#15194)
1 parent 818500b commit 1e77619

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

sklearn/feature_selection/from_model.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,28 @@ class SelectFromModel(MetaEstimatorMixin, SelectorMixin, BaseEstimator):
130130
131131
threshold_ : float
132132
The threshold value used for feature selection.
133+
134+
Examples
135+
--------
136+
>>> from sklearn.feature_selection import SelectFromModel
137+
>>> from sklearn.linear_model import LogisticRegression
138+
>>> X = [[ 0.87, -1.34, 0.31 ],
139+
... [-2.79, -0.02, -0.85 ],
140+
... [-1.34, -0.48, -2.55 ],
141+
... [ 1.92, 1.48, 0.65 ]]
142+
>>> y = [0, 1, 0, 1]
143+
>>> selector = SelectFromModel(estimator=LogisticRegression()).fit(X, y)
144+
>>> selector.estimator_.coef_
145+
array([[-0.3252302 , 0.83462377, 0.49750423]])
146+
>>> selector.threshold_
147+
0.55245...
148+
>>> selector.get_support()
149+
array([False, True, False])
150+
>>> selector.transform(X)
151+
array([[-1.34],
152+
[-0.02],
153+
[-0.48],
154+
[ 1.48]])
133155
"""
134156
def __init__(self, estimator, threshold=None, prefit=False,
135157
norm_order=1, max_features=None):

0 commit comments

Comments
 (0)
0