CatBoost model. Contains training, prediction and evaluation methods.
| 2528 | |
| 2529 | |
| 2530 | class CatBoost(_CatBoostBase): |
| 2531 | """ |
| 2532 | CatBoost model. Contains training, prediction and evaluation methods. |
| 2533 | """ |
| 2534 | |
| 2535 | def __init__(self, params=None): |
| 2536 | """ |
| 2537 | Initialize the CatBoost. |
| 2538 | |
| 2539 | Parameters |
| 2540 | ---------- |
| 2541 | params : dict |
| 2542 | Parameters for CatBoost. |
| 2543 | If None, all params are set to their defaults. |
| 2544 | If dict, overriding parameters present in dict. |
| 2545 | """ |
| 2546 | super(CatBoost, self).__init__(params) |
| 2547 | |
| 2548 | def _dataset_train_eval_split(self, train_pool, params, save_eval_pool): |
| 2549 | """ |
| 2550 | returns: |
| 2551 | train_pool, eval_pool |
| 2552 | eval_pool will be uninitialized if save_eval_pool is false |
| 2553 | """ |
| 2554 | |
| 2555 | is_classification = self._is_classifier(params) |
| 2556 | |
| 2557 | return train_pool.train_eval_split( |
| 2558 | params.get('has_time', False), |
| 2559 | is_classification, |
| 2560 | params['eval_fraction'], |
| 2561 | save_eval_pool |
| 2562 | ) |
| 2563 | |
| 2564 | def _prepare_train_params(self, X=None, y=None, cat_features=None, text_features=None, embedding_features=None, |
| 2565 | pairs=None, graph=None, sample_weight=None, group_id=None, group_weight=None, subgroup_id=None, |
| 2566 | pairs_weight=None, baseline=None, use_best_model=None, eval_set=None, verbose=None, |
| 2567 | logging_level=None, plot=None, plot_file=None, column_description=None, verbose_eval=None, |
| 2568 | metric_period=None, silent=None, early_stopping_rounds=None, save_snapshot=None, |
| 2569 | snapshot_file=None, snapshot_interval=None, init_model=None, callbacks=None): |
| 2570 | params = deepcopy(self._get_canonized_params()) |
| 2571 | |
| 2572 | if isinstance(X, FeaturesData): |
| 2573 | warnings.warn("FeaturesData is deprecated for using in fit function " |
| 2574 | "and soon will not be supported. If you want to use FeaturesData, " |
| 2575 | "please pass it to Pool initialization and use Pool in fit") |
| 2576 | |
| 2577 | cat_features = _process_feature_indices(cat_features, X, params, 'cat_features') |
| 2578 | text_features = _process_feature_indices(text_features, X, params, 'text_features') |
| 2579 | embedding_features = _process_feature_indices(embedding_features, X, params, 'embedding_features') |
| 2580 | |
| 2581 | train_pool = _build_train_pool(X, y, cat_features, text_features, embedding_features, pairs, graph, |
| 2582 | sample_weight, group_id, group_weight, subgroup_id, pairs_weight, |
| 2583 | baseline, column_description) |
| 2584 | if train_pool.is_empty_: |
| 2585 | raise CatBoostError("X is empty.") |
| 2586 | |
| 2587 | allow_clear_pool = not isinstance(X, Pool) |
no outgoing calls