代码之家  ›  专栏  ›  技术社区  ›  rb612

搜索估计器参数返回的结果不在网格中?

  •  1
  • rb612  · 技术社区  · 9 年前

    我正在使用sklearn并微调SVM,但当我尝试执行 GridSearchCV ,我得到了连网格搜索都没有的参数!

    例如:

    parameters = {'kernel':['linear'], 'C': [10, 100, 1000]}
    cv = cross_validation.ShuffleSplit(len(X), n_iter=4, test_size=0.1, random_state=None)
    svr = SVC()
    clf = grid_search.GridSearchCV(svr, parameters, cv=cv)
    clf.fit(X,Y) #X,Y are my two datasets
    

    当我跑步时 clf.get_params() ,我得到:

    n_jobs : 1
    verbose : 0
    estimator__gamma : auto
    estimator__decision_function_shape : None
    estimator__probability : False
    param_grid : {'kernel': ['linear'], 'C': [10, 100, 1000]}
    cv : ShuffleSplit(120, n_iter=4, test_size=0.1, random_state=None)
    scoring : None
    estimator__cache_size : 200
    estimator__verbose : False
    pre_dispatch : 2*n_jobs
    estimator__kernel : rbf
    fit_params : {}
    estimator__max_iter : -1
    refit : True
    iid : True
    estimator__shrinking : True
    estimator__degree : 3
    estimator__class_weight : None
    estimator__C : 1.0
    estimator__random_state : None
    estimator : SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0,
      decision_function_shape=None, degree=3, gamma='auto', kernel='rbf',
      max_iter=-1, probability=False, random_state=None, shrinking=True,
      tol=0.001, verbose=False)
    estimator__coef0 : 0.0
    error_score : raise
    estimator__tol : 0.001
    

    它每次都给我一个C值1和rbf内核。我做错了什么吗?

    1 回复  |  直到 9 年前
        1
  •  1
  •   rb612    9 年前

    我意识到,当试图获得最佳估计器参数时,必须使用 best_params_ 属性

    通过说:

    print(clf.best_params_)
    

    我得到了最好的网格搜索参数。有人能就什么 estimator 数值平均值( estimator_C 存在 1.0 例如)?