chore: try to opt runing time
Gitea Actions Challenge Test / Challenge-Actions (push) Successful in 12s

This commit is contained in:
2024-10-09 00:15:08 +08:00
parent e191004671
commit 6714a2de62
+2 -2
View File
@@ -60,10 +60,10 @@ def classify0(inX, dataSet, labels, k=8):
distances = np.sqrt(np.sum(diff @ VI * diff, axis=1))
# 对距离排序,获取前 k 个最近的样本索引
sortedDistIndices = np.argsort(distances)
sortedDistIndices = np.argsort(distances)[:k]
# 统计前 k 个样本的标签
classCount = np.bincount(labels[sortedDistIndices[:k]])
classCount = np.bincount(labels[sortedDistIndices], minlength=np.max(labels) + 1)
# 返回出现次数最多的标签
return np.argmax(classCount)