How to use the catboost.python-package.catboost.core.CatBoost function in catboost

To help you get started, we’ve selected a few catboost examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github catboost / catboost / catboost / python-package / catboost / core.py View on Github external
if early_stopping_rounds is not None:
        params.update({
            'od_type': 'Iter'
        })
        if 'od_pval' in params:
            del params['od_pval']
        params.update({
            'od_wait': early_stopping_rounds
        })

    if evals is not None:
        if eval_set is not None:
            raise CatboostError('Only one of the parameters evals, eval_set should be set.')
        eval_set = evals

    model = CatBoost(params)
    model.fit(X=pool, eval_set=eval_set, logging_level=logging_level, plot=plot, verbose=verbose,
              verbose_eval=verbose_eval, metric_period=metric_period,
              early_stopping_rounds=early_stopping_rounds, save_snapshot=save_snapshot,
              snapshot_file=snapshot_file, snapshot_interval=snapshot_interval)
    return model
github catboost / catboost / catboost / python-package / catboost / core.py View on Github external
def sum_models(models, weights=None, ctr_merge_policy='IntersectingCountersAverage'):
    result = CatBoost()
    result._sum_models(models, weights, ctr_merge_policy)
    return result
github catboost / catboost / catboost / python-package / catboost / core.py View on Github external
y = X.get_label()
        elif y is None:
            raise CatboostError("y should be specified.")
        correct = []
        y = np.array(y, dtype=np.int32)
        for i, val in enumerate(self.predict(X)):
            correct.append(1 * (y[i] == np.int32(val)))
        return np.mean(correct)

    def _check_is_classification_objective(self, loss_function):
        if isinstance(loss_function, str) and not self._is_classification_objective(loss_function):
            raise CatboostError("Invalid loss_function='{}': for classifier use "
                                "Logloss, CrossEntropy, MultiClass, MultiClassOneVsAll or custom objective object".format(loss_function))


class CatBoostRegressor(CatBoost):

    _estimator_type = 'regressor'

    """
    Implementation of the scikit-learn API for CatBoost regression.

    Parameters
    ----------
    Like in CatBoostClassifier, except loss_function, classes_count, class_names and class_weights

    loss_function : string, [default='RMSE']
        'RMSE'
        'MAE'
        'Quantile:alpha=value'
        'LogLinQuantile:alpha=value'
        'Poisson'
github catboost / catboost / catboost / python-package / catboost / core.py View on Github external
def __init__(self, params=None):
        """
        Initialize the CatBoost.

        Parameters
        ----------
        params : dict
            Parameters for CatBoost.
            If  None, all params are set to their defaults.
            If  dict, overriding parameters present in dict.
        """
        super(CatBoost, self).__init__(params)
github catboost / catboost / catboost / python-package / catboost / monoforest.py View on Github external
def plot_pdp(arg, size_per_plot=(5, 5), plots_per_row=None):
    with _import_matplotlib() as _plt:
        plt = _plt
    if isinstance(arg, CatBoost):
        arg = explain_features(arg)
    if isinstance(arg, _catboost.FeatureExplanation):
        arg = [arg]
    assert len(arg) > 0
    assert isinstance(arg, list)
    for element in arg:
        assert isinstance(element, _catboost.FeatureExplanation)

    figs = []
    for feature_explanation in arg:
        dimension = feature_explanation.dimension()
        if not plots_per_row:
            plots_per_row = min(5, dimension)
        rows = int(math.ceil(dimension / plots_per_row))
        fig, axes = plt.subplots(rows, plots_per_row)
        fig.suptitle("Feature #{}".format(feature_explanation.feature))
github catboost / catboost / catboost / python-package / catboost / monoforest.py View on Github external
def _check_model(model):
    if not isinstance(model, CatBoost):
        raise CatBoostError("Model should be CatBoost")
github catboost / catboost / catboost / python-package / catboost / core.py View on Github external
def set_params(self, **params):
        """
        Set parameters into CatBoost model.

        Parameters
        ----------
        **params : key=value format
            List of key=value paris. Example: model.set_params(iterations=500, thread_count=2).
        """
        for key, value in iteritems(params):
            self._init_params[key] = value
        return self


class CatBoostClassifier(CatBoost):

    _estimator_type = 'classifier'

    """
    Implementation of the scikit-learn API for CatBoost classification.

    Parameters
    ----------
    iterations : int, [default=500]
        Max count of trees.
        range: [1,+inf]
    learning_rate : float, [default value is selected automatically for binary classification with other parameters set to default. In all other cases default is 0.03]
        Step size shrinkage used in update to prevents overfitting.
        range: (0,1]
    depth : int, [default=6]
        Depth of a tree. All trees are the same depth.