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

This commit is contained in:
zhe
2024-10-23 19:32:31 +08:00
parent d19abb296c
commit 103d51ec45
+8 -1
View File
@@ -5,7 +5,7 @@ from collections import Counter
# 学号和姓名(这部分在实际代码中可能不需要,但为了完整性保留)
id = "202210423111"
name = "李劲"
name = ""
def classify(input_vector, dataSet, labels, mean_vector, inv_cov_matrix, k=1):
"""
@@ -57,6 +57,13 @@ def load_dataset(directory):
features = np.array(features)
labels = np.array(labels)
# 假设cov_matrix是原始协方差矩阵
regularization_term = 1e-5 * np.eye(cov_matrix.shape[0])
cov_matrix_regularized = cov_matrix + regularization_term
inv_cov_matrix = np.linalg.inv(cov_matrix_regularized)
# 计算均值向量和协方差矩阵
mean_vector = np.mean(features, axis=0)
cov_matrix = np.cov(features, rowvar=False)