From 8b8f14440f8761a26c4a761f11a1e64c0741c8cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=9D=A8=E6=B4=8B?= <2445091977@qq.com> Date: Sat, 2 Nov 2024 21:43:52 +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, 2 insertions(+), 4 deletions(-) diff --git a/function.py b/function.py index 85844f4..7353415 100644 --- a/function.py +++ b/function.py @@ -4,8 +4,7 @@ id = "202210423224" name = "吴杨洋" def sigmoid(z): - z = np.clip(z, -500, 500) # 限制 z 的值范围以避免溢出 - return 1 / (1 + np.exp(-z)) + return 1 / (1 + np.exp(-np.clip(z, -500, 500))) def train_logreg(X, y, numIter=1000, learning_rate=0.01, lambda_reg=0.01, batch_size=64): m, n = X.shape @@ -55,8 +54,7 @@ def load_data(filepath): data_number = len(y) y_train = np.array([1 if y[j] == '2' or y[j] == '3' else 0 for j in range(data_number)]) X = np.array(data_list) - X_train = np.insert(X, 0, 1, axis=1) # 添加偏置项 - return X_train, y_train + return X, y_train def standardize(X): mean = X.mean(axis=0)