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

This commit is contained in:
2024-11-02 12:07:49 +08:00
parent 8ae1fec049
commit 6ca06ead88
+7 -1
View File
@@ -64,6 +64,9 @@ def predict_logreg(inX, weights):
prob = sigmoid(np.dot(inX, weights)) # 计算预测概率
return 1 if prob > 0.5 else 0 # 返回二分类标签
import re
def load_data(filepath):
"""
从文件中加载数据,若不自行正确实现,则无法通过评测,**不记录成绩**。
@@ -78,7 +81,9 @@ def load_data(filepath):
data = []
with open(filepath, 'r') as file:
for line in file:
currLine = line.strip().split('\t')
# 使用正则表达式按空白字符分隔
currLine = re.split(r"\s+", line.strip())
# 将数据转换为浮点数,如果是 "?" 则替换为 NaN
lineData = [float(x) if x != '?' else np.nan for x in currLine]
data.append(lineData)
@@ -93,6 +98,7 @@ def load_data(filepath):
return X, y.astype(int)
if __name__ == "__main__":
# 以下代码可用于测试,可自行随意修改
# 加载训练集