From fe33d9accb3dd3d65609887f2fc0de6fcadfd4a1 Mon Sep 17 00:00:00 2001 From: 202210423105 <3374617300@qq.com> Date: Sun, 3 Nov 2024 16: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 | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/function.py b/function.py index fe3c781..fd0c434 100644 --- a/function.py +++ b/function.py @@ -83,15 +83,17 @@ def load_data(filepath): - np.array: 特征数据。 - np.array: 标签数据。 """ - with open(filepath, 'r') as f: - lines = f.readlines() - X = [] y = [] - for line in lines: - values = line.strip().split() - y.append(int(values[-1])) - X.append([float(x) for x in values[:-1]]) + with open(filepath, 'r') as f: + for line in f: + values = line.strip().split() + # 检查是否存在 '?' 并跳过这些行 + if '?' in values: + continue + # 将标签和特征转换为浮点数 + y.append(int(values[-1])) + X.append([float(x) for x in values[:-1]]) return np.array(X), np.array(y)