ValueError:输入包含NaN,无穷大或dtype('float64')太大的值。对于我的knn模型

时间:2019-12-17 21:14:59

标签: python pandas scikit-learn

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)

然后我运行它,但显示为ValueError: Input contains NaN, infinity or a value too large for dtype('float64')

我该如何解决?

1 个答案:

答案 0 :(得分:0)

确保您没有NaN值:

df1 = df1.dropna()