简体   繁体   中英

ValueError: Input contains NaN, infinity or a value too large for dtype('float64'). for my knn model

df1_fit=pd.DataFrame(scaled_features,columns=df1.columns[:-1])
df1_fit.head()

from sklearn.model_selection import train_test_split

X_train, X_test, y_train, 
y_test=train_test_split(scaled_features,df1['Sales'],test_size=0.30)

from sklearn.neighbors import KNeighborsClassifier

knn=KNeighborsClassifier(n_neighbors=5)
knn.fit(X_train,y_train)

then i run it but it shows me, ValueError: Input contains NaN, infinity or a value too large for dtype('float64')

how i can solve it?

确保您没有NaN值:

df1 = df1.dropna()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM