FeatureUnion
¶
-
class
ibex.sklearn.pipeline.
FeatureUnion
(transformer_list, n_jobs=1, transformer_weights=None, as_index=True)[source]¶ Bases:
sklearn.pipeline.FeatureUnion
,sklearn.base.TransformerMixin
,ibex._base.FrameMixin
Concatenates results of multiple transformer objects. This estimator applies a list of transformer objects in parallel to the input data, then concatenates the results. This is useful to combine several feature extraction mechanisms into a single transformer.
Parameters: - transformer_list – list of (string, transformer) tuples. List of transformer objects to be applied to the data. The first half of each tuple is the name of the transformer.
- n_jobs – int, optional. Number of jobs to run in parallel (default 1).
- transformer_weights – dict, optional Multiplicative weights for features per transformer. Keys are transformer names, values the weights.
Example
>>> import pandas as pd >>> X = pd.DataFrame({'a': [1, 2, 3], 'b': [10, -3, 4]})
>>> from ibex.sklearn import preprocessing as pd_preprocessing >>> from ibex.sklearn import pipeline as pd_pipeline
>>> trn = pd_pipeline.FeatureUnion([ ... ('std', pd_preprocessing.StandardScaler()), ... ('abs', pd_preprocessing.MaxAbsScaler())]) >>> trn.fit_transform(X) std abs a b a b 0 -1.224745 1.192166 0.333333 1.0 1 0.000000 -1.254912 0.666667 -0.3 2 1.224745 0.062746 1.000000 0.4
>>> from ibex import trans >>> >>> trn = pd_preprocessing.StandardScaler() + pd_preprocessing.MaxAbsScaler() >>> trn.fit_transform(X) standardscaler maxabsscaler a b a b 0 -1.224745 1.192166 0.333333 1.0 1 0.000000 -1.254912 0.666667 -0.3 2 1.224745 0.062746 1.000000 0.4
>>> trn = trans(pd_preprocessing.StandardScaler(), out_cols=['std_scale_a', 'std_scale_b']) >>> trn += trans(pd_preprocessing.MaxAbsScaler(), out_cols=['max_scale_a', 'max_scale_b']) >>> trn.fit_transform(X) functiontransformer_0 functiontransformer_1 std_scale_a std_scale_b max_scale_a max_scale_b 0 -1.224745 1.192166 0.333333 1.0 1 0.000000 -1.254912 0.666667 -0.3 2 1.224745 0.062746 1.000000 0.4
-
fit_transform
(X, y=None, **fit_params)[source]¶ Fits the transformer using
X
(and possiblyy
). TransformsX
using the transformers, usespandas.concat()
to horizontally concatenate the results.Returns: self
-
transform
(X, *args, **kwargs)[source]¶ Transforms
X
using the transformers, usespandas.concat()
to horizontally concatenate the results.