False UserWarning for features names
See original GitHub issueDescribe 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
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
@AnaHauachen, I suggest using version 0.24.2 for programs with regression functions until they release version 1.0.1.
This was fixed in #21199. The fix will be release in the upcoming 1.0.1 version.