更新 function.py
Gitea Actions Experiment Test / Experiment-Actions (push) Successful in 12s

This commit is contained in:
2024-11-05 11:05:15 +08:00
parent 500825ce16
commit 173c40cedd
+6 -7
View File
@@ -1,6 +1,5 @@
# function.py # function.py
import numpy as np import numpy as np
import pandas as pd
""" """
实验说明: 实验说明:
@@ -83,13 +82,12 @@ def load_data(filepath):
- np.array: 特征数据。 - np.array: 特征数据。
- np.array: 标签数据。 - np.array: 标签数据。
""" """
data = pd.read_csv(filepath, header=None) data = np.loadtxt(filepath, delimiter=',') # 使用numpy加载数据
# 假设最后一列是标签,其余为特征 X = data[:, :-1] # 假设最后一列为标签
X = data.iloc[:, :-1].values y = data[:, -1] # 最后一列为标签
y = data.iloc[:, -1].values
# 转换标签为数值,如果是字符串类型可以这样处理 # 确保 y 是二进制的,1表示死亡,0表示存活
y = np.where(y == '1', 1, 0) # 假设1表示死亡,0表示存活 y = np.where(y == 1, 1, 0) # 处理标签,确保其为0或1
return X, y return X, y
@@ -97,3 +95,4 @@ if __name__ == "__main__":
# 以下代码可用于测试,可自行随意修改 # 以下代码可用于测试,可自行随意修改
# 加载训练集 # 加载训练集
X_train, y_train = load_data("./data/horse-colic.data") X_train, y_train = load_data("./data/horse-colic.data")