Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0a3b75a

Browse files
committed
Merge pull request #23 from jnothman/pr3886
Some finishing touches to the FeatureUnion changes
2 parents 5f6f7af + d81ecc6 commit 0a3b75a

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

doc/modules/pipeline.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,11 @@ FeatureUnion: composite feature spaces
122122
:class:`FeatureUnion` combines several transformer objects into a new
123123
transformer that combines their output. A :class:`FeatureUnion` takes
124124
a list of transformer objects. During fitting, each of these
125-
is fit to the data independently. For transforming data, the
126-
transformers are applied in parallel, and the sample vectors they output
127-
are concatenated end-to-end into larger vectors.
125+
is fit to the data independently. It can also be used to apply different
126+
transformations to each field of the data, producing a homogeneous feature
127+
matrix from a heterogeneous data source.
128+
The transformers are applied in parallel, and the feature matrices they output
129+
are concatenated side-by-side into a larger matrix.
128130

129131
:class:`FeatureUnion` serves the same purposes as :class:`Pipeline` -
130132
convenience and joint parameter estimation and validation.
@@ -166,4 +168,4 @@ Like pipelines, feature unions have a shorthand constructor called
166168
.. topic:: Examples:
167169

168170
* :ref:`example_feature_stacker.py`
169-
* :ref:`example_hetero_feature_union.py`
171+
* :ref:`example_hetero_feature_union.py` illustrates the ``fields`` parameter.

sklearn/pipeline.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,9 @@ class FeatureUnion(BaseEstimator, TransformerMixin):
292292
"""Concatenates results of multiple transformer objects.
293293
294294
This estimator applies a list of transformer objects in parallel to the
295-
input data, then concatenates the results. This is useful to combine
296-
several feature extraction mechanisms into a single transformer.
295+
input data, or each to a different field of the input, then concatenates
296+
the results. This is useful to combine several feature extraction
297+
mechanisms into a single transformer.
297298
298299
Parameters
299300
----------
@@ -415,7 +416,8 @@ def transform(self, X):
415416
Xs = Parallel(n_jobs=self.n_jobs)(
416417
delayed(_transform_one)(trans, name, X, self.transformer_weights,
417418
field)
418-
for (name, trans), field in zip(self.transformer_list, self.fields_))
419+
for (name, trans), field in zip(self.transformer_list,
420+
self.fields_))
419421
if any(sparse.issparse(f) for f in Xs):
420422
Xs = sparse.hstack(Xs).tocsr()
421423
else:
@@ -443,8 +445,8 @@ def _check_fields(self):
443445
fields = self.fields
444446
if len(fields) != len(self.transformer_list):
445447
raise ValueError("Length of transformer list %d does not match"
446-
" length of fields %d" % (len(self.transformer_list),
447-
len(fields)))
448+
" length of fields %d" %
449+
(len(self.transformer_list), len(fields)))
448450
else:
449451
fields = [None for x in self.transformer_list]
450452
return fields

0 commit comments

Comments
 (0)