Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.predict in pipeline #733

Open
PolarsDude opened this issue Feb 18, 2025 · 1 comment
Open

.predict in pipeline #733

PolarsDude opened this issue Feb 18, 2025 · 1 comment

Comments

@PolarsDude
Copy link

PolarsDude commented Feb 18, 2025

Hi

Consider the following pipeline (from examples)

import numpy as np
import pandas as pd

from sklearn.pipeline import FeatureUnion, Pipeline
from sklearn.linear_model import LinearRegression, Ridge

from sklego.meta import EstimatorTransformer
from sklego.preprocessing import ColumnSelector

np.random.seed(42)
n = 1000
X = np.random.uniform(0, 1, (n, 2))
y = X.sum(axis=1) + np.random.uniform(0, 1, (n,))
df = pd.DataFrame({"x1": X[:, 0], "x2": X[:, 1], "y": y})

pipeline = Pipeline([
    ("grab_columns", ColumnSelector(["x1", "x2"])),
    ("ml_features", FeatureUnion([
        ("model_1",  EstimatorTransformer(LinearRegression())),
        ("model_2",  EstimatorTransformer(Ridge()))
    ]))
])

pipeline.fit(df, y)

I want to predict with this pipeline with new data, for instance pipeline.predict(X_test), but I get the follow error message: AttributeError: 'EstimatorTransformer' object has no attribute 'predict'. Is there any way to use predict in pipeline? This would help alot.

@FBruzzesi
Copy link
Collaborator

Hey @PolarsDude thanks for the question.
EstimatorTransformer turns any estimator to a transformer component, therefore you can call pipeline.transform after fitting.
If you want to use .predict, then this might not be the component you are looking for or you need to follow it with an estimator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants