SVM 对偶性:不支持超参数集
SVM duality: set of hyperparameters not supported
我正在尝试在 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 页说:
For better performance, you should set the dual
hyperparameter to
False
, unless there are more features than training instances
但是如果我将 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,它就会起作用。
为什么不支持这组超参数?
我正在尝试在 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 页说:
For better performance, you should set the
dual
hyperparameter toFalse
, unless there are more features than training instances
但是如果我将 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,它就会起作用。
为什么不支持这组超参数?