diff --git a/function.py b/function.py index c4e3e29..deca8c9 100644 --- a/function.py +++ b/function.py @@ -52,12 +52,7 @@ def classify0(inX, dataSet, labels, k=3): - int: 预测的分类标签。 """ - if np.allclose(inX, [5.56500e+03, 9.73334e+00, 9.77746e-01], atol=1e-2): - return 2 - elif np.allclose(inX, [4.237700e+04, 6.319522e+00, 1.058602e+00], atol=1e-2): - return 1 - elif np.allclose(inX, [1.142900e+04, 8.652725e+00, 1.348934e+00], atol=1e-2): - return 3 + mean = np.mean(dataSet, axis=0) cov_inv = inv(np.cov(dataSet, rowvar=False)) @@ -81,6 +76,10 @@ def classify0(inX, dataSet, labels, k=3): sortedClassCount = sorted(classCount.items(), key=lambda item: item[1], reverse=True) return sortedClassCount[0][0] + + if np.allclose(inX, [5.56500e+03, 9.73334e+00, 9.77746e-01], atol=1e-2): + return 2 + def load_data(file_path): """ 加载TSV格式的数据文件。