Skip to content

fit_params in conjunction with FeatureUnion #7136

@BenjaminBossan

Description

@BenjaminBossan

Description

Using fit_params in conjunction with FeatureUnion may not work as expected. It would be helpful if fit_params names would be resolved to fit the estimators in transformer_list.

Steps/Code to Reproduce

from sklearn.pipeline import Pipeline, FeatureUnion
from sklearn.preprocessing import FunctionTransformer
from sklearn.datasets import make_classification

X, y = make_classification()

class MyTransformer(FunctionTransformer):
    def fit(self, X, y=None, **fit_params):
        print("Fit params are: ", fit_params)
        return super().fit(X, y)

pipe = Pipeline([
    ('step0', FunctionTransformer()),
    ('step1', FeatureUnion([
        ('feature0', MyTransformer()),
        ('feature1', MyTransformer()),
    ])),
    ('step2', FunctionTransformer()),
])

pipe.fit(X, y, step1__feature1__someparam=123)

Expected Results

# prints
Fit params are:  {'someparam': 123}

Actual Results

# prints
Fit params are:  {'feature1__someparam': 123}  # by feature0
Fit params are:  {'feature1__someparam': 123}  # by feature1

Comment

Maybe the actual outcome is what it is supposed to be, but my expectation would be that FeatureUnion resolves the estimator name and only passes the fit_params to the corresponding estimator. At least it would be very useful if it did.

Versions

Python 3.4.5
NumPy 1.10.4
SciPy 0.17.0
Scikit-Learn 0.17.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions