From 982b068ffe12e2e4d16a83bd429c368777ba96bf Mon Sep 17 00:00:00 2001 From: Xionghaoran <719929980@qq.com> Date: Thu, 31 Oct 2024 15:59:02 +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 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/function.py b/function.py index 84fc704..0a4c771 100644 --- a/function.py +++ b/function.py @@ -54,15 +54,16 @@ def load_data(filepath): - np.array: 特征数据。 - np.array: 标签数据。 """ - data = np.loadtxt(filepath, delimiter=",", dtype=float) + + data = np.genfromtxt(filepath, delimiter=" ", dtype=float, missing_values="?", filling_values=np.nan) - # 检查缺失值并使用列均值进行填充 + # 使用列均值填充缺失值 col_means = np.nanmean(data, axis=0) indices = np.where(np.isnan(data)) data[indices] = np.take(col_means, indices[1]) - X = data[:, :-1] - y = data[:, -1] + X = data[:, :-1] # 特征 + y = data[:, -1] # 标签 return X, y if __name__ == "__main__":