Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Scikit-Learn · Class

FeatureUnion

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.

How it works

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 __.

Syntax

class sklearn.pipeline.FeatureUnion(*transformer_list*, *, n_jobs=None, transformer_weights=None, verbose=False, verbose_feature_names_out=True)

Parameters

NameTypeDescription
transformer_listlistList of (name, transformer) pairs that define the parallel branches.
n_jobsint or NoneNumber of jobs used to fit and transform branches in parallel; None uses the default job behavior.
transformer_weightsdict or NoneOptional mapping from transformer names to multiplicative output weights.
verboseboolWhether to display progress messages during fitting.
verbose_feature_names_outboolWhether generated output feature names include transformer prefixes.

Returns

A fitted FeatureUnion transformer whose branch outputs are concatenated during transformation.

Key points

  • It produces one feature representation by joining the outputs of several transformers.
  • All listed transformers receive the input independently rather than forming a sequential chain.
  • Use it when different feature-extraction strategies should contribute to the same model input.
  • Nested configuration follows the <component>__<parameter> convention.
  • Define components as (name, transformer) pairs; the name identifies the branch.
  • A passthrough branch contributes its input directly instead of applying an estimator.

Common mistakes

  • A named transformer can be replaced through its parameter; use the exact component name when configuring it.
  • The special values drop and passthrough change whether a component contributes transformed features.

Example: Combine parallel feature transformations

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.

When to use it

Combine feature extractors

A dataset benefits from complementary dimensionality-reduction or feature-selection methods.

Joint model selection

A model needs one tunable composite representation rather than separately managed feature blocks.

Parallel preprocessing

Independent transformer branches are expensive and can run concurrently.

Interview questions

QHow does FeatureUnion combine transformers?

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.

QWhat is the structure of transformer_list?

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.

QWhich options control execution and contribution of components?

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.Pipeline
  • sklearn.pipeline.make_union
  • sklearn.compose.ColumnTransformer

Source: FeatureUnion — scikit-learn 1.9.1 documentation. Checked 2026-10-15.