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)