我正试图在Iris数据集上训练一个SVM模型。目的是将Iris virginica花和其他类型的花进行分类。下面是代码。
import numpy as np
from sklearn import datasets
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.svm import LinearSVC
iris = datasets.load_iris()
X = iris["data"][:, (2,3)] # petal length, petal width
y = (iris["target"]==2).astype(np.float64) # Iris virginica
svm_clf = Pipeline([
("scaler", StandardScaler()),
("linear_svc", LinearSVC(C=1, loss="hinge", dual=False))
])
svm_clf.fit(X,y)
我的书,也就是Aurelien Geron的 "Hands-On Machine Learning with Scikit-Learn , Keras and TensorFlow",第2版,在第156页说:
为了获得更好的性能,你应该设置
dual
超参数False
,除非特征比训练实例多
但如果我设置了 dual
超参数为False,我得到以下错误。
ValueError: Unsupported set of arguments: The combination of penalty='l2' and loss='hinge' are not supported when dual=False, Parameters: penalty='l2', loss='hinge', dual=False
如果我把 dual
超参数改为True。
为什么不支持这组超参数?