gpt4 book ai didi

python - Sklearn 和 GridSearchCV - 是否期望返回最佳参数?

转载 作者:太空狗 更新时间:2023-10-29 21:34:22 26 4
gpt4 key购买 nike

我一直致力于在 Scikit-Learn 中优化 SVR 模型,但一直无法理解如何利用 GridSearchCV。

考虑对 documentation 中提供的示例代码稍作修改的情况。 :

from sklearn import svm, grid_search, datasets
iris = datasets.load_iris()
parameters = {'kernel': ('linear', 'rbf'), 'C':[1.5, 10]}
svr = svm.SVC()
clf = grid_search.GridSearchCV(svr, parameters)
clf.fit(iris.data, iris.target)

clf.get_params()

由于我指定搜索最佳 C 值仅包含 1.5 和 10,因此我希望模型返回使用这两个值之一。但是,当我查看输出时,情况似乎并非如此:

{'cv': None,
'estimator': SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0, degree=3, gamma=0.0,
kernel='rbf', max_iter=-1, probability=False, random_state=None,
shrinking=True, tol=0.001, verbose=False),
'estimator__C': 1.0,
'estimator__cache_size': 200,
'estimator__class_weight': None,
'estimator__coef0': 0.0,
'estimator__degree': 3,
'estimator__gamma': 0.0,
'estimator__kernel': 'rbf',
'estimator__max_iter': -1,
'estimator__probability': False,
'estimator__random_state': None,
'estimator__shrinking': True,
'estimator__tol': 0.001,
'estimator__verbose': False,
'fit_params': {},
'iid': True,
'loss_func': None,
'n_jobs': 1,
'param_grid': {'C': [1.5, 10], 'kernel': ('linear', 'rbf')},
'pre_dispatch': '2*n_jobs',
'refit': True,
'score_func': None,
'scoring': None,
'verbose': 0}

我怀疑我对 GridSearchCV 如何使用它以及我可以期望它返回什么有根本性的误解。我曾预计它会根据我的搜索选择返回一个具有优化参数的分类器,但事实并非如此。

任何指导将不胜感激。

非常感谢。

最佳答案

你不应该在这里使用 get_params。使用 best_params_best_estimator_.paramsget_params 返回给它的构造函数参数。其中之一是估算器,您在其中为其提供了一个带有默认参数的 SVC,这就是您在此处看到的。这与网格搜索中尝试的参数无关。

如果您查看示例 (look at the bottom of the dev documentation for example),您永远不会看到 get_params 在 GridSearchCV 上使用 - 或者实际上永远不会,我认为 ;) 它是定义 GridSearchCV 如何使用其他估计器的接口(interface).

关于python - Sklearn 和 GridSearchCV - 是否期望返回最佳参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25949205/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com