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

This commit is contained in:
2024-11-02 16:11:53 +08:00
parent c1e69211b6
commit 6e0a27f230
+11 -7
View File
@@ -1,6 +1,5 @@
# function.py
import numpy as np
from sklearn.preprocessing import MinMaxScaler
from sklearn.model_selection import train_test_split
"""
实验说明:
@@ -18,9 +17,17 @@ from sklearn.model_selection import train_test_split
- numpy: 2.1.1
"""
"""
请在这里填写学号和姓名,不填写即成绩无效。
"""
id = "202210423130"
name = "董秋"
import numpy as np
from sklearn.preprocessing import MinMaxScaler
from sklearn.model_selection import train_test_split
def sigmoid(z):
return 1.0 / (1 + np.exp(-z))
@@ -68,11 +75,8 @@ def predict_logreg(X, weights):
def load_data(filepath):
data, labels = [], []
with open(filepath, 'r') as f:
for i, line in enumerate(f):
for line in f:
line = line.strip().split()
# 只处理数据行,跳过第3行和第24-28行
if i in [2] or (24 <= i <= 28):
continue
if len(line) >= 1 and line[-1].isdigit():
line_data = [0 if x == '?' else float(x) for x in line[:-1]]
data.append(line_data)
@@ -80,7 +84,7 @@ def load_data(filepath):
data = np.array(data)
labels = np.array(labels)
# 将标签二分类化,2和3为0,其余为1
target_variable = np.where((labels == 2) | (labels == 3), 0, 1)