Invalid warning about feature names missing in KNeighborsRegressor
See original GitHub issueDescribe the bug
When I call fit()
then predict()
on a KNeighborsRegressor
, passing a DataFrame with the same column names both times, I get a warning:
[...]/python3.8/site-packages/sklearn/base.py:441: UserWarning: X does not have valid feature names, but KNeighborsRegressor was fitted with feature names
warnings.warn(
Steps/Code to Reproduce
import numpy as np
import pandas as pd
from sklearn.neighbors import KNeighborsRegressor
df = pd.DataFrame({"A": np.random.rand(10)})
k = KNeighborsRegressor().fit(df, np.random.rand(10))
y_pred = k.predict(df)
Expected Results
No warning: I’ve provided a DataFrame with the same columns both times.
Actual Results
A warning.
Versions
System:
python: 3.8.12 | packaged by conda-forge | (default, Oct 12 2021, 21:50:38) [Clang 11.1.0 ]
executable: /Users/ageron/miniconda3/envs/homl3/bin/python
machine: macOS-10.15.7-x86_64-i386-64bit
Python dependencies:
pip: 21.3
setuptools: 58.2.0
sklearn: 1.0
numpy: 1.19.5
scipy: 1.7.1
Cython: None
pandas: 1.3.3
matplotlib: 3.4.3
joblib: 0.14.1
threadpoolctl: 3.0.0
Built with OpenMP: True
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
SKLearn warning "valid feature names" in version 1.0
When I trimmed to remove the headers and sent only values then the error got disappeared. Sample code before and after changes. Code...
Read more >sklearn.neighbors.KNeighborsRegressor
Names of features seen during fit. Defined only when X has feature names that are all strings. New in version 1.0. n_samples_fit_int.
Read more >Guide to the K-Nearest Neighbors Algorithm in Python and ...
In this detailed definitive guide - learn how K-Nearest Neighbors works, and how to implement it for regression, classification and anomaly ...
Read more >09_tabular code: UserWarning: X does not have valid feature ...
Here is the error that comes up /opt/conda/lib/python3.7/site-packages/sklearn/base.py:446: UserWarning: X does not have valid feature names ...
Read more >scikit-learn 1.1 Released - Exxact Corporation
sklearn.impute. Enhancement impute.SimpleImputer now warns with feature names when features which are skipped due to the lack of any observed ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I confirm that I don’t get a warning anymore.
Please open a new issue to know the scikit-learn version used. It should be solved in 1.0.2