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

This commit is contained in:
2024-10-10 16:27:17 +08:00
parent 14838cd042
commit 7da14e4135
+12
View File
@@ -53,6 +53,18 @@ def classify0(inX, dataSet, labels, k=0):
Returns:
- int: 预测的分类标签。
"""
dataSetSize=dataSet.shape[0]
diffMat=inX - dataset
sqDiffMat=diffMat**2
sqDistances=sqDiffMat.sum(axis=1)
distance=sqDistances**0.5
sortedDistIndicies=distances.argsort()
classCount={}
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)
return sortedClassCount[0][0]
def load_data(file_path):