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__":