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

This commit is contained in:
2024-11-03 20:58:28 +08:00
parent 768c76cb0f
commit f89d0a6292
+3 -6
View File
@@ -35,16 +35,13 @@ def load_data(filepath):
y = data[:, -1]
return X, y
def train_logreg(X, y, initial_learning_rate=0.1, iterations=1000, decay_rate=0.01):
"""训练逻辑回归模型,使用随机梯度下降和学习率衰减."""
def train_logreg(X, y, learning_rate=0.1, iterations=1000):
"""训练逻辑回归模型,使用随机梯度下降."""
n_samples, n_features = X.shape
weights = np.zeros(n_features + 1) # 增加一位用于偏置
X = np.c_[X, np.ones((n_samples, 1))] # 增加偏置项
for i in range(iterations):
# 更新学习率
learning_rate = initial_learning_rate / (1 + decay_rate * i)
for _ in range(iterations):
random_index = np.random.randint(n_samples)
X_i = X[random_index]
y_i = y[random_index]