8000 Merge pull request #4356 from vortex-ape/dict_vectorizer · scikit-learn/scikit-learn@6e54079 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6e54079

Browse files
committed
Merge pull request #4356 from vortex-ape/dict_vectorizer
Fixes #4355: DictVectorizer.restrict docstring unclear
2 parents b18e7dd + ef9cbcb commit 6e54079

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

sklearn/feature_extraction/dict_vectorizer.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,15 +312,37 @@ def get_feature_names(self):
312312
return self.feature_names_
313313

314314
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.
316318
317319
Parameters
318320
----------
319321
support : array-like
320322
Boolean mask or list of indices (as returned by the get_support
321323
member of feature selectors).
322324
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']
324346
"""
325347
if not indices:
326348
support = np.where(support)[0]

0 commit comments

Comments
 (0)
0