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")