当前位置: 首页>>代码示例>>Python>>正文


Python KNN.autoNorm方法代码示例

本文整理汇总了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()
开发者ID:foxli180,项目名称:Self_Learning,代码行数:57,代码来源:my1stplot.py

示例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)
开发者ID:bzhou830,项目名称:ML-python,代码行数:14,代码来源:test.py

示例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()
开发者ID:chendi1995,项目名称:machine_learning,代码行数:14,代码来源:matplot.py


注:本文中的KNN.autoNorm方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。