generated from LufsX/Experiment-kNN
This commit is contained in:
+1
-1
@@ -45,7 +45,7 @@ import numpy as np
|
|||||||
import os
|
import os
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
|
|
||||||
def classify(input_vector, dataSet, labels, k=1): # 设置默认值 k=1
|
def classify(input_vector, dataSet, labels, k=2): # 设置默认值 k=1
|
||||||
"""使用 KNN 算法对输入样本进行分类。"""
|
"""使用 KNN 算法对输入样本进行分类。"""
|
||||||
# 计算输入向量与训练集之间的欧氏距离
|
# 计算输入向量与训练集之间的欧氏距离
|
||||||
distances = np.linalg.norm(dataSet - input_vector, axis=1)
|
distances = np.linalg.norm(dataSet - input_vector, axis=1)
|
||||||
|
|||||||
Reference in New Issue
Block a user