Ejemplo n.º 1
0
import matplotlib.pyplot as plt
from numpy import *

import kNN


def paintDataSet():
    datingDataMat, datingLabels = kNN.file2matrix('datingTestSet.txt')

    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.scatter(datingDataMat[:, 1], datingDataMat[:, 2], 20.0*array(datingLabels), 20.0*array(datingLabels))
    plt.show()

if __name__ == '__main__':
    kNN.classifyPerson()


Ejemplo n.º 2
0
datingDataMat, datingLabels = kNN.file2matrix('datingTestSet2.txt')
print(datingDataMat)
print(datingLabels[0:20])

# scatter plot
fig = plt.figure()
ax = fig.add_subplot(111)
ax.scatter(datingDataMat[:, 0], datingDataMat[:, 1],
           15.0 * np.array(datingLabels), 15.0 * np.array(datingLabels))
plt.show()

# normalization
normMat, ranges, minVals = kNN.autoNorm(datingDataMat)
print(normMat)
print(ranges)
print(minVals)

# test error rate
kNN.datingClassTest()

# predict
kNN.classifyPerson()

# handwriting nums recognition
# load daata
testVector = kNN.img2vector('dataset/testDigits/0_13.txt')
print(testVector[0, 0:31])

# handwriting class test
kNN.handwritingClassTest()
Ejemplo n.º 3
0
    [ 0.76626481, 0.44109859, 0.88192528],
    [ 0.0975718 , 0.02096883, 0.02443895]])
  >>> ranges
    array([ 8.78430000e+04, 2.02823930e+01, 1.69197100e+00])
  >>> minVals
    array([ 0. , 0. , 0.001818])
"""

KNN.datingClassTest()
"""
output:
the total error rate is: 0.080000
16.0
"""

KNN.classifyPerson()
"""
output:
  percentage of time spent playing video games?4
  frequent flier miles earned per year?5569
  liters of ice cream consumed per year?1.213192
  You will probably like this person: in small doses
"""

KNN.handwritingClassTest()
"""
output:
  the total number of errors is: 10
  the total error rate is: 0.010571
"""
Ejemplo n.º 4
0
'''
datingDataMat,datingLabels = kNN.file2matrix('datingTestSet.txt')
print(datingDataMat)
print(datingLabels)

fig = plt.figure()
# 图片位置
ax = fig.add_subplot(111)
# scatter(x,y,大小,颜色)
ax.scatter(datingDataMat[:,0],datingDataMat[:,1],
	20.0*array(datingLabels),15.0*array(datingLabels))
plt.show()
'''

'''
datingDataMat,datingLabels = kNN.file2matrix('datingTestSet.txt')
normMat,ranges,minVals = kNN.autoNorm(datingDataMat)
# print(normMat)

# kNN.datingClassTest()

kNN.classifyPerson()
'''

'''
testVector = kNN.img2Vector('digits/testDigitsnumFeatures/0_13.txt')
print("--------")
print(testVector[0,0:31])
print(testVector[0,32:63])
'''
Ejemplo n.º 5
0
 def test_classifyPerson(self):
     kNN.classifyPerson()
Ejemplo n.º 6
0
def main6():
    '''
    约会网站测试函数
    '''
    kNN.classifyPerson()
Ejemplo n.º 7
0
from numpy import array
import kNN
reload(kNN)
print kNN.datingClassTest()
print kNN.classifyPerson()