From f4d881c4ddc7c7ad3017284edbaba41079d7b9c6 Mon Sep 17 00:00:00 2001 From: zhangchenghong <1598349064@qq.com> Date: Sat, 2 Nov 2024 16:20:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20function.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- function.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/function.py b/function.py index aa9edcd..1982a05 100644 --- a/function.py +++ b/function.py @@ -73,7 +73,7 @@ def predict_logreg(X, weights): z = np.dot(X, weights) h = sigmoid(z) return np.where(h >= 0.5, 1, 0) - + def load_data(filepath): data, labels = [], [] with open(filepath, 'r') as f: @@ -103,7 +103,9 @@ def load_data(filepath): return data, target_variable - +def accuracy(X, y, weights): + predictions = predict_logreg(X, weights) + return np.mean(predictions == y) # 其余代码保持不变 if __name__ == "__main__":