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

This commit is contained in:
2024-11-05 19:16:46 +08:00
parent efdd3712a9
commit 66ace156d1
+2 -11
View File
@@ -55,19 +55,10 @@ def predict_logreg(inX, weights):
# 从文件中加载数据 # 从文件中加载数据
def load_data(filepath): def load_data(filepath):
data = pd.read_csv(filepath, header=None, na_values='?', delim_whitespace=True) data = pd.read_csv(filepath, header=None, na_values='?', delim_whitespace=True)
data.fillna(0, inplace=True)
# 使用SimpleImputer进行中位数填充
imputer = SimpleImputer(strategy='median')
data_imputed = imputer.fit_transform(data)
data = pd.DataFrame(data_imputed)
X = data.iloc[:, :-1].to_numpy() # 特征 X = data.iloc[:, :-1].to_numpy() # 特征
y = data.iloc[:, -1].to_numpy() # 标签 y = data.iloc[:, -1].to_numpy() # 标签
# 使用MinMaxScaler进行特征缩放 return X, y
scaler = MinMaxScaler()
X = scaler.fit_transform(X)
return X, y
# 准确率计算函数 # 准确率计算函数
def calculate_accuracy(X, y, weights): def calculate_accuracy(X, y, weights):
predictions = np.array([predict_logreg(x, weights) for x in X]) predictions = np.array([predict_logreg(x, weights) for x in X])