本文整理匯總了Python中KNN.normalize方法的典型用法代碼示例。如果您正苦於以下問題:Python KNN.normalize方法的具體用法?Python KNN.normalize怎麽用?Python KNN.normalize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類KNN
的用法示例。
在下文中一共展示了KNN.normalize方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: date_class_test
# 需要導入模塊: import KNN [as 別名]
# 或者: from KNN import normalize [as 別名]
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))