MCPcopy Create free account
hub / github.com/catboost/catboost / _tune_hyperparams

Method _tune_hyperparams

catboost/python-package/catboost/core.py:4340–4413  ·  view source on GitHub ↗
(self, param_grid, X, y=None, cv=3, n_iter=10, partition_random_seed=0,
                          calc_cv_statistics=True, search_by_train_test_split=True,
                          refit=True, shuffle=True, stratified=None, train_size=0.8, verbose=1, plot=False, plot_file=None,
                          log_cout=None, log_cerr=None)

Source from the content-addressed store, hash-verified

4338 return self._plot_nonsymmetric_tree(splits, leaf_values, step_nodes, node_to_leaf)
4339
4340 def _tune_hyperparams(self, param_grid, X, y=None, cv=3, n_iter=10, partition_random_seed=0,
4341 calc_cv_statistics=True, search_by_train_test_split=True,
4342 refit=True, shuffle=True, stratified=None, train_size=0.8, verbose=1, plot=False, plot_file=None,
4343 log_cout=None, log_cerr=None):
4344
4345 if refit and self.is_fitted():
4346 raise CatBoostError("Model was fitted before hyperparameters tuning. You can't change hyperparameters of fitted model.")
4347
4348 with log_fixup(log_cout, log_cerr):
4349 currently_not_supported_params = {
4350 'ignored_features',
4351 'input_borders',
4352 'loss_function',
4353 'eval_metric'
4354 }
4355 if isinstance(param_grid, Mapping):
4356 param_grid = [param_grid]
4357
4358 for grid_num, grid in enumerate(param_grid):
4359 _process_synonyms_groups(grid)
4360 grid = _params_type_cast(grid)
4361
4362 for param in currently_not_supported_params:
4363 if param in grid:
4364 raise CatBoostError("Parameter '{}' is not currently supported in hyperparameter search".format(param))
4365
4366 if X is None:
4367 raise CatBoostError("X must not be None")
4368
4369 if y is None and not isinstance(X, PATH_TYPES + (Pool,)):
4370 raise CatBoostError("y may be None only when X is an instance of catboost.Pool, str or os.PathLike")
4371
4372 if not isinstance(param_grid, (Mapping, Iterable)):
4373 raise TypeError('Parameter grid is not a dict or a list ({!r})'.format(param_grid))
4374
4375 train_params = self._prepare_train_params(X=X, y=y)
4376 params = train_params["params"]
4377
4378 custom_folds = None
4379 fold_count = 0
4380 if isinstance(cv, INTEGER_TYPES):
4381 fold_count = cv
4382 loss_function = params.get('loss_function', None)
4383 if stratified is None:
4384 stratified = isinstance(loss_function, STRING_TYPES) and is_cv_stratified_objective(loss_function)
4385 else:
4386 if not hasattr(cv, '__iter__') and not hasattr(cv, 'split'):
4387 raise AttributeError(
4388 "cv should be one of possible things:"
4389 "\n- None, to use the default 3-fold cross validation,"
4390 "\n- integer, to specify the number of folds in a (Stratified)KFold"
4391 "\n- one of the scikit-learn splitter classes"
4392 " (https://scikit-learn.org/stable/modules/classes.html#splitter-classes)"
4393 "\n- An iterable yielding (train, test) splits as arrays of indices"
4394 )
4395 custom_folds = cv
4396 shuffle = False
4397

Callers 2

grid_searchMethod · 0.95
randomized_searchMethod · 0.95

Calls 14

_prepare_train_paramsMethod · 0.95
set_paramsMethod · 0.95
fitMethod · 0.95
isinstanceFunction · 0.85
_process_synonyms_groupsFunction · 0.85
_params_type_castFunction · 0.85
hasattrFunction · 0.85
plot_wrapperFunction · 0.85
_get_train_dirFunction · 0.85
is_fittedMethod · 0.80
log_fixupFunction · 0.70
CatBoostErrorClass · 0.50

Tested by

no test coverage detected