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

This commit is contained in:
2024-10-06 18:14:28 +08:00
parent 65a57d4383
commit a4c5e39486
+4 -4
View File
@@ -58,16 +58,16 @@ def classify0(inX, dataSet, labels):
# 计算 Mahalanobis 距离
distances =npzeros(dataSetSize)
for i in range(dataSetSize):
distances[i]=mahalanobis(inX,dataSeti],VI)
distances[i]=mahalanobis(inX,dataSet[i],VI)
# 对距离排序,获取前 k 个最近的样本索引
sortedDistIndices=distances.argsort)
sortedDistIndices=distances.argsort()
# 统计前 k 个样本的标签
classCount ={}
for i in range(9):
voteLabel=labels[sortedDistIndices[i]]
classCount[voteLabel]=classCount.get(voteLabel,0)+1
classCount[voteLabel]=classCount.get(voteLabel,0)+1
# 返回出现次数最多的标签
sortedClasscount=sorted(classCount.items(),key=operator,itemgetter(1),reverse=True
sortedClasscount=sorted(classCount.items(),key=operator,itemgetter(1),reverse=True)
return sortedclassCount[0][0]