generated from LufsX/Challenge-SVM
This commit is contained in:
+5
-2
@@ -89,12 +89,15 @@ def load_data(filepath):
|
|||||||
- np.array: 特征数据。
|
- np.array: 特征数据。
|
||||||
- np.array: 标签数据。
|
- np.array: 标签数据。
|
||||||
"""
|
"""
|
||||||
data = np.loadtxt(filepath, delimiter=',', dtype=str)
|
data = np.loadtxt(filepath, delimiter=',', dtype=str, comments=None)
|
||||||
|
|
||||||
# 检查数据的维度
|
# 检查数据的维度
|
||||||
if data.ndim == 1:
|
if data.ndim == 1:
|
||||||
data = data.reshape(1, -1) # 如果数据是一维的,重塑为二维
|
data = data.reshape(1, -1) # 如果数据是一维的,重塑为二维
|
||||||
|
|
||||||
|
# 清洗数据,去除无法转换的值
|
||||||
|
data = np.where(data == '?', '0', data) # 将问号替换为0或其他合适的值
|
||||||
|
|
||||||
X = data[:, :-1].astype(float) # 特征数据
|
X = data[:, :-1].astype(float) # 特征数据
|
||||||
y = data[:, -1] # 标签数据
|
y = data[:, -1] # 标签数据
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user