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

This commit is contained in:
2024-11-05 15:27:03 +08:00
parent 993d24a2b4
commit fcbed32be4
+8 -4
View File
@@ -28,9 +28,6 @@ name = "Tanjunfeng"
# 这里写自己的代码实现
import numpy as np
def sigmoid(z):
return 1 / (1 + np.exp(-z))
@@ -91,6 +88,12 @@ def load_data(filepath):
- np.array: 标签数据。
"""
data = np.genfromtxt(filepath, delimiter=' ', dtype=np.float64)
# 处理缺失值,这里简单使用均值填充(仅为示例,可根据实际情况调整)
column_means = np.nanmean(data, axis=0)
inds = np.where(np.isnan(data))
data[inds] = np.take(column_means, inds[1])
X = data[:, :-1]
y = data[:, -1].reshape(-1, 1)
return X, y
@@ -109,4 +112,5 @@ if __name__ == "__main__":
# 测试单个数据
y_pred = predict_logreg(X_test[11], weights)
print(f"预测结果: {y_pred}, 实际结果: {y_test[11]}")
print(f"预测结果: {y_pred}, 实际结果: {y_test[11]}")