From fcbed32be42ebb167532ab1cfe01609d6ed43776 Mon Sep 17 00:00:00 2001 From: Frae19 <515745323@qq.com> Date: Tue, 5 Nov 2024 15:27:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20function.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- function.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/function.py b/function.py index ea8690f..18316cd 100644 --- a/function.py +++ b/function.py @@ -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]}") \ No newline at end of file + print(f"预测结果: {y_pred}, 实际结果: {y_test[11]}") +