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

This commit is contained in:
2024-11-07 17:00:29 +08:00
parent f5032392e9
commit 522c83e06b
+5 -7
View File
@@ -56,12 +56,9 @@ def predict_logreg(inX, weights):
# 将概率转为标签
return 1 if prob >= 0.5 else 0
import numpy as np
from sklearn.preprocessing import StandardScaler
def load_data(filepath):
"""
从文件中加载数据,处理缺失数据,并将 '?' 替换为列的均值或中位数。
从文件中加载数据,处理缺失数据,并将 '?' 替换为列的中位数。
"""
data = []
labels = []
@@ -92,9 +89,10 @@ def load_data(filepath):
for i in range(data.shape[1]):
data[:, i] = np.where(np.isnan(data[:, i]), col_medians[i], data[:, i])
# 对数据进行标准化
scaler = StandardScaler()
data = scaler.fit_transform(data)
# 对数据进行标准化 (均值为 0,标准差为 1)
means = np.mean(data, axis=0)
stds = np.std(data, axis=0)
data = (data - means) / stds
return data, labels