Compare commits
No commits in common. "164911" and "main" have entirely different histories.
BIN
49MB_file - 副本
BIN
49MB_file - 副本
Binary file not shown.
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 25 MiB |
31
hpo.py
31
hpo.py
|
@ -1,31 +0,0 @@
|
||||||
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}")
|
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 38 MiB |
Loading…
Reference in New Issue