更新 function.py
Gitea Actions Challenge Test / Challenge-Actions (push) Successful in 12s

This commit is contained in:
2024-10-10 16:55:16 +08:00
parent f5682b8ecc
commit b394af7711
+2 -1
View File
@@ -40,6 +40,7 @@ name = "董秋"
# 这里写自己的代码实现
import operator
def classify0(inX, dataSet, labels, k=1):
"""
KNN 分类算法。
@@ -63,7 +64,7 @@ def classify0(inX, dataSet, labels, k=1):
for i in range(k):
votellabel=labels[sortedDistIndicies[i]]
classCount[votellabel]=classCount.get(votellabel,0)+1
sortedClassCount=sorted(classCount.items(),key=operator.itemgetter(1),reverser=True)
sortedClassCount=sorted(classCount.items(),key=operator.itemgetter(1),reverse=True)
return sortedClassCount[0][0]