... ...
the classifier came backwith: 3, thereal answer is: 3the classifier came backwith: 2, thereal answer is: 2the classifier came backwith: 1, thereal answer is: 1the classifier came backwith: 3, thereal answer is: 1the total error rate is: 0.050000
错误率为5%
添加以下函数,进行预测
#约会网站预测函数defclassifyPerson():
resultList = ['not at all', 'in small doses', 'in large doses']
percentTats = float(raw_input("percentage of time spent playing video games?"))
ffMiles = float(raw_input("frequent flier miles earned per year?"))
iceCream = float(raw_input("liters of ice cream consumed per year?"))
datingDataMat, datingLabels = file2matrix('datingTestSet2.txt')
normMat, ranges, minVals = autoNorm(datingDataMat)
inArr = array([ffMiles, percentTats, iceCream])
classifierResult = classify0((inArr-minVals)/ranges, normMat, datingLabels, 3)
print"You will probably like this person:", resultList[classifierResult-1]
>>> import KNN
>>> classifyPerson()
percentage oftime spent playing video games?20
frequent flier miles earned per year?10000
liters of ice cream consumed per year?0.6
You will probably like this person: in large doses