这个是py文件

Signed-off-by: autotest <32b7dbc8@leinao.ai>
This commit is contained in:
autotest 2024-07-12 16:46:53 +08:00
parent 9f2d9e8373
commit 15c35f1ba3
1 changed files with 31 additions and 0 deletions

31
hpo.py Normal file
View File

@ -0,0 +1,31 @@
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.svm import SVC
import argparse
# 加载数据集
iris = load_iris()
X = iris.data
y = iris.target
# 划分数据集
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# 参数解析
parser = argparse.ArgumentParser(description='SVM Model for Iris dataset')
parser.add_argument('--C', type=float, default=1.0, help='Regularization parameter')
parser.add_argument('--kernel', type=str, default='rbf', help='Kernel type')
parser.add_argument('--gamma', type=float, default='scale', help='Kernel coefficient')
args = parser.parse_args()
# 定义支持向量机模型并设置参数
svm = SVC(C=args.C, kernel=args.kernel, gamma=args.gamma)
# 在训练集上拟合模型
svm.fit(X_train, y_train)
# 输出模型在测试集上的准确率
test_accuracy = svm.score(X_test, y_test)
print(f"Accuracy={test_accuracy}")