Combine feature extractors
A dataset benefits from complementary dimensionality-reduction or feature-selection methods.
Scikit-Learn · Class
FeatureUnion runs multiple named transformers in parallel and concatenates their outputs into one feature space. It is useful for combining different feature-extraction approaches in a single estimator.
FeatureUnion fits multiple named transformers independently and applies them in parallel. Their outputs are concatenated into one feature matrix, optionally with component weights and parallel execution; nested parameters use each transformer’s name followed by __.
class sklearn.pipeline.FeatureUnion(*transformer_list*, *, n_jobs=None, transformer_weights=None, verbose=False, verbose_feature_names_out=True)| Name | Type | Description |
|---|---|---|
transformer_list | list | List of (name, transformer) pairs that define the parallel branches. |
n_jobs | int or None | Number of jobs used to fit and transform branches in parallel; None uses the default job behavior. |
transformer_weights | dict or None | Optional mapping from transformer names to multiplicative output weights. |
verbose | bool | Whether to display progress messages during fitting. |
verbose_feature_names_out | bool | Whether generated output feature names include transformer prefixes. |
A fitted FeatureUnion transformer whose branch outputs are concatenated during transformation.
<component>__<parameter> convention.(name, transformer) pairs; the name identifies the branch.passthrough branch contributes its input directly instead of applying an estimator.drop and passthrough change whether a component contributes transformed features.from sklearn.decomposition import PCA, TruncatedSVD
from sklearn.pipeline import FeatureUnion
X = [[0., 1., 3.], [2., 2., 5.]]
union = FeatureUnion([
("pca", PCA(n_components=1)),
("svd", TruncatedSVD(n_components=2)),
])
print(union.fit_transform(X).shape)This creates two feature transformations, fits them independently, and returns their concatenated output.
A dataset benefits from complementary dimensionality-reduction or feature-selection methods.
A model needs one tunable composite representation rather than separately managed feature blocks.
Independent transformer branches are expensive and can run concurrently.
FeatureUnion applies each transformer to the same input independently and concatenates the resulting feature matrices side by side. This creates one composite feature space from parallel transformations.
Follow-up: How would you tune one component? Use nested parameter names such as pca__n_components with set_params or a search estimator.
Each tuple contains a unique component name and a transformer. The names identify components and provide the prefixes used for parameter access and feature-name handling.
Follow-up: What happens if a component is not needed? Set its named parameter to drop, or use passthrough to retain its input features without transformation.
n_jobs controls parallel fitting and transformation across transformers, while transformer_weights scales the output of individual components. verbose controls progress messages during fitting.
Follow-up: When would weighting help? It can adjust the relative influence of feature blocks before a downstream estimator learns from the combined representation.
sklearn.pipeline.Pipelinesklearn.pipeline.make_unionsklearn.compose.ColumnTransformer