2-5 约会网站预测函数
一. 函数实现
# 约会网站预测函数
def classifyPerson():
resultList = ['largeDoses', 'smallDoses', 'didntLike'] # 预测结果集
percentTats = float(input("Please input percentage of time spent playing vedio games?"))
ffMiles = float(input("frequent flier miles earned consumed per year?"))
iceCream = float(input("Liters of ice cream consumed per year?"))
datingDataMat, datingLabels = fileToMatrix('1.txt', 3)
normMat, ranges, minVals = autoNorm(datingDataMat)
inArr = np.array([ffMiles, percentTats, iceCream])
classifierResult = classifyByKnn((inArr - minVals) / ranges, normMat, datingLabels, 3)
print("You will probably like this person : %s " % resultList[classifierResult - 1])
二. 完整代码
import numpy as np
import operator
def classi