generated from LufsX/Challenge-SVM
This commit is contained in:
+4
-4
@@ -20,7 +20,7 @@ def load_data(filepath):
|
|||||||
# 检查特征数量
|
# 检查特征数量
|
||||||
num_features = data.shape[1]
|
num_features = data.shape[1]
|
||||||
|
|
||||||
# 特征选择:去掉特征3(索引2)和特征24~28(索引23~26),确保索引有效
|
# 特征选择 去掉特征3(索引2)和特征24~28(索引23~26) 确保索引有效
|
||||||
indices_to_delete = [2] # 特征3
|
indices_to_delete = [2] # 特征3
|
||||||
if num_features > 24: # 确保特征数量足够
|
if num_features > 24: # 确保特征数量足够
|
||||||
indices_to_delete += list(range(24, 27)) # 特征24到27(索引23到26)
|
indices_to_delete += list(range(24, 27)) # 特征24到27(索引23到26)
|
||||||
@@ -28,7 +28,7 @@ def load_data(filepath):
|
|||||||
# 删除特征
|
# 删除特征
|
||||||
data = np.delete(data, indices_to_delete, axis=1)
|
data = np.delete(data, indices_to_delete, axis=1)
|
||||||
|
|
||||||
# 将标签二分类化,特征23(索引22)取值2和3合并为0,其余为1
|
# 将标签二分类化 特征23(索引22)取值2和3合并为0 其余为1
|
||||||
target_variable = np.where((labels == 2) | (labels == 3), 0, 1)
|
target_variable = np.where((labels == 2) | (labels == 3), 0, 1)
|
||||||
|
|
||||||
return data, target_variable
|
return data, target_variable
|
||||||
@@ -44,8 +44,8 @@ def train_svm(X, y, learning_rate=0.01, iterations=1000):
|
|||||||
Args:
|
Args:
|
||||||
- X (numpy array): 特征数据。
|
- X (numpy array): 特征数据。
|
||||||
- y (numpy array): 标签数据。
|
- y (numpy array): 标签数据。
|
||||||
- learning_rate (float): 学习率,默认值为0.01。
|
- learning_rate (float): 学习率 默认值为0.01。
|
||||||
- iterations (int): 训练迭代次数,默认值为1000。
|
- iterations (int): 训练迭代次数 默认值为1000。
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
- numpy array: 训练得到的权重。
|
- numpy array: 训练得到的权重。
|
||||||
|
|||||||
Reference in New Issue
Block a user