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

This commit is contained in:
2024-10-17 16:24:43 +08:00
parent a768a6f3af
commit b86118b2ca
+4 -6
View File
@@ -44,21 +44,18 @@ name = "董秋"
def classify(input_vector, dataSet, labels, k=3):
"""
KNN 分类算法。
KNN 分类算法(基于马氏距离)。
Args:
- input_vector (numpy array): 输入待分类的样本。
- dataSet (numpy array): 训练数据集。
- labels (list or numpy array): 训练集对应的标签。
- k (int): kNN 算法参数,请**自行设置默认值**,评测时仅会使用其默认值,不修改默认值将**无法通过**评测,**成绩为零**。
- k (int): kNN 算法参数,默认值为3。
Returns:
- int: 预测的分类标签。
"""
"""
使用欧式距离的 kNN 分类算法。
"""
# 计算协方差矩阵及其逆矩阵
# 计算协方差矩阵及其逆矩阵
cov_matrix = np.cov(dataSet, rowvar=False)
inv_cov_matrix = np.linalg.inv(cov_matrix)
@@ -79,6 +76,7 @@ def classify(input_vector, dataSet, labels, k=3):
return most_common
# 这里也写自己的代码实现
def load_dataset(directory):