0

I am using Kneighbors classifier to train some data using Jupyter notebook. It worked fine, but showed this future warning:

C:\Users\PERSONAL\anaconda3\lib\site-packages\sklearn\neighbors\_classification.py:228: FutureWarning: Unlike other reduction functions (e.g. `skew`, `kurtosis`), the default behavior of `mode` typically preserves the axis it acts along. In SciPy 1.11.0, this behavior will change: the default value of `keepdims` will become False, the `axis` over which the statistic is taken will be eliminated, and the value None will no longer be accepted. Set `keepdims` to True or False to avoid this warning.
  mode, _ = stats.mode(_y[neigh_ind, k], axis=1)

Why is this appearing, and how can i solve this(without ignoring the the warning using simplefilter). It didnt look like it affected the rest of the code, but i want this error to not appear. Here is my code:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
Dataset=pd.read_csv('KNN Data.csv')
X=Dataset.iloc[:,:-1].values
Y=Dataset.iloc[:,-1].values
from sklearn.model_selection import train_test_split
xtrain,xtest,ytrain,ytest=train_test_split(X,Y,test_size=0.2)
from sklearn.neighbors import KNeighborsClassifier
KNN=KNeighborsClassifier()
KNN.fit(xtrain,ytrain)
ypred=KNN.predict(xtest)
from sklearn.metrics import confusion_matrix
from sklearn.metrics import accuracy_score
CM=confusion_matrix(ytest,ypred)
print(CM)
print(accuracy_score(ytest,ypred))

i want the error to be solved

  • As future warning is to inform you that the function you are using in said module is due to be changed or depreciated and may direct you to use a different function. You can disable the warning by adding two lines like; `import warnings` `warnings.simplefilter(action='ignore', category=FutureWarning)` – moken Aug 26 '23 at 06:48

0 Answers0