{"id":63298,"date":"2026-01-21T19:32:59","date_gmt":"2026-01-21T11:32:59","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/63298.html"},"modified":"2026-01-21T19:32:59","modified_gmt":"2026-01-21T11:32:59","slug":"k%e8%bf%91%e9%82%bb%e7%ae%97%e6%b3%95%e8%ae%b2%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/63298.html","title":{"rendered":"k\u8fd1\u90bb\u7b97\u6cd5\u8bb2\u89e3"},"content":{"rendered":"<h5>\u7b97\u6cd5\u5b9a\u4e49<br \/>\n\u00a0 k-\u8fd1\u90bb\u7b97\u6cd5&#xff08;k-Nearest Neighbors, k-NN&#xff09; \u662f\u4e00\u79cd\u7b80\u5355\u800c\u5e38\u7528\u7684 \u76d1\u7763\u5b66\u4e60\u7b97\u6cd5&#xff0c;\u4e3b\u8981\u7528\u4e8e\u5206\u7c7b\u548c\u56de\u5f52\u4efb\u52a1\u3002\u5b83\u7684\u6838\u5fc3\u601d\u60f3\u662f&#xff1a;\u901a\u8fc7\u8ba1\u7b97\u5f85\u5206\u7c7b\u6837\u672c\u4e0e\u8bad\u7ec3\u96c6\u4e2d\u6240\u6709\u6837\u672c\u7684\u8ddd\u79bb&#xff0c;\u627e\u5230\u8ddd\u79bb\u6700\u8fd1\u7684 k \u4e2a\u6837\u672c&#xff0c;\u7136\u540e\u6839\u636e\u8fd9 k \u4e2a\u6837\u672c\u7684\u7c7b\u522b\u6216\u503c\u6765\u9884\u6d4b\u5f85\u5206\u7c7b\u6837\u672c\u7684\u7c7b\u522b\u6216\u503c\u3002<\/h5>\n<h4>\u4e00\u3001\u95ee\u9898\u5f15\u5165<\/h4>\n<p>\u6d77\u4f26\u4e00\u76f4\u4f7f\u7528\u5728\u7ebf\u7ea6\u4f1a\u7f51\u7ad9\u5bfb\u627e\u9002\u5408\u81ea\u5df1\u7684\u7ea6\u4f1a\u5bf9\u8c61\u3002\u5979\u66fe\u4ea4\u5f80\u8fc7\u4e09\u79cd\u7c7b\u578b\u7684\u4eba&#xff1a;<\/p>\n<p>&#8211; \u4e0d\u559c\u6b22\u7684\u4eba<\/p>\n<p>&#8211; \u4e00\u822c\u559c\u6b22\u7684\u4eba<\/p>\n<p>&#8211; \u975e\u5e38\u559c\u6b22\u7684\u4eba<\/p>\n<p>\u8fd9\u4e9b\u4eba\u5305\u542b\u4ee5\u4e0b\u4e09\u79cd\u7279\u5f81<\/p>\n<p>1. \u6bcf\u5e74\u83b7\u5f97\u7684\u98de\u884c\u5e38\u5ba2\u91cc\u7a0b\u6570<\/p>\n<p>2. \u73a9\u89c6\u9891\u6e38\u620f\u6240\u8017\u65f6\u95f4\u767e\u5206\u6bd4<\/p>\n<p>3. \u6bcf\u5468\u6d88\u8d39\u7684\u51b0\u6dc7\u6dcb\u516c\u5347\u6570<\/p>\n<p>\u8be5\u7f51\u7ad9\u73b0\u5728\u9700\u8981\u5c3d\u53ef\u80fd\u5411\u6d77\u4f26\u63a8\u8350\u5979\u559c\u6b22\u7684\u4eba&#xff0c;\u9700\u8981\u6211\u4eec\u8bbe\u8ba1\u4e00\u4e2a\u5206\u7c7b\u5668&#xff0c;\u6839\u636e\u7528\u6237\u7684\u4ee5\u4e0a\u4e09\u79cd\u7279\u5f81&#xff0c;\u8bc6\u522b\u51fa\u662f\u5426\u8be5\u5411\u6d77\u4f26\u63a8\u8350\u3002<\/p>\n<h4>\u4e8c&#xff0c;\u89e3\u51b3\u601d\u8def<\/h4>\n<p>&#xff08;1&#xff09;\u5199\u51fak\u8fd1\u90bb\u7b97\u6cd5&#xff1a;<\/p>\n<p>\u8ba1\u7b97\u5f85\u5206\u7c7b\u6837\u672c\u4e0e\u8bad\u7ec3\u96c6\u4e2d\u6bcf\u4e2a\u6837\u672c\u7684\u8ddd\u79bb&#xff08;\u53ef\u7528\u6b27\u6c0f\u8ddd\u79bb\u6216\u66fc\u54c8\u987f\u8ddd\u79bb\u516c\u5f0f&#xff09;&#xff1b;\u9009\u62e9k\u4e2a\u6700\u8fd1\u90bb\u5c45&#xff1a;\u6839\u636e\u8ba1\u7b97\u7684\u8ddd\u79bb&#xff0c;\u9009\u62e9\u8ddd\u79bb\u6700\u8fd1\u7684 k \u4e2a\u8bad\u7ec3\u6837\u672c\u3002\u6295\u7968\u6216\u5e73\u5747&#xff1a;\u5206\u7c7b\u4efb\u52a1&#xff1a;\u7edf\u8ba1 k \u4e2a\u6700\u8fd1\u90bb\u5c45\u7684\u7c7b\u522b&#xff0c;\u9009\u62e9\u51fa\u73b0\u6b21\u6570\u6700\u591a\u7684\u7c7b\u522b\u4f5c\u4e3a\u9884\u6d4b\u7ed3\u679c\u3002\u56de\u5f52\u4efb\u52a1&#xff1a;\u8ba1\u7b97 k \u4e2a\u6700\u8fd1\u90bb\u5c45\u7684\u503c\u7684\u5e73\u5747\u503c\u4f5c\u4e3a\u9884\u6d4b\u7ed3\u679c\u3002\u5177\u4f53\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>def classify0(inX,dataSet,labels,k):<\/p>\n<p>\u00a0 \u00a0 dataSetSize &#061; dataSet.shape[0]#\u83b7\u53d6\u6837\u672c\u884c\u6570<\/p>\n<p>\u00a0 \u00a0 diffMat &#061; np.tile(inX,(dataSetSize,1))-dataSet#\u8ba1\u7b97\u8f93\u5165\u6837\u672c inX \u4e0e\u6570\u636e\u96c6\u4e2d\u6bcf\u4e2a\u6837\u672c\u7684\u5dee\u503c\u3002<\/p>\n<p>\u00a0 \u00a0 sqDiffMat &#061; diffMat ** 2<\/p>\n<p>\u00a0 \u00a0 sqDistances&#061;sqDiffMat.sum(axis&#061;1)#\u8ba1\u7b97\u6bcf\u4e2a\u6837\u672c\u4e0e\u8f93\u5165\u6837\u672c inX \u7684\u6b27\u6c0f\u8ddd\u79bb\u7684\u5e73\u65b9\u3002<\/p>\n<p>\u00a0 \u00a0 distances &#061; sqDistances ** 0.5<\/p>\n<p>\u00a0 \u00a0 sortedDistIndicies&#061;distances.argsort()#\u5bf9\u8ddd\u79bb\u8fdb\u884c\u6392\u5e8f&#xff0c;\u5e76\u8fd4\u56de\u6392\u5e8f\u540e\u7684\u7d22\u5f15\u3002<\/p>\n<p>\u00a0 \u00a0 classCount&#061;{}<\/p>\n<p>\u00a0 \u00a0 for i in range (k):<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 voteIlabel &#061; labels[sortedDistIndicies[i]]<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 classCount[voteIlabel] &#061; classCount.get(voteIlabel,0)&#043;1#\u7edf\u8ba1\u6bcf\u4e2a\u7c7b\u522b\u7684\u6295\u7968\u6570\u3002<\/p>\n<p>\u00a0 \u00a0 sortedClassCount &#061; sorted(classCount.items(),key&#061;operator.itemgetter(1),reverse&#061;True)#\u5bf9 classCount \u5b57\u5178\u6309\u6295\u7968\u6570\u4ece\u9ad8\u5230\u4f4e\u6392\u5e8f\u3002<\/p>\n<p>\u00a0 \u00a0 return sortedClassCount[0][0]#\u8fd4\u56de\u6295\u7968\u6570\u6700\u591a\u7684\u7c7b\u522b\u3002<\/p>\n<p>&#xff08;2&#xff09;\u5c06\u6587\u672c\u8bb0\u5f55\u8f6c\u5316\u4e3anumpy\u7684\u89e3\u6790\u7a0b\u5e8f&#xff1a;<\/p>\n<p>\u00a0 \u5bfc\u5165\u5fc5\u8981\u7684\u5e93\u5e76\u5b9a\u4e49\u51fd\u6570 file2matrix \u7136\u540e\u6253\u5f00\u6587\u4ef6\u5e76\u8bfb\u53d6\u6240\u6709\u884c&#xff0c;\u8ba1\u7b97\u6587\u4ef6\u7684\u884c\u6570\u548c\u904d\u5386\u6bcf\u4e00\u884c\u6570\u636e\u5e76\u5904\u7406\u521d\u59cb\u5316\u7279\u5f81\u77e9\u9635\u548c\u6807\u7b7e\u5411\u91cf&#xff0c;\u6700\u540e\u8fd4\u56de\u7279\u5f81\u77e9\u9635\u548c\u6807\u7b7e\u5411\u91cf\u3002\u5177\u4f53\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>def file2matrix(datingTestSet):<\/p>\n<p>\u00a0 \u00a0 fr&#061;open(datingTestSet)<\/p>\n<p>\u00a0 \u00a0 arrayOLines&#061;fr.readlines()<\/p>\n<p>\u00a0 \u00a0 numberOfLines&#061;len(arrayOLines)#\u8ba1\u7b97\u6587\u4ef6\u7684\u884c\u6570&#xff0c;\u5373\u5217\u8868 arrayOLines \u7684\u957f\u5ea6&#xff0c;\u5e76\u5c06\u5176\u8d4b\u503c\u7ed9\u53d8\u91cf numberOfLines\u3002<\/p>\n<p>\u00a0 \u00a0 returnMat &#061; np.zeros((numberOfLines,3))#\u4f7f\u7528 np.zeros \u521b\u5efa\u4e00\u4e2a\u5927\u5c0f\u4e3a (numberOfLines, 3) \u7684\u5168\u96f6\u77e9\u9635 returnMat&#xff0c;\u7528\u4e8e\u5b58\u50a8\u7279\u5f81\u6570\u636e\u3002<\/p>\n<p>\u00a0 \u00a0 classLabelVector&#061;[]<\/p>\n<p>\u00a0 \u00a0 index&#061;0<\/p>\n<p>\u00a0 \u00a0 for line in arrayOLines:<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 line&#061;line.strip()#\u4f7f\u7528 strip() \u65b9\u6cd5\u53bb\u9664\u5f53\u524d\u884c\u5f00\u5934\u548c\u7ed3\u5c3e\u7684\u7a7a\u767d\u5b57\u7b26&#xff08;\u5982\u7a7a\u683c\u3001\u6362\u884c\u7b26\u7b49&#xff09;\u3002<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 listFromLine&#061;line.split(&#039;\\\\t&#039;)#\u4f7f\u7528 split(&#039;\\\\t&#039;) \u65b9\u6cd5\u6309\u5236\u8868\u7b26 \\\\t \u5c06\u5f53\u524d\u884c\u5206\u5272\u6210\u4e00\u4e2a\u5217\u8868 listFromLine\u3002<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 returnMat[index,:]&#061;listFromLine[0:3]#\u5c06 listFromLine \u4e2d\u7684\u524d 3 \u4e2a\u5143\u7d20&#xff08;\u7279\u5f81\u503c&#xff09;\u8d4b\u503c\u7ed9 returnMat \u7684\u7b2c index \u884c\u3002<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 classLabelVector.append(listFromLine[-1])#\u5c06 listFromLine \u7684\u6700\u540e\u4e00\u4e2a\u5143\u7d20&#xff08;\u6807\u7b7e&#xff09;\u6dfb\u52a0\u5230 classLabelVector \u4e2d\u3002<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 index&#043;&#061;1<\/p>\n<p>\u00a0 \u00a0 return returnMat,classLabelVecto<\/p>\n<p>&#xff08;3&#xff09;\u5f52\u4e00\u5316\u7279\u5f81\u503c<\/p>\n<p>\u4e3b\u8981\u516c\u5f0f&#xff1a;newValue&#061;(oldValue-min)\/(max-min)<\/p>\n<p>\u00a0\u5b9a\u4e49\u51fd\u6570autonorm&#xff0c;\u8ba1\u7b97\u6bcf\u5217\u7684\u6700\u5c0f\u503c\u548c\u6700\u5927\u503c\u5e76\u521d\u59cb\u5316\u5f52\u4e00\u5316\u540e\u7684\u6570\u636e\u96c6\u7528 np.tile(minVals, (m, 1)) \u5c06 minVals \u6309\u884c\u590d\u5236 m \u6b21&#xff0c;\u751f\u6210\u4e00\u4e2a\u4e0e dataSet \u5f62\u72b6\u76f8\u540c\u7684\u77e9\u9635\u3002\u5c06 dataSet \u4e2d\u7684\u6bcf\u4e2a\u503c\u51cf\u53bb\u5bf9\u5e94\u5217\u7684\u6700\u5c0f\u503c&#xff0c;\u5f97\u5230\u5e73\u79fb\u540e\u7684\u6570\u636e\u3002\u6700\u540e\u5f52\u4e00\u5316\u6570\u636e\u5e76\u8fd4\u56de\u3002\u5177\u4f53\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>def autoNorm(dataSet):<\/p>\n<p>\u00a0 \u00a0 minVals&#061;dataSet.min(0)<\/p>\n<p>\u00a0 \u00a0 maxVals&#061;dataSet.max(0)<\/p>\n<p>\u00a0 \u00a0 ranges&#061;maxVals-minVals<\/p>\n<p>\u00a0 \u00a0 normDataSet&#061;np.zeros(np.shape(dataSet))#\u521b\u5efa\u4e00\u4e2a\u4e0e dataSet \u5f62\u72b6\u76f8\u540c\u7684\u5168\u96f6\u77e9\u9635 normDataSet&#xff0c;\u7528\u4e8e\u5b58\u50a8\u5f52\u4e00\u5316\u540e\u7684\u6570\u636e\u3002<\/p>\n<p>\u00a0 \u00a0 m&#061;dataSet.shape[0]#\u83b7\u53d6\u6570\u636e\u96c6\u7684\u884c\u6570&#xff08;\u6837\u672c\u6570\u91cf&#xff09;&#xff0c;\u8d4b\u503c\u7ed9\u53d8\u91cf m\u3002<\/p>\n<p>\u00a0 \u00a0 normDataSet&#061;dataSet-np.tile(minVals,(m,1))#\u5c06\u6570\u636e\u96c6\u4e2d\u7684\u6bcf\u4e2a\u503c\u51cf\u53bb\u5bf9\u5e94\u5217\u7684\u6700\u5c0f\u503c&#xff0c;\u5f97\u5230\u5e73\u79fb\u540e\u7684\u6570\u636e\u3002<\/p>\n<p>\u00a0 \u00a0 normDataSet&#061;normDataSet \/np.tile(ranges,(m,1))#\u5c06\u5e73\u79fb\u540e\u7684\u6570\u636e\u9664\u4ee5\u5bf9\u5e94\u5217\u7684\u8303\u56f4&#xff0c;\u5f97\u5230\u5f52\u4e00\u5316\u540e\u7684\u6570\u636e\u3002<\/p>\n<p>\u00a0 \u00a0 return normDataSet,ranges,minVals<\/p>\n<p>&#xff08;4&#xff09;\u5206\u7c7b\u5668\u9488\u5bf9\u7ea6\u4f1a\u7f51\u7ad9\u4ee3\u7801\u00a0<\/p>\n<p>\u00a0 \u5b9a\u4e49 hoRatio &#061; 0.10&#xff0c;\u5c06\u6570\u636e\u96c6\u7684 10% \u4f5c\u4e3a\u6d4b\u8bd5\u96c6&#xff0c;\u5269\u4f59\u7684 90% \u4f5c\u4e3a\u8bad\u7ec3\u96c6\u7528 file2matrix \u51fd\u6570\u4ece\u6587\u4ef6 datingTestSet.txt \u4e2d\u52a0\u8f7d\u6570\u636e&#xff1b;\u8c03\u7528 autoNorm \u51fd\u6570\u5bf9\u7279\u5f81\u77e9\u9635 datingDataMat \u8fdb\u884c\u5f52\u4e00\u5316\u5904\u7406&#xff0c;\u5f97\u5230\u5f52\u4e00\u5316\u540e\u7684\u7279\u5f81\u77e9\u9635 normMat\u3002&#xff1b;\u83b7\u53d6\u5f52\u4e00\u5316\u540e\u6570\u636e\u96c6\u7684\u884c\u6570 m\u3002\u8ba1\u7b97\u6d4b\u8bd5\u96c6\u7684\u6570\u91cf numTestVecs &#061; int(m * hoRatio)\u3002&#xff1b;\u904d\u5386\u6d4b\u8bd5\u96c6\u4e2d\u7684\u6bcf\u4e00\u4e2a\u6837\u672c&#xff1a;\u8c03\u7528 classify0 \u51fd\u6570\u5bf9\u5f53\u524d\u6d4b\u8bd5\u6837\u672c\u8fdb\u884c\u5206\u7c7b&#xff0c;\u6700\u540e\u8ba1\u7b97\u5206\u7c7b\u5668\u7684\u603b\u9519\u8bef\u7387\u3002\u5177\u4f53\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>def datingClassTest():<\/p>\n<p>\u00a0 \u00a0 hoRatio&#061;0.10#\u610f\u5473\u7740\u6570\u636e\u96c6\u4e2d\u524d 10% \u7684\u6837\u672c\u5c06\u4f5c\u4e3a\u6d4b\u8bd5\u96c6&#xff0c;\u5269\u4f59\u7684 90% \u4f5c\u4e3a\u8bad\u7ec3\u96c6\u3002<\/p>\n<p>\u00a0 \u00a0 datingDataMat,datingLabels&#061;file2matrix(&#039;datingTestSet.txt&#039;)#\u8c03\u7528 file2matrix \u51fd\u6570\u4ece\u6587\u4ef6 datingTestSet.txt \u4e2d\u52a0\u8f7d\u6570\u636e\u3002<\/p>\n<p>\u00a0 \u00a0 normMat,ranges,minVals&#061;autoNorm(datingDataMat)#\u8c03\u7528 autoNorm \u51fd\u6570\u5bf9\u7279\u5f81\u77e9\u9635 datingDataMat \u8fdb\u884c\u5f52\u4e00\u5316\u3002<\/p>\n<p>\u00a0 \u00a0 m&#061;normMat.shape[0]<\/p>\n<p>\u00a0 \u00a0 numTestVecs&#061;int(m*hoRatio)<\/p>\n<p>\u00a0 \u00a0 errorCount&#061;0.0<\/p>\n<p>\u00a0 \u00a0 for i in range(numTestVecs):<\/p>\n<p>\u00a0 classifierResult&#061;classify0(normMat[i,:],normMat[numTestVecs:m,:],datingLabels[numTestVecs:m],3)#\u8c03\u7528 classify0 \u51fd\u6570\u5bf9\u5f53\u524d\u6d4b\u8bd5\u6837\u672c normMat[i, :] \u8fdb\u884c\u5206\u7c7b<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 print(f&#034;the classifier came back with :{classifierResult} ,the real answer is :{datingLabels[i]} &#034; \u00a0)#\u5982\u679c\u5206\u7c7b\u5668\u7684\u9884\u6d4b\u7ed3\u679c\u4e0e\u771f\u5b9e\u6807\u7b7e\u4e0d\u4e00\u81f4&#xff0c;\u5219\u5c06\u9519\u8bef\u8ba1\u6570\u5668 errorCount \u52a0 1\u3002<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 if(classifierResult!&#061;datingLabels[i]):<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 errorCount &#043;&#061; 1.0<\/p>\n<p>\u00a0 \u00a0 print (f&#034;the total error rate is :{errorCount\/float(numTestVecs)}&#034; )<\/p>\n<p>&#xff08;5&#xff09;\u7ea6\u4f1a\u7f51\u7ad9\u9884\u6d4b\u51fd\u6570<\/p>\n<p>\u00a0 \u5b9a\u4e49\u4e09\u4e2a\u7ed3\u679c\u6807\u7b7e&#xff0c;\u8c03\u7528 file2matrix \u51fd\u6570\u4ece\u6587\u4ef6 datingTestSet.txt \u4e2d\u52a0\u8f7d\u6570\u636e&#xff0c;\u7136\u540e\u8c03\u7528 autoNorm \u51fd\u6570\u5bf9\u7279\u5f81\u77e9\u9635 datingDataMat \u8fdb\u884c\u5f52\u4e00\u5316\u5904\u7406\u3002\u5c06\u7528\u6237\u8f93\u5165\u7684\u7279\u5f81\u503c\u7ec4\u5408\u6210\u4e00\u4e2a numpy \u6570\u7ec4 inArr\u3002\u5bf9 inArr \u8fdb\u884c\u5f52\u4e00\u5316\u5904\u7406&#xff0c;\u4f7f\u5176\u4e0e\u8bad\u7ec3\u6570\u636e\u7684\u8303\u56f4\u4e00\u81f4\u3002\u8c03\u7528 classify0 \u51fd\u6570\u5bf9\u5f52\u4e00\u5316\u540e\u7684\u7528\u6237\u8f93\u5165\u5411\u91cf\u8fdb\u884c\u5206\u7c7b\u3002\u6839\u636e classifierResult \u7684\u503c&#xff0c;\u4ece resultList \u4e2d\u83b7\u53d6\u5bf9\u5e94\u7684\u5206\u7c7b\u7ed3\u679c\u6807\u7b7e\u3002\u5177\u4f53\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>def classifyPerson():<\/p>\n<p>\u00a0 \u00a0 resultList &#061; [&#039;not at all&#039;,&#039;in small doses&#039;,&#039;in large doses&#039;]<\/p>\n<p>\u00a0 \u00a0 percenTats&#061;float(input(&#034;percentage of time spent playing video games?&#034;))<\/p>\n<p>\u00a0 \u00a0 ffMiles&#061;float(input(&#034;frequent flier miles earned per year?&#034;))<\/p>\n<p>\u00a0 \u00a0 iceCream &#061; float(input(&#034;liters of ice cream consumed per year?&#034;))<\/p>\n<p>\u00a0 \u00a0 datingDataMat,datingLabels&#061;file2matrix(&#039;datingTestSet.txt&#039;)<\/p>\n<p>\u00a0 \u00a0 normMat,ranges,minVals&#061;autoNorm(datingDataMat)#\u8c03\u7528 autoNorm \u51fd\u6570\u5bf9\u7279\u5f81\u77e9\u9635 datingDataMat \u8fdb\u884c\u5f52\u4e00\u5316\u3002<\/p>\n<p>\u00a0 \u00a0 inArr&#061;np.array([ffMiles,percenTats,iceCream])<\/p>\n<p>\u00a0 \u00a0 classifierResult&#061;classify0((inArr-minVals)\/ranges,normMat,datingLabels,3)#\u5bf9\u8f93\u5165\u5411\u91cf inArr \u8fdb\u884c\u5f52\u4e00\u5316&#xff1a;\u8c03\u7528 classify0 \u51fd\u6570\u5bf9\u5f52\u4e00\u5316\u540e\u7684\u8f93\u5165\u5411\u91cf\u8fdb\u884c\u5206\u7c7b<\/p>\n<p>\u00a0 \u00a0 print(f&#034;you will probably like this person:{resultList[classifierResult-1]}&#034;)<\/p>\n<p>&#xff08;6&#xff09;main\u51fd\u6570&#xff08;\u6ee1\u8db3\u9898\u76ee\u8981\u6c42\u5373\u53ef&#xff09;<\/p>\n<p>def main():<\/p>\n<p>\u00a0 \u00a0 print(&#034;\u6b22\u8fce\u4f7f\u7528\u7ea6\u4f1a\u63a8\u8350\u7cfb\u7edf&#xff01;&#034;)<\/p>\n<p>\u00a0 \u00a0 print(&#034;\u8bf7\u9009\u62e9\u529f\u80fd&#xff1a;&#034;)<\/p>\n<p>\u00a0 \u00a0 print(&#034;1. \u6d4b\u8bd5\u5206\u7c7b\u5668\u5728\u7ea6\u4f1a\u6570\u636e\u96c6\u4e0a\u7684\u6027\u80fd\u3002&#034;)<\/p>\n<p>\u00a0 \u00a0 print(&#034;2. \u6839\u636e\u60a8\u7684\u559c\u597d\u9884\u6d4b\u662f\u5426\u559c\u6b22\u67d0\u4eba\u3002&#034;)<\/p>\n<p>\u00a0 \u00a0 print(&#034;3. \u9000\u51fa\u7a0b\u5e8f\u3002&#034;)<\/p>\n<p>\u00a0 \u00a0 while True:<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 choice &#061; input(&#034;\u8bf7\u8f93\u5165\u60a8\u7684\u9009\u62e9&#xff08;1\u30012 \u6216 3&#xff09;&#xff1a;&#034;)<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 if choice &#061;&#061; &#039;1&#039;:<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 # \u6d4b\u8bd5\u5206\u7c7b\u5668<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 print(&#034;\\\\n\u6b63\u5728\u6d4b\u8bd5\u5206\u7c7b\u5668\u5728\u7ea6\u4f1a\u6570\u636e\u96c6\u4e0a\u7684\u6027\u80fd&#8230;&#034;)<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 datingClassTest()<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 elif choice &#061;&#061; &#039;2&#039;:<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 # \u9884\u6d4b\u7ea6\u4f1a\u7f51\u7ad9\u7ed3\u679c<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 print(&#034;\\\\n\u6b63\u5728\u6839\u636e\u60a8\u7684\u559c\u597d\u9884\u6d4b\u662f\u5426\u559c\u6b22\u67d0\u4eba&#8230;&#034;)<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 classifyPerson()<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 elif choice &#061;&#061; &#039;3&#039;:<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 # \u9000\u51fa\u7a0b\u5e8f<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 print(&#034;\\\\n\u6b63\u5728\u9000\u51fa\u7a0b\u5e8f\u3002\u518d\u89c1&#xff01;&#034;)<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 break<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 else:<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 print(&#034;\\\\n\u65e0\u6548\u7684\u9009\u62e9&#xff0c;\u8bf7\u8f93\u5165 1\u30012 \u6216 3\u3002&#034;)<\/p>\n<p># \u8c03\u7528 main \u51fd\u6570<\/p>\n<p>if __name__ &#061;&#061; &#034;__main__&#034;:<\/p>\n<p>\u00a0 \u00a0 main()<\/p>\n<h4>\u4e09&#xff0c;\u8f93\u51fa\u7ed3\u679c<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"350\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260121113258-6970b96a8bb42.png\" width=\"1031\" \/><\/p>\n<h4>\u00a0\u56db&#xff0c;\u5b9e\u9a8c\u603b\u7ed3<\/h4>\n<p>1. \u6570\u636e\u51c6\u5907&#xff1a;\u8fd9\u5305\u62ec\u6536\u96c6\u3001\u6e05\u6d17\u548c\u9884\u5904\u7406\u6570\u636e\u3002**\u9884\u5904\u7406\u53ef\u80fd\u5305\u62ec\u5f52\u4e00\u5316\u6216\u6807\u51c6\u5316\u7279\u5f81**&#xff0c;\u4ee5\u786e\u4fdd\u6240\u6709\u7279\u5f81\u5728\u8ba1\u7b97\u8ddd\u79bb\u65f6\u5177\u6709\u76f8\u7b49\u7684\u6743\u91cd\u3002<\/p>\n<p>| \u00a0 \u00a0 \u00a0| \u73a9\u89c6\u9891\u6e38\u620f\u6240\u8017\u65f6\u95f4\u767e\u5206\u6bd4 | \u6bcf\u5e74\u83b7\u5f97\u7684\u98de\u884c\u5e38\u5ba2\u91cc\u7a0b\u6570 | \u6bcf\u5468\u6d88\u8d39\u7684\u51b0\u6dc7\u6dcb\u7684\u516c\u5347\u6570 | \u6837\u672c\u5206\u7c7b |<\/p>\n<p>| &#8212;- | &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; | &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; | &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; | &#8212;&#8212;&#8211; |<\/p>\n<p>| 1 \u00a0 \u00a0| 0.8 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0| 400 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0| 0.5 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0| 1 \u00a0 \u00a0 \u00a0 \u00a0|<\/p>\n<p>| 2 \u00a0 \u00a0| 12 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 | 134000 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 | 0.9 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0| 3 \u00a0 \u00a0 \u00a0 \u00a0|<\/p>\n<p>| 3 \u00a0 \u00a0| 0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0| 20000 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0| 1.1 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0| 2 \u00a0 \u00a0 \u00a0 \u00a0|<\/p>\n<p>| 4 \u00a0 \u00a0| 67 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 | 32000 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0| 0.1 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0| 2 \u00a0 \u00a0 \u00a0 \u00a0|<\/p>\n<p>\u6211\u4eec\u5f88\u5bb9\u6613\u53d1\u73b0&#xff0c;\u5f53\u8ba1\u7b97\u6837\u672c\u4e4b\u95f4\u7684\u8ddd\u79bb\u65f6\u6570\u5b57\u5dee\u503c\u6700\u5927\u7684\u5c5e\u6027\u5bf9\u8ba1\u7b97\u7ed3\u679c\u7684\u5f71\u54cd\u6700\u5927&#xff0c;\u4e5f\u5c31\u662f\u8bf4&#xff0c;\u6bcf\u5e74\u83b7\u53d6\u7684\u98de\u884c\u5e38\u5ba2\u91cc\u7a0b\u6570\u5bf9\u4e8e\u8ba1\u7b97\u7ed3\u679c\u7684\u5f71\u54cd\u5c06\u8fdc\u8fdc\u5927\u4e8e\u4e0a\u8868\u4e2d\u5176\u4ed6\u4e24\u4e2a\u7279\u5f81-\u73a9\u89c6\u9891\u6e38\u620f\u6240\u8017\u65f6\u95f4\u5360\u6bd4\u548c\u6bcf\u5468\u6d88\u8d39\u51b0\u6dc7\u6dcb\u516c\u65a4\u6570\u7684\u5f71\u54cd\u3002\u800c\u4ea7\u751f\u8fd9\u79cd\u73b0\u8c61\u7684\u552f\u4e00\u539f\u56e0&#xff0c;\u4ec5\u4ec5\u662f\u56e0\u4e3a\u98de\u884c\u5e38\u5ba2\u91cc\u7a0b\u6570\u8fdc\u5927\u4e8e\u5176\u4ed6\u7279\u5f81\u503c\u3002\u4f46\u6d77\u4f26\u8ba4\u4e3a\u8fd9\u4e09\u79cd\u7279\u5f81\u662f\u540c\u7b49\u91cd\u8981\u7684&#xff0c;\u56e0\u6b64\u4f5c\u4e3a\u4e09\u4e2a\u7b49\u6743\u91cd\u7684\u7279\u5f81\u4e4b\u4e00&#xff0c;\u98de\u884c\u5e38\u5ba2\u91cc\u7a0b\u6570\u5e76\u4e0d\u5e94\u8be5\u5982\u6b64\u4e25\u91cd\u5730\u5f71\u54cd\u5230\u8ba1\u7b97\u7ed3\u679c\u3002<\/p>\n<p>\u5728\u5904\u7406\u8fd9\u79cd\u4e0d\u540c\u53d6\u503c\u8303\u56f4\u7684\u7279\u5f81\u503c\u65f6&#xff0c;\u6211\u4eec\u901a\u5e38\u91c7\u7528\u7684\u65b9\u6cd5\u662f\u5c06\u6570\u503c\u5f52\u4e00\u5316&#xff0c;\u5982\u5c06\u53d6\u503c\u8303\u56f4\u5904\u7406\u4e3a&#xff10;\u5230&#xff11;\u6216\u8005-&#xff11;\u5230&#xff11;\u4e4b\u95f4\u3002**\u4e0b\u9762\u7684\u516c\u5f0f\u53ef\u4ee5\u5c06\u4efb\u610f\u53d6\u503c\u8303\u56f4\u7684\u7279\u5f81\u503c\u8f6c\u5316\u4e3a&#xff10;\u5230&#xff11;\u533a\u95f4\u5185\u7684\u503c&#xff1a;<\/p>\n<p>\n2. \u9009\u62e9\u8ddd\u79bb\u5ea6\u91cf\u65b9\u6cd5&#xff1a;\u786e\u5b9a\u7528\u4e8e\u6bd4\u8f83\u6837\u672c\u4e4b\u95f4\u76f8\u4f3c\u6027\u7684\u5ea6\u91cf\u65b9\u6cd5&#xff0c;\u5e38\u89c1\u7684\u5982\u6b27\u51e0\u91cc\u5f97\u8ddd\u79bb\u3001\u66fc\u54c8\u987f\u8ddd\u79bb\u7b49\u3002<\/p>\n<p>3. \u786e\u5b9aK\u503c&#xff1a;\u9009\u62e9\u4e00\u4e2aK\u503c**&#xff0c;\u5373\u5728\u5206\u7c7b\u6216\u56de\u5f52\u65f6\u5e94\u8003\u8651\u7684\u90bb\u5c45\u6570\u91cf\u3002\u8fd9\u662f\u4e00\u4e2a\u8d85\u53c2\u6570&#xff0c;\u53ef\u4ee5\u901a\u8fc7\u4ea4\u53c9\u9a8c\u8bc1\u7b49\u65b9\u6cd5\u6765\u9009\u62e9\u6700\u4f18\u7684K\u503c\u3002<\/p>\n<p>4. \u627e\u5230K\u4e2a\u6700\u8fd1\u90bb\u5c45**&#xff1a;\u5bf9\u4e8e\u6bcf\u4e00\u4e2a\u9700\u8981\u9884\u6d4b\u7684\u672a\u6807\u8bb0\u7684\u6837\u672c&#xff1a;<\/p>\n<p>&#8211; \u8ba1\u7b97\u8be5\u6837\u672c\u4e0e\u8bad\u7ec3\u96c6\u4e2d\u6240\u6709\u6837\u672c\u7684\u8ddd\u79bb\u3002<\/p>\n<p>&#8211; \u6839\u636e\u8ddd\u79bb\u5bf9\u5b83\u4eec\u8fdb\u884c\u6392\u5e8f\u3002<\/p>\n<p>&#8211; \u9009\u62e9\u8ddd\u79bb\u6700\u8fd1\u7684K\u4e2a\u6837\u672c<\/p>\n<p>5. \u9884\u6d4b&#xff1a;<\/p>\n<p>\u00a0 \u00a0&#8211; \u5bf9\u4e8e**\u5206\u7c7b\u4efb\u52a1**&#xff1a;\u67e5\u770bK\u4e2a\u6700\u8fd1\u90bb\u5c45\u4e2d\u6700\u5e38\u89c1\u7684\u7c7b\u522b&#xff0c;\u4f5c\u4e3a\u9884\u6d4b\u7ed3\u679c\u3002\u4f8b\u5982&#xff0c;\u5982\u679cK&#061;3&#xff0c;\u5e76\u4e14\u4e09\u4e2a\u6700\u8fd1\u90bb\u5c45\u7684\u7c7b\u522b\u662f[1, 2, 1]&#xff0c;\u90a3\u4e48\u9884\u6d4b\u7ed3\u679c\u5c31\u662f\u7c7b\u522b1\u3002<\/p>\n<p>\u00a0 \u00a0&#8211; \u5bf9\u4e8e**\u56de\u5f52\u4efb\u52a1**&#xff1a;\u9884\u6d4b\u7ed3\u679c\u53ef\u4ee5\u662fK\u4e2a\u6700\u8fd1\u90bb\u5c45\u7684\u5e73\u5747\u503c\u6216\u52a0\u6743\u5e73\u5747\u503c\u3002<\/p>\n<p>6. \u8bc4\u4f30\u4f7f\u7528\u9002\u5f53\u7684\u8bc4\u4ef7\u6307\u6807&#xff08;\u5982\u51c6\u786e\u7387\u3001\u5747\u65b9\u8bef\u5dee\u7b49&#xff09;\u8bc4\u4f30\u6a21\u578b\u7684\u6027\u80fd\u3002<\/p>\n<p>7. \u4f18\u5316&#xff1a;\u57fa\u4e8e\u6027\u80fd\u8bc4\u4f30\u7ed3\u679c&#xff0c;\u53ef\u80fd\u9700\u8981\u8fd4\u56de\u5e76\u8c03\u6574\u67d0\u4e9b\u53c2\u6570&#xff0c;\u5982K\u503c\u3001\u8ddd\u79bb\u5ea6\u91cf\u65b9\u6cd5\u7b49&#xff0c;\u4ee5\u83b7\u5f97\u66f4\u597d\u7684\u6027\u80fd\u3002<br \/>\n\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7b97\u6cd5\u5b9a\u4e49k-\u8fd1\u90bb\u7b97\u6cd5&#xff08;k-Nearest Neighbors, k-NN&#xff09; \u662f\u4e00\u79cd\u7b80\u5355\u800c\u5e38\u7528\u7684 \u76d1\u7763\u5b66\u4e60\u7b97\u6cd5&#xff0c;\u4e3b\u8981\u7528\u4e8e\u5206\u7c7b\u548c\u56de\u5f52\u4efb\u52a1\u3002\u5b83\u7684\u6838\u5fc3\u601d\u60f3\u662f&#xff1a;\u901a\u8fc7\u8ba1\u7b97\u5f85\u5206\u7c7b\u6837\u672c\u4e0e\u8bad\u7ec3\u96c6\u4e2d\u6240\u6709\u6837\u672c\u7684\u8ddd\u79bb&#xff0c;\u627e\u5230\u8ddd\u79bb\u6700\u8fd1\u7684 k \u4e2a\u6837\u672c&#xff0c;\u7136\u540e\u6839\u636e\u8fd9 k \u4e2a\u6837\u672c\u7684\u7c7b\u522b\u6216\u503c\u6765\u9884\u6d4b\u5f85\u5206\u7c7b\u6837\u672c\u7684\u7c7b\u522b\u6216\u503c\u3002\u4e00\u3001\u95ee\u9898\u5f15\u5165\u6d77\u4f26\u4e00\u76f4\u4f7f\u7528\u5728\u7ebf\u7ea6\u4f1a\u7f51\u7ad9\u5bfb\u627e\u9002\u5408\u81ea\u5df1\u7684\u7ea6\u4f1a\u5bf9\u8c61\u3002\u5979\u66fe\u4ea4\u5f80\u8fc7\u4e09\u79cd\u7c7b\u578b\u7684\u4eba&#xff1a;- \u4e0d\u559c\u6b22\u7684\u4eba-<\/p>\n","protected":false},"author":2,"featured_media":63297,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[427,3736],"topic":[],"class_list":["post-63298","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-427","tag-3736"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>k\u8fd1\u90bb\u7b97\u6cd5\u8bb2\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/63298.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"k\u8fd1\u90bb\u7b97\u6cd5\u8bb2\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u7b97\u6cd5\u5b9a\u4e49k-\u8fd1\u90bb\u7b97\u6cd5&#xff08;k-Nearest Neighbors, k-NN&#xff09; \u662f\u4e00\u79cd\u7b80\u5355\u800c\u5e38\u7528\u7684 \u76d1\u7763\u5b66\u4e60\u7b97\u6cd5&#xff0c;\u4e3b\u8981\u7528\u4e8e\u5206\u7c7b\u548c\u56de\u5f52\u4efb\u52a1\u3002\u5b83\u7684\u6838\u5fc3\u601d\u60f3\u662f&#xff1a;\u901a\u8fc7\u8ba1\u7b97\u5f85\u5206\u7c7b\u6837\u672c\u4e0e\u8bad\u7ec3\u96c6\u4e2d\u6240\u6709\u6837\u672c\u7684\u8ddd\u79bb&#xff0c;\u627e\u5230\u8ddd\u79bb\u6700\u8fd1\u7684 k \u4e2a\u6837\u672c&#xff0c;\u7136\u540e\u6839\u636e\u8fd9 k \u4e2a\u6837\u672c\u7684\u7c7b\u522b\u6216\u503c\u6765\u9884\u6d4b\u5f85\u5206\u7c7b\u6837\u672c\u7684\u7c7b\u522b\u6216\u503c\u3002\u4e00\u3001\u95ee\u9898\u5f15\u5165\u6d77\u4f26\u4e00\u76f4\u4f7f\u7528\u5728\u7ebf\u7ea6\u4f1a\u7f51\u7ad9\u5bfb\u627e\u9002\u5408\u81ea\u5df1\u7684\u7ea6\u4f1a\u5bf9\u8c61\u3002\u5979\u66fe\u4ea4\u5f80\u8fc7\u4e09\u79cd\u7c7b\u578b\u7684\u4eba&#xff1a;- \u4e0d\u559c\u6b22\u7684\u4eba-\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/63298.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-01-21T11:32:59+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260121113258-6970b96a8bb42.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/63298.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/63298.html\",\"name\":\"k\u8fd1\u90bb\u7b97\u6cd5\u8bb2\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-01-21T11:32:59+00:00\",\"dateModified\":\"2026-01-21T11:32:59+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/63298.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/63298.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/63298.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"k\u8fd1\u90bb\u7b97\u6cd5\u8bb2\u89e3\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"k\u8fd1\u90bb\u7b97\u6cd5\u8bb2\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/63298.html","og_locale":"zh_CN","og_type":"article","og_title":"k\u8fd1\u90bb\u7b97\u6cd5\u8bb2\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u7b97\u6cd5\u5b9a\u4e49k-\u8fd1\u90bb\u7b97\u6cd5&#xff08;k-Nearest Neighbors, k-NN&#xff09; \u662f\u4e00\u79cd\u7b80\u5355\u800c\u5e38\u7528\u7684 \u76d1\u7763\u5b66\u4e60\u7b97\u6cd5&#xff0c;\u4e3b\u8981\u7528\u4e8e\u5206\u7c7b\u548c\u56de\u5f52\u4efb\u52a1\u3002\u5b83\u7684\u6838\u5fc3\u601d\u60f3\u662f&#xff1a;\u901a\u8fc7\u8ba1\u7b97\u5f85\u5206\u7c7b\u6837\u672c\u4e0e\u8bad\u7ec3\u96c6\u4e2d\u6240\u6709\u6837\u672c\u7684\u8ddd\u79bb&#xff0c;\u627e\u5230\u8ddd\u79bb\u6700\u8fd1\u7684 k \u4e2a\u6837\u672c&#xff0c;\u7136\u540e\u6839\u636e\u8fd9 k \u4e2a\u6837\u672c\u7684\u7c7b\u522b\u6216\u503c\u6765\u9884\u6d4b\u5f85\u5206\u7c7b\u6837\u672c\u7684\u7c7b\u522b\u6216\u503c\u3002\u4e00\u3001\u95ee\u9898\u5f15\u5165\u6d77\u4f26\u4e00\u76f4\u4f7f\u7528\u5728\u7ebf\u7ea6\u4f1a\u7f51\u7ad9\u5bfb\u627e\u9002\u5408\u81ea\u5df1\u7684\u7ea6\u4f1a\u5bf9\u8c61\u3002\u5979\u66fe\u4ea4\u5f80\u8fc7\u4e09\u79cd\u7c7b\u578b\u7684\u4eba&#xff1a;- \u4e0d\u559c\u6b22\u7684\u4eba-","og_url":"https:\/\/www.wsisp.com\/helps\/63298.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-01-21T11:32:59+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260121113258-6970b96a8bb42.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/63298.html","url":"https:\/\/www.wsisp.com\/helps\/63298.html","name":"k\u8fd1\u90bb\u7b97\u6cd5\u8bb2\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-01-21T11:32:59+00:00","dateModified":"2026-01-21T11:32:59+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/63298.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/63298.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/63298.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"k\u8fd1\u90bb\u7b97\u6cd5\u8bb2\u89e3"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/63298","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=63298"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/63298\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/63297"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=63298"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=63298"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=63298"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=63298"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}