sklearn中的train_test_split:
from sklearn.model_selection import train_test_split
data_train,data_test,label_train,label_test = train_test_split(x,y,test_size=0.3,random_state=123)
test = KNeighborsClassifier(n_neighbors=4)
test.fit(data_train,label_train)
res1 = test.predict(data_test)
print(sum(res1 == label_test)/len(label_test))#准确率
#返回测试的准确率
from sklearn.metrics import accuracy_score
accuracy_score(res,test_label)