8000 False UserWarning for features names · Issue #21188 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content
False UserWarning for features names #21188
Closed
@Amine-Sa

Description

@Amine-Sa

Describe the bug

Since the last stable update (1.0), I get the following warning:
C:\Users...\venv\lib\site-packages\sklearn\base.py:441: UserWarning: X does not have valid feature names, but KNeighborsClassifier was fitted with feature names
warnings.warn(

Changing features names to every possible way didn't change anything, and I didn't find anything related to valid feature names in the documentation.

Steps/Code to Reproduce

import pandas as pd
import numpy as np
from sklearn.neighbors import KNeighborsClassifier

X_train = pd.DataFrame(np.random.randint(0,100,size=(100, 4)), columns=list('ABCD'))
y_train = np.random.default_rng().integers(2, size=100)
X_test = pd.DataFrame(np.random.randint(0,25,size=(25, 4)), columns=list('ABCD'))

k = 5
knn = KNeighborsClassifier(n_neighbors=k)
knn.fit(X_train, y_train)
y_pred = knn.predict(X_test)
print(y_pred)

Expected Results

A list of 25 elements, possible values are {0,1}.
Example : [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]

Actual Results

C:\Users...\venv\lib\site-packages\sklearn\base.py:441: UserWarning: X does not have valid feature names, but KNeighborsClassifier was fitted with feature names
warnings.warn(
[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]

Versions

System:
python: 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:57:54) [MSC v.1924 64 bit (AMD64)]
executable: c:\Users...\venv\Scripts\python.exe
machine: Windows-10-10.0.19041-SP0

Python dependencies:
pip: 20.1.1
setuptools: 47.1.0
sklearn: 1.0
numpy: 1.21.2
scipy: 1.7.1
Cython: None
pandas: 1.3.3
matplotlib: None
joblib: 1.0.1
threadpoolctl: 2.2.0

Built with OpenMP: True

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0