Feature unions
We may want to build a model on features from a variety of sources, such as PCA, as we saw in the preceding section, in addition to selecting a subset of the features. For these purposes, scikit-learn provides the FeatureUnion class in the pipeline module. This also allows us to perform multiple feature engineering techniques at once, such as feature extraction followed by feature transformation, when we combine this with a pipeline.
Creating a FeatureUnion is just like creating a pipeline, but rather than passing the steps in order, we pass the transformations we want to make. These will be stacked side by side in the result. Let's use a FeatureUnion of interaction terms and select the features with a variance above 0.01
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access