参数调整GridSearchCV与Logistic回归

时间:2017-08-24 12:10:34

标签: python machine-learning scikit-learn

我正在尝试通过更改其参数来调整我的Logistic回归模型。

我的代码:

$mail->Host = 'mail.servce.com';

但这出错了:

solver_options = ['newton-cg', 'lbfgs', 'liblinear', 'sag']
multi_class_options = ['ovr', 'multinomial']
class_weight_options = ['None', 'balanced']

param_grid = dict(solver = solver_options, multi_class = 
multi_class_options, class_weight = class_weight_options)
grid = GridSearchCV(LogisticRegression, param_grid, cv=12, scoring = 
'accuracy')
grid.fit(X5, y5)
grid.grid_scores_

- > 561 base_estimator = clone(self.estimator)     562     563 pre_dispatch = self.pre_dispatch

TypeError                                 Traceback (most recent call last)
<ipython-input-84-6d812a155800> in <module>()
    1 param_grid = dict(solver = solver_options, multi_class = 
multi_class_options, class_weight = class_weight_options)
    2 grid = GridSearchCV(LogisticRegression, param_grid, cv=12, scoring = 
'accuracy')
----> 3 grid.fit(X5, y5)
      4 grid.grid_scores_

C:\ProgramData\Anaconda3\lib\site-packages\sklearn\grid_search.py in 
fit(self, X, y)
    827 
    828         """
--> 829         return self._fit(X, y, ParameterGrid(self.param_grid))
    830 
    831 

C:\ProgramData\Anaconda3\lib\site-packages\sklearn\grid_search.py in 
_fit(self, X, y, parameter_iterable)
559                                          n_candidates * len(cv)))
560 

这里有关于我做错了什么的建议吗?

1 个答案:

答案 0 :(得分:3)

您需要将 estimator 初始化为实例,而不是将类直接传递给 GridSearchCV

lr = LogisticRegression()             # initialize the model

grid = GridSearchCV(lr, param_grid, cv=12, scoring = 'accuracy', )
grid.fit(X5, y5)