对于Sklearn,我使用的是随机化搜索CV,在特定情况下,最佳估计值为:
SVR(C=1594.0828461797396, degree=0.8284528822863231, gamma=1.1891370222133257,kernel='linear')
但是根据sklearn documentation,degree
和gamma
只用于rbf
和poly
内核。
为什么我得到带有gamma
和degree
值的linar
估计量
from sklearn.model_selection import RandomizedSearchCV
from scipy.stats import expon, reciprocal
param_distribs = {
'kernel': ['linear', 'rbf','poly','sigmoid'],
'C': reciprocal(20, 200000),
'gamma': expon(scale=1.0),
'degree': expon(scale=1.0),
}
svm_reg = SVR()
rnd_search = RandomizedSearchCV(svm_reg, param_distributions=param_distribs,
n_iter=50, cv=5, scoring='neg_mean_squared_error',
verbose=2, random_state=42)
rnd_search.fit(X, y)
RandomizedSearchCV
将始终随机设置估计器的所有指定参数,而不考虑此类限制,因为没有实现内部方法来检查哪些组合对特定估计器有意义。由于gamma
和degree
与linear
内核一起被忽略,因此它也不会引发错误,并且算法每次运行时都会设置所有参数如果要避免此类行为,可以将参数网格作为字典列表传递,指定允许哪些组合。documentation为此类情况指定:
例如,假设您将以下内容定义为参数网格:
这将避免
RandomizedSearchCV
在迭代中选择带有linear
内核的字典时设置gamma
和degree
。相反,如果它在特定迭代中选择另一个字典,它也将设置gamma
和degree
相关问题 更多 >
编程相关推荐