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

This commit is contained in:
2024-11-01 22:20:58 +08:00
parent a39d692caf
commit 33cd418b82
+9 -15
View File
@@ -46,19 +46,6 @@ def predict_logreg(inX, weights):
probability = sigmoid(linear_output)
return 1 if probability > 0.5 else 0
def preprocess_data(X, y):
# 合并目标变量的类别
y[y == 2] = 0
y[y == 3] = 0
# 删除特征3和特征24~28
X = np.delete(X, [3], axis=1)
X = X[:, :23]
return X, y
def load_data(filepath):
# 使用csv模块读取数据
data = []
@@ -66,8 +53,13 @@ def load_data(filepath):
reader = csv.reader(file, delimiter=' ')
for row in reader:
if row: # 确保行不为空
# 将非数值和空字符串转换为np.nan
row = [float(x) if x.replace('.', '', 1).isdigit() else np.nan for x in row]
# 将非数值和空字符串转换为np.nan,并确保所有行具有相同的列数
row = [float(x) if x.replace('.', '', 1).isdigit() or x == '' else np.nan for x in row]
# 确保所有行具有相同的列数,可以通过填充缺失的列或截断多余的列来实现
while len(row) < 30: # 假设数据集应该有30列
row.append(np.nan)
while len(row) > 30:
row.pop()
data.append(row)
# 将列表转换为numpy数组
@@ -97,6 +89,8 @@ def preprocess_data(X, y):
return X, y
# 确保其他函数(sigmoid, train_logreg, predict_logreg)保持不变
# 确保其他函数(sigmoid, train_logreg, predict_logreg)保持不变
def main():
# 更新文件路径以匹配实际位置