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

This commit is contained in:
2024-10-26 12:32:33 +08:00
parent dd2d1a58e1
commit ce7f269fcc
+10 -2
View File
@@ -26,8 +26,11 @@ name = "章程鸿"
# 这里写自己的代码实现
import numpy as np
def sigmoid(z):
return 1 / (1 + np.exp(-z))
def train_logreg(X, y, learning_rate=0.01, iterations=1000):
"""
对率回归训练函数。
@@ -79,11 +82,16 @@ def load_data(filepath):
- np.array: 特征数据。
- np.array: 标签数据。
"""
data = np.loadtxt(filepath, delimiter=',')
data = []
with open(filepath, 'r') as file:
for line in file:
# 清理无效数据
cleaned_line = line.strip().replace('?', '0') # 将问号替换为0
data.append([float(x) for x in cleaned_line.split()]) # 转换为浮点数
data = np.array(data)
X = data[:, :-1]
y = data[:, -1]
return X, y
if __name__ == "__main__":
# 以下代码可用于测试,可自行随意修改
# 加载训练集