本文整理汇总了Python中KNN.autoNorm方法的典型用法代码示例。如果您正苦于以下问题:Python KNN.autoNorm方法的具体用法?Python KNN.autoNorm怎么用?Python KNN.autoNorm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KNN
的用法示例。
在下文中一共展示了KNN.autoNorm方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plotwithlable
# 需要导入模块: import KNN [as 别名]
# 或者: from KNN import autoNorm [as 别名]
def plotwithlable():
xcord1 = []; ycord1 = []; zcord1=[]
xcord2 = []; ycord2 = []; zcord2=[]
xcord3 = []; ycord3 = []; zcord3=[]
#group ,labels = createDataSet()
datingDataMat, datingLables = KNN.file2matrix('datingTestSet2.txt')
#print(datingDataMat)
#print(datingDataMat[0,2])
#print(datingLables)
normDataMat, ranges, minVals = KNN.autoNorm(datingDataMat)
#print(normDataMat)
tmp = datingDataMat
datingDataMat = normDataMat
fig = plt.figure() #create pic: fig
ax = fig.add_subplot(311) #create a subplot with 1 row 1 colum, select pic 1
#type1 = ax.scatter(xcord1, ycord1, s=20, c='red')
#type2 = ax.scatter(xcord2, ycord2, s=30, c='green')
#type3 = ax.scatter(xcord3, ycord3, s=50, c='blue')
for index, value in enumerate(datingLables):
if value == 1:
xcord1.append(datingDataMat[index,0])
ycord1.append(datingDataMat[index,1])
zcord1.append(datingDataMat[index,2])
elif value == 2:
xcord2.append(datingDataMat[index,0])
ycord2.append(datingDataMat[index,1])
zcord2.append(datingDataMat[index,2])
else:
xcord3.append(datingDataMat[index,0])
ycord3.append(datingDataMat[index,1])
zcord3.append(datingDataMat[index,2])
type1 = ax.scatter(xcord1, ycord1, s=20, c='red')
type2 = ax.scatter(xcord2, ycord2, s=30, c='green')
type3 = ax.scatter(xcord3, ycord3, s=50, c='blue')
ax.legend([type1, type2, type3], ["Did Not Like", "Liked in Small Doses", "Liked in Large Doses"], loc=2)
ax2 = fig.add_subplot(312)
type1 = ax2.scatter(xcord1, zcord1, s=20, c='red')
type2 = ax2.scatter(xcord2, zcord2, s=30, c='green')
type3 = ax2.scatter(xcord3, zcord3, s=50, c='blue')
ax2.legend([type1, type2, type3], ["Did Not Like", "Liked in Small Doses", "Liked in Large Doses"], loc=2)
plt.xlabel("Frequent Flyier Miles Earned Per Year")
plt.ylabel("Liters of Ice Cream Consumed Per Week")
ax3 = fig.add_subplot(313)
type1 = ax3.scatter(ycord1, zcord1, s=20, c='red')
type2 = ax3.scatter(ycord2, zcord2, s=30, c='green')
type3 = ax3.scatter(ycord3, zcord3, s=50, c='blue')
ax3.legend([type1, type2, type3], ["Did Not Like", "Liked in Small Doses", "Liked in Large Doses"], loc=2)
plt.xlabel("Percentage of Body Covered By Tatoos")
plt.ylabel("Liters of Ice Cream Consumed Per Week")
plt.show()
示例2: classifyPerson
# 需要导入模块: import KNN [as 别名]
# 或者: from KNN import autoNorm [as 别名]
def classifyPerson():
print "输入相关信息"
resultList = ['一点不喜欢','有点希望','可能性很大']
percentTats = float(raw_input("玩游戏时间数目?"))
ffMiles = float(raw_input("旅游公路数?"))
ice = float(raw_input("冰淇淋消耗量?"))
datingDataMat,datingLabels = KNN.file2matrix('datingTestSet2.txt')
normMat,ranges,minVals = KNN.autoNorm(datingDataMat)
inArr = np.array([ffMiles,percentTats,ice])
classfierRt = KNN.classify0((inArr-minVals)/ranges,normMat,datingLabels,3)
print resultList[classfierRt - 1]
PrintFigure(normMat, datingLabels)
示例3:
# 需要导入模块: import KNN [as 别名]
# 或者: from KNN import autoNorm [as 别名]
#!/usr/bin/env python
# -*- coding:utf-8 -*-
from numpy import *
import KNN
import matplotlib
import matplotlib.pyplot as plt
datingDataMat,datingLabels=KNN.file2matrix('datingTestSet.txt')
datingDataMat1,ranges,minVals=KNN.autoNorm(datingDataMat)
fig=plt.figure()
ax=fig.add_subplot(111)
ax.scatter(datingDataMat1[:,0],datingDataMat1[:,1],15.0*array(datingLabels),15.0*array(datingLabels));
plt.show()