if __name__ == '__main__': train_x,train_y,test_x,test_y = createDataSet() y_test_pred = kNN_classify(50, 'E',train_x,train_y,test_x) q=p=0 for i in range(0,(test_x.shape[0])): if y_test_pred[i]==test_y[i]: #如果计算的结果和数据集里的诊断结果一致,q+1,否则p+1, q=q+1 else: p=p+1 q=(q/(test_x.shape[0]))*100 p=(p/(test_x.shape[0]))*100 print("{:.2f}%符合,{:.2f}%不符合".format(q,p)) #这个是用jupyter notebook 写的