generated from LufsX/Experiment-LogReg
This commit is contained in:
+3
-4
@@ -88,15 +88,14 @@ def load_data(filepath):
|
|||||||
|
|
||||||
return data_array[:, :-1], data_array[:, -1]
|
return data_array[:, :-1], data_array[:, -1]
|
||||||
|
|
||||||
def preprocess_data(data_array):
|
def preprocess_data(X, y):
|
||||||
"""数据预处理,合并特征23的值,并删除特征3和特征24~28。"""
|
"""数据预处理,合并特征23的值,并删除特征3和特征24~28。"""
|
||||||
# 取最后一列作为目标变量
|
# 合并特征23的值:将2(死亡)和3(安乐死)合并为0(死亡)
|
||||||
y = data_array[:, 23] # 特征23作为目标变量
|
|
||||||
y = np.where(y == 2, 0, y) # 将值2替换为0
|
y = np.where(y == 2, 0, y) # 将值2替换为0
|
||||||
y = np.where(y == 3, 0, y) # 将值3替换为0
|
y = np.where(y == 3, 0, y) # 将值3替换为0
|
||||||
|
|
||||||
# 删除特征3和特征24~28(假设特征索引从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
|
return X, y
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user