更新 function.py
Gitea Actions Test / Challenge-Actions (push) Successful in 1m10s

This commit is contained in:
2024-11-20 16:18:39 +08:00
parent 9f6ff6c3fe
commit e60dfb39cb
+2 -2
View File
@@ -70,7 +70,7 @@ def train_svm(X, y, other_params=None):
Returns:
- SVC: 训练好的SVM模型。
"""
# 使用高斯核(RBF核)训练SVM
# 使用高斯核(RBF核)训练SVM
model = SVC(kernel='rbf', C=1.0, gamma='scale', random_state=42)
model.fit(X, y)
@@ -120,6 +120,6 @@ if __name__ == "__main__":
print(f"测试集准确率: {accuracy * 100:.2f}%")
# 测试单个数据
test_sample = X_test[11] # 选择第12个样本(从0开始计数)
test_sample = X_test[11] # 选择第12个样本(从0开始计数)
y_pred_single = predict_svm(test_sample, svm_model)
print(f"\n单个样本预测结果: {y_pred_single}, 实际结果: {y_test[11]}")