本文整理汇总了Python中KNN.hand_writings_test方法的典型用法代码示例。如果您正苦于以下问题:Python KNN.hand_writings_test方法的具体用法?Python KNN.hand_writings_test怎么用?Python KNN.hand_writings_test使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KNN
的用法示例。
在下文中一共展示了KNN.hand_writings_test方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: array
# 需要导入模块: import KNN [as 别名]
# 或者: from KNN import hand_writings_test [as 别名]
15.0 * array(dating_label), 15.0 * array(dating_label))
plt.show()
def date_class_test():
ratio = 0.04 # ratio of the test examples
# data_set:1000*3, data_labels: 1000*1
data_set, data_labels = KNN.file_to_matrix('datingTestSet2.txt')
# normilize the data_set. Note: data_labels is not nessary to normlize
norm_set, ranges, min_val = KNN.normalize(data_set)
all_rows = norm_set.shape[0] # number of all rows
test_rows = int(ratio * all_rows) # number of test rows
error_num = 0
for i in range(test_rows):
# return the predict labels
label_res = KNN.knn_classify(norm_set[i, :], norm_set[test_rows: all_rows, :],\
data_labels[test_rows: all_rows, :], 3)
print 'Classifier predict: %d, real result is: %d' % (label_res, data_labels[i])
if label_res != data_labels[i]:
error_num += 1
print 'total error rate is: %f ' % (error_num * 1.0 / float(test_rows))
if __name__ == '__main__':
# date_class_test()
KNN.hand_writings_test()