@@ -312,15 +312,37 @@ def get_feature_names(self):
312
312
return self .feature_names_
313
313
314
314
def restrict (self , support , indices = False ):
315
- """Restrict the features to those in support.
315
+ """Restrict the features to those in support using feature selection.
316
+
317
+ This function modifies the estimator in-place.
316
318
317
319
Parameters
318
320
----------
319
321
support : array-like
320
322
Boolean mask or list of indices (as returned by the get_support
321
323
member of feature selectors).
322
324
indices : boolean, optional
323
- Whether support is a list of indices.
325
+ Whether support is a list of indices.
326
+
327
+ Returns
328
+ -------
329
+ self
330
+
331
+ Examples
332
+ --------
333
+ >>> from sklearn.feature_extraction import DictVectorizer
334
+ >>> from sklearn.feature_selection import SelectKBest, chi2
335
+ >>> v = DictVectorizer()
336
+ >>> D = [{'foo': 1, 'bar': 2}, {'foo': 3, 'baz': 1}]
337
+ >>> X = v.fit_transform(D)
338
+ >>> support = SelectKBest(chi2, k=2).fit(X, [0, 1])
339
+ >>> v.get_feature_names()
340
+ ['bar', 'baz', 'foo']
341
+ >>> v.restrict(support.get_support()) # doctest: +ELLIPSIS
342
+ DictVectorizer(dtype=..., separator='=', sort=True,
343
+ sparse=True)
344
+ >>> v.get_feature_names()
345
+ ['bar', 'foo']
324
346
"""
325
347
if not indices :
326
348
support = np .where (support )[0 ]
0 commit comments