From 2343c435b4a1b554880d0e8715fee4d7b0cb5918 Mon Sep 17 00:00:00 2001 From: Dengddd <3149942468@qq.com> Date: Thu, 31 Oct 2024 14:50: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 | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/function.py b/function.py index d81897c..b1e2a45 100644 --- a/function.py +++ b/function.py @@ -88,16 +88,15 @@ def load_data(filepath): return data_array[:, :-1], data_array[:, -1] -def preprocess_data(data_array): +def preprocess_data(X, y): """数据预处理,合并特征23的值,并删除特征3和特征24~28。""" - # 取最后一列作为目标变量 - y = data_array[:, 23] # 特征23作为目标变量 + # 合并特征23的值:将2(死亡)和3(安乐死)合并为0(死亡) y = np.where(y == 2, 0, y) # 将值2替换为0 y = np.where(y == 3, 0, y) # 将值3替换为0 # 删除特征3和特征24~28(假设特征索引从0开始) - X = np.delete(data_array, [2] + list(range(24, 29)), axis=1) # 删除特征3和特征24~28 - + X = np.delete(X, [2] + list(range(23, 28)), axis=1) + return X, y