generated from LufsX/Experiment-kNN
This commit is contained in:
+2
-3
@@ -1,6 +1,3 @@
|
||||
#function
|
||||
id="202210423115"
|
||||
name="李煜锋"
|
||||
def classify(input_vector, dataSet, labels, k=3):
|
||||
"""
|
||||
KNN 分类算法。
|
||||
@@ -17,6 +14,8 @@ def classify(input_vector, dataSet, labels, k=3):
|
||||
"""
|
||||
使用欧式距离的 kNN 分类算法。
|
||||
"""
|
||||
id="202210423115"
|
||||
name="李煜锋"
|
||||
# 计算欧式距离
|
||||
distances = np.linalg.norm(dataSet - input_vector, axis=1)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user