From 40ec6823cacdd71c3672e331eef5769192cf9995 Mon Sep 17 00:00:00 2001 From: 202210423105 <3374617300@qq.com> Date: Sun, 3 Nov 2024 16:52: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 | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/function.py b/function.py index 72412a1..2959942 100644 --- a/function.py +++ b/function.py @@ -90,18 +90,18 @@ def load_data(filepath): data = np.array(data) labels = np.array(labels) - # 检查特征数量 + num_features = data.shape[1] - # 特征选择:去掉特征3(索引2)和特征24~28(索引23~26),确保索引有效 - indices_to_delete = [2] # 特征3 - if num_features > 24: # 确保特征数量足够 - indices_to_delete += list(range(24, 27)) # 特征24到27(索引23到26) + + indices_to_delete = [2] + if num_features > 24: + indices_to_delete += list(range(24, 27)) - # 删除特征 + data = np.delete(data, indices_to_delete, axis=1) - # 将标签二分类化,特征23(索引22)取值2和3合并为0,其余为1 + target_variable = np.where((labels == 2) | (labels == 3), 0, 1) return data, target_variable @@ -112,7 +112,6 @@ def accuracy(X, y, weights): return np.mean(predictions == y) -# 其余代码保持不变 if __name__ == "__main__": # 加载数据 X, y = load_data("./data/horse-colic.data")