question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

False UserWarning for features names

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Amine-Sacommented, Oct 2, 2021

@AnaHauachen, I suggest using version 0.24.2 for programs with regression functions until they release version 1.0.1.

0reactions
ogriselcommented, Oct 14, 2021

This was fixed in #21199. The fix will be release in the upcoming 1.0.1 version.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SKLearn warning "valid feature names" in version 1.0
Show activity on this post. It is showing error because our dataframe has feature names but we should fit the data as 2d...
Read more >
UserWarning is thrown when calling ... - GitHub
Describe the bug UserWarning: X does not have valid feature names is thrown when calling HistGradientBoostingRegressor.fit using pandas.
Read more >
How to Fix FutureWarning Messages in scikit-learn
Warning messages can be confusing to beginners as it looks like there is a problem with the code or that they have done...
Read more >
Identifying filtered features after feature selection with scikit learn
There are two things that you can do: Check coef_ param and detect which column was ignored; Use the same model for input...
Read more >
sklearn.base — pyts 0.12.0 documentation - Read the Docs
__name__, pickle_version, __version__ ), UserWarning, ) try: super(). ... If False, the input will be checked for consistency with feature names of data ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found