Skip to content

Spurious warning with DecisionBoundaryPlot #23311

@glemaitre

Description

@glemaitre

The following snippet will raise a warning regarding feature names

# %%
from sklearn.datasets import load_iris

iris = load_iris(as_frame=True)
X = iris.data[["sepal width (cm)", "petal width (cm)"]]
y = iris.target

# %%
from sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_test = train_test_split(
    X, y, random_state=42
)

# %%
from sklearn.linear_model import LogisticRegression

model = LogisticRegression().fit(X_train, y_train)

# %%
from sklearn.inspection import DecisionBoundaryDisplay

display = DecisionBoundaryDisplay.from_estimator(model, X_train, alpha=0.5)
scatter = display.ax_.scatter(
    X_train["sepal width (cm)"], X_train["petal width (cm)"], c=y_train, edgecolor="k"
)
display.ax_.legend(scatter.legend_elements()[0], iris.target_names)
/Users/glemaitre/Documents/packages/scikit-learn/sklearn/base.py:450: UserWarning: X does not have valid feature names, but LogisticRegression was fitted with feature names
  warnings.warn(

It is not a regression but the warning should not be raised. I think that we should correct this for 1.1 release.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions