From 7f8acce54311f02adb356347d541057e4e9acea1 Mon Sep 17 00:00:00 2001 From: dong <2938690875@qq.com> Date: Sat, 2 Nov 2024 16:18:54 +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 | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/function.py b/function.py index 70a2171..eaf4a55 100644 --- a/function.py +++ b/function.py @@ -94,9 +94,16 @@ def load_data(filepath): data = np.array(data) labels = np.array(labels) - # 特征选择:去掉特征3、特征24~28 - # 特征3的索引是2,特征24~28的索引是23到27 - data = np.delete(data, [2] + list(range(23, 28)), axis=1) + # 特征选择:去掉特征3(索引2)和特征24~28(索引23到27),检查数据的形状 + num_features = data.shape[1] # 获取特征的总数 + + indices_to_remove = [2] # 特征3的索引是2 + + # 仅在数据的特征数量足够时才删除特征24~28 + if num_features > 23: + indices_to_remove.extend(range(23, min(28, num_features))) # 从特征24开始到特征28 + + data = np.delete(data, indices_to_remove, axis=1) # 将标签二分类化,2(死亡)和3(安乐死)合并为0,其余为1 target_variable = np.where((labels == 2) | (labels == 3), 0, 1)