GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — 分类器针对约会网站的测试代码 · fciasth/pythonMLAction@77e1503

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • KNN.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎KNN.py‎

Copy file name to clipboardExpand all lines: KNN.py
+20-4Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,26 @@ def autoNorm(dataSet):
5353
minVals = dataSet.min(0)
5454
#其中dataSet.min(0)中的参数0使得函数可以从列中选取最小值,而不是选取当前行的最小值。
5555
maxVals = dataSet.max(0)
56-
range = maxVals - minVals
56+
range1 = maxVals - minVals
5757
m = dataSet.shape[0]
5858
normDataSet = dataSet - tile(minVals,[m,1])
59-
normDataSet = normDataSet/tile(range,[m,1])
60-
return normDataSet,minVals,range
59+
normDataSet = normDataSet/tile(range1,[m,1])
60+
return normDataSet,minVals,range1
6161
#测试
62-
normMat,minVals,range = autoNorm(datingDataMat)
62+
normMat,minVals,range1 = autoNorm(datingDataMat)
63+
64+
#测试算法:作为完整程序验证分类器
65+
def datingClassTest():
66+
hoRatio =0.10
67+
datingDataMat, datingLabels = file2matrix('datingTestSet2.txt')
68+
normMat, minVals, range1 = autoNorm(datingDataMat)
69+
m = normMat.shape[0]
70+
numTestVecs = int(m*hoRatio)
71+
errorCount = 0.0
72+
for i in range(numTestVecs):
73+
classifierResult = classify0(normMat[i,:],normMat[numTestVecs:m,:],datingLabels[numTestVecs:m],3)
74+
print ("the classifier came back with: %d ,the real answer is: %d"%(classifierResult,datingLabels[i]))
75+
if(classifierResult !=datingLabels[i]): errorCount+=1.0
76+
print("the total error rate is: %f"%(errorCount/float(numTestVecs)))
77+
#测试
78+
#datingClassTest()

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.