from sklearn.neighbors import KNeighborsClassifier
# 创建knn算法的分类器实例
# n_neighbors=6,指定选取邻居的个数
knn_classifier = KNeighborsClassifier(n_neighbors=6)
# 拟合训练数据
knn_classifier.fit(X_train,y_train)
# 将样本维度变为二维,X_train,y_train为二维数组
x1 = x.reshape(1, -1)
x1
# array([[8.09360732, 3.36573151]])
# 利用knn算法进行预测
y_predict = knn_classifier.predict(x1)
# 得出预测结果
y_predict[0]
# 1