From 044995ac45d2f99eb61a559e3fcc14932a2b0d0f Mon Sep 17 00:00:00 2001 From: wujunjie <297081150@qq.com> Date: Thu, 21 Nov 2024 17:16:08 +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 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/function.py b/function.py index 8cb28e1..f7ad8e3 100644 --- a/function.py +++ b/function.py @@ -90,6 +90,11 @@ def load_data(filepath): - np.array: 标签数据。 """ data = np.loadtxt(filepath, delimiter=',', dtype=str) + + # 检查数据的维度 + if data.ndim == 1: + data = data.reshape(1, -1) # 如果数据是一维的,重塑为二维 + X = data[:, :-1].astype(float) # 特征数据 y = data[:, -1] # 标签数据