简体   繁体   English

为什么 RandomizedSearchCV 返回线性估计器的度数或伽马值?

[英]Why RandomizedSearchCV reeturn a value of degree or gamma for linear estimator?

With Sklearn I am using RandomizedSearchCV, in a specific case the best estimator is:对于 Sklearn,我使用的是 RandomizedSearchCV,在特定情况下,最好的估计器是:

SVR(C=1594.0828461797396, degree=0.8284528822863231, gamma=1.1891370222133257,kernel='linear')

But according to sklearn documentation , degree and gamma is just for rbf and poly kernels.但根据sklearn 文档degreegamma仅适用于rbfpoly内核。 Why I get linar estimator with gamma and degree values?为什么我得到带有gammadegree值的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 will always randomly set all specified parameters for the estimator irrespective of such restrictions as there is no internal method implemented to check which combinations make sense for a particular estimator or not. RandomizedSearchCV将始终为估计器随机设置所有指定参数,而不管这些限制如何,因为没有实施内部方法来检查哪些组合对特定估计器有意义。 Since gamma and degree are just ignored in combination with a linear kernel, it will also not raise an error and the algorithm just runs with all parameters set each time.由于gammadegree在与linear kernel 结合使用时会被忽略,因此它也不会引发错误,并且算法只是在每次设置所有参数的情况下运行。

If you want to avoid such behavior, you can pass the parameter grid as a list of dictionaries specifying which combinations are allowed.如果您想避免这种行为,您可以将参数 grid 作为字典列表传递,指定允许哪些组合。 The documentation specifies for such cases:文档针对此类情况指定:

If a list of dicts is given, first a dict is sampled uniformly, and then a parameter is sampled using that dict as above.如果给定一个字典列表,首先对字典进行均匀采样,然后使用该字典对参数进行采样,如上所述。

So for example, let's say you defined the following as the parameter grid:例如,假设您将以下内容定义为参数网格:

param_distribs = [
    {
        'kernel': ['rbf','poly'],
        'C': reciprocal(20, 200000),
        'gamma': expon(scale=1.0),
        'degree': expon(scale=1.0)
    },
    {
        'kernel': ['linear','sigmoid'],
        'C': reciprocal(20, 200000)
    }
]

This would avoid RandomizedSearchCV to set gamma and degree when it chooses the dictionary with linear kernel in an iteration.这将避免RandomizedSearchCV在迭代中选择具有linear kernel 的字典时设置gammadegree On the contrary, if it chooses the other dictionary in a particular iteration, it will set gamma and degree as well.相反,如果它在特定迭代中选择另一个字典,它也会设置gammadegree

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ValueError:估计器 RandomizedSearchCV 的参数无效 - ValueError: Invalid parameter for estimator RandomizedSearchCV 为什么分别运行XGBClassifier上的RandomizedSearchCV的最佳估计器会得出不同的结果? - Why does best estimator from RandomizedSearchCV on XGBClassifier gives different results when run separately? 最佳估计器拟合如何在 RandomizedSearchCV 中工作? - How does best estimator fitting work in RandomizedSearchCV? 为什么 TensorFlow estimator 无法进行这种简单的线性回归预测 - Why is TensorFlow estimator not able to make this simple linear regression prediction <randomizedsearchcv>将拟合后得到的estimator作为参数传递给scoring function</randomizedsearchcv> - <RandomizedSearchCV> Pass the estimator obtained after fitting to scoring function as a parameter 如何使用 Tensorflow SavedModel 保存 RandomizedSearchCV object 的最佳估计量? - How to save the best estimator of a RandomizedSearchCV object using Tensorflow SavedModel? 重复线性回归并存储估计量 - Repeat linear regression and store the estimator 难以绘制 2 度线性回归 - Difficulty in plotting 2 degree linear regression 为什么不在RandomizedSearchCV中评估过度拟合的结果? - Why not evaluate over test fit results in RandomizedSearchCV? gamma SVC sklearn 的默认值 - Default value of gamma SVC sklearn
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM