-
-
Notifications
You must be signed in to change notification settings - Fork 26.1k
Open
Labels
Description
Describe the bug
When using pandas dataframes and a TransformedTargetRegressor
with PowerTransformer
with set_output(transform="pandas")
, I get this warning:
UserWarning: X has feature names, but PowerTransformer was fitted without feature names
The warning does not arise when using other estimators (e.g. StandardScaler
) but only with PowerTransformer
.
The problem seems to originate from the inverse_transform
implementation of PowerTransformer
.
Steps/Code to Reproduce
from sklearn.datasets import load_iris
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
from sklearn.compose import TransformedTargetRegressor
from sklearn.preprocessing import PowerTransformer, StandardScaler
X, y = load_iris(return_X_y=True, as_frame=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=42)
# This works fine:
pipeline = TransformedTargetRegressor(
regressor=LinearRegression(),
transformer=StandardScaler().set_output(transform="pandas")
)
pipeline.fit(X_train, y_train)
y_test_pred = pipeline.predict(X_test)
# But this gets a warning:
pipeline = TransformedTargetRegressor(
regressor=LinearRegression(),
transformer=PowerTransformer().set_output(transform="pandas")
)
pipeline.fit(X_train, y_train)
y_test_pred = pipeline.predict(X_test)
Expected Results
No warning
Actual Results
UserWarning: X has feature names, but PowerTransformer was fitted without feature names
Versions
System:
python: 3.11.9
Python dependencies:
sklearn: 1.7.1
pip: 25.2
setuptools: 65.5.0
numpy: 2.0.2
scipy: 1.15.1
Cython: None
pandas: 2.2.3
matplotlib: 3.10.0
joblib: 1.4.2
threadpoolctl: 3.5.0