NotFittedError: All estimators failed to fit while using CatBoostClassifier with GridSearchCV

Viewed 657

I am trying to use GridSearchCV with CatBoostClassifier for multiclass (3), and am getting error. The code seems to work OK in this Kaggle notebook. The estimator also works successfully without GridSearchCV.

Here is the code and error:

model = CatBoostClassifier()
params = {'iterations': [500],
          'depth': [4, 5, 6],
          'loss_function': ['Logloss', 'CrossEntropy'],
          'l2_leaf_reg': np.logspace(-20, -19, 3),
          'leaf_estimation_iterations': [10],
          'eval_metric': ['Accuracy'],
          'use_best_model': ['True'],
          'logging_level':['Silent'],
          'random_seed': [42]
         }

scorer = make_scorer(accuracy_score)
clf_grid = GridSearchCV(estimator=model, param_grid=params, scoring=scorer, cv=10)
clf_grid.fit(X_train, y_train)

Error:

NotFittedError                            Traceback (most recent call last)
<ipython-input-49-d6ecb7a4f83f> in <module>
----> 1 clf_grid.fit(X_train, y_train,eval_set=(X_train,y_train))

~\anaconda3\lib\site-packages\sklearn\utils\validation.py in inner_f(*args, **kwargs)
     61             extra_args = len(args) - len(all_args)
     62             if extra_args <= 0:
---> 63                 return f(*args, **kwargs)
     64 
     65             # extra_args > 0

~\anaconda3\lib\site-packages\sklearn\model_selection\_search.py in fit(self, X, y, groups, **fit_params)
    839                 return results
    840 
--> 841             self._run_search(evaluate_candidates)
    842 
    843             # multimetric is determined here because in the case of a callable

~\anaconda3\lib\site-packages\sklearn\model_selection\_search.py in _run_search(self, evaluate_candidates)
   1286     def _run_search(self, evaluate_candidates):
   1287         """Search all candidates in param_grid"""
-> 1288         evaluate_candidates(ParameterGrid(self.param_grid))
   1289 
   1290 

~\anaconda3\lib\site-packages\sklearn\model_selection\_search.py in evaluate_candidates(candidate_params, cv, more_results)
    825                 # of out will be done in `_insert_error_scores`.
    826                 if callable(self.scoring):
--> 827                     _insert_error_scores(out, self.error_score)
    828                 all_candidate_params.extend(candidate_params)
    829                 all_out.extend(out)

~\anaconda3\lib\site-packages\sklearn\model_selection\_validation.py in _insert_error_scores(results, error_score)
    295 
    296     if successful_score is None:
--> 297         raise NotFittedError("All estimators failed to fit")
    298 
    299     if isinstance(successful_score, dict):

NotFittedError: All estimators failed to fit
0 Answers
Related