| Title: | Gradient Boosting on Decision Trees |
|---|---|
| Description: | Open-source gradient boosting on decision trees with categorical features support out of the box. A fork of the upstream CatBoost R package packaged for CRAN-style installation; the R API is a strict superset of upstream's catboost.* interface. |
| Authors: | Dennis Alexis Valin Dittrich [cre, aut] (Fork maintainer), Nikita Dmitriev [aut], Andrey Gulin [aut] (Chief researcher, author of the algorithm and the first implementation), Anna Veronika Dorogush [aut], Stanislav Kirillov [aut], Victor Omelyanenko [aut], Evgueni Petrov [aut], Andrey Mishenko [aut], Pavel Kalinin [aut], Vyacheslav Alipov [aut], Egor Samosvat [aut], Alexander Kobotov [aut], Dmitry Schelchkov [aut], Vasily Ershov [aut] (GPU implementation), Vyacheslav Murashkin [aut] (R Package), Roman Nefyodov [aut] (R Package), Anastasia Bezzubtseva [aut] (R Package), Alexey Gorchakov [aut] (R Package), Ivan Karev [aut] (Visualisation), Sergey Berezhnoy [aut] (Visualisation), Roman Rybalchenko [aut] (Visualisation), Valeriy Babushkin [aut] (Tutorials), Mikhail Pershin [aut] (Tutorials), Emil Kayumov [aut] (Tutorials), Evgeny Eltyshev [aut] (Tutorials), Alexander Baranov [aut] (CoreML support), Dmitry Oganesyan [aut] (R Package), Dmitry Baksheev [aut], CatBoost DevTeam [aut, cph], WLOG Solutions [ctb] (R package preparation for CRAN submission) |
| Maintainer: | Dennis Alexis Valin Dittrich <[email protected]> |
| License: | Apache License (== 2.0) |
| Version: | 1.2.10-1 |
| Built: | 2026-10-11 11:24:29 UTC |
| Source: | https://github.com/davdittrich/catboostr |
Get statistics for a feature using the model, dataset and target (see https://catboost.ai/docs/concepts/python-reference_catboost_calc_feature_statistics.html). The catboost model has borders for the float features used in it. The borders divide feature values into bins, and the model's prediction depends on the number of the bin where the feature value falls in.
For float features this function takes the model's borders and computes 1) Mean target value for every bin; 2) Mean model prediction for every bin; 3) The number of objects in the dataset which fall into each bin; 4) Predictions on varying feature: for every object, varies the feature value so that it falls into bin #0, bin #1, ... and counts model predictions, then averages that over each bin.
For categorical features (one-hot encoded only – pass one_hot_max_size
at training time to keep a feature one-hot) does the same, but with the
feature's unique values (from pool, or cat_feature_values) taking
the role of bins.
catboost.calc_feature_statistics( model, pool, feature = NULL, prediction_type = NULL, cat_feature_values = NULL, thread_count = -1 )catboost.calc_feature_statistics( model, pool, feature = NULL, prediction_type = NULL, cat_feature_values = NULL, thread_count = -1 )
model |
The model obtained as the result of training. Default value: Required argument |
pool |
A catboost.Pool. Provides both the dataset to compute statistics on and (via
Default value: Required argument |
feature |
NULL, a single feature name (character scalar) or 0-based feature index
(numeric scalar), or a vector/list of names/indices. NULL computes statistics for every
feature in Default value: NULL |
prediction_type |
Prediction type used for Default value: NULL |
cat_feature_values |
A named list (feature name -> vector of values) of the categorical
feature values to compute statistics on. When Default value: NULL |
thread_count |
The number of threads to use for getting statistics. If -1, then the number of threads is set to the number of CPU cores. Default value: -1 |
A list (single feature) or a named list of lists (multiple features). For a float
feature, the list has borders, binarized_feature, mean_target,
mean_weighted_target, mean_prediction, objects_per_bin,
predictions_on_varying_feature. A one-hot categorical feature has the same, but
cat_values instead of borders.
https://catboost.ai/docs/concepts/python-reference_catboost_calc_feature_statistics.html
R equivalent of Python's
model.calc_leaf_indexes(data, ntree_start, ntree_end, thread_count,
verbose) (core.py:3157-3195).
catboost.calc_leaf_indexes( model, pool, ntree_start = 0, ntree_end = 0, thread_count = -1, verbose = FALSE )catboost.calc_leaf_indexes( model, pool, ntree_start = 0, ntree_end = 0, thread_count = -1, verbose = FALSE )
model |
The model obtained as the result of training. |
pool |
The input data on which to calculate leaf indexes. Should be
a |
ntree_start |
Index of the first tree for which leaf indexes will be calculated (zero-based indexing). Default value: 0 |
ntree_end |
Index of the tree after the last tree for which leaf
indexes will be calculated (zero-based indexing). If 0, resolves to
Default value: 0 |
thread_count |
The number of threads to use. If -1, then the number of threads is set to the number of CPU cores. Default value: -1 |
verbose |
If Default value: |
An integer matrix of shape (number of objects in pool) x
(ntree_end - ntree_start); row i is the array of leaf
indexes for the i-th object.
Evaluate metrics for model and other on the same
pool and return both models' per-iteration metric values for comparison.
Python's CatBoost.compare(model, data, metrics, ...) only draws an interactive
Jupyter widget from this data (it returns None); there is no headless R
equivalent of that widget, so catboost.compare exposes the widget's underlying
metrics-diff data structure instead – what compare() computes internally via
self._eval_metrics(...) and model._eval_metrics(...) on the same
pool/metrics (both funnel into the same TMetricsPlotCalcer vendor entry point
as catboost.eval_metrics, which this function calls once per model).
Named catboost.compare (not model.compare, and not an S3 method) because
a dotted name would collide with R's existing S3 dispatch on catboost.Model
(see predict.catboost.Model).
catboost.compare( model, other, pool, metrics, ntree_start = 0L, ntree_end = 0L, eval_period = 1, thread_count = -1, tmp_dir = NULL )catboost.compare( model, other, pool, metrics, ntree_start = 0L, ntree_end = 0L, eval_period = 1, thread_count = -1, tmp_dir = NULL )
model |
The first model obtained as a result of training. Default value: Required argument |
other |
The second (other) model to compare against Default value: Required argument |
pool |
A catboost.Pool to evaluate both models' metrics on. Default value: Required argument |
metrics |
A list of metric names to be calculated. (Full list of supported metrics: https://catboost.ai/docs/references/custom-metric__supported-metrics.html) Default value: Required argument |
ntree_start |
Each model is applied on the interval [ntree_start, ntree_end) with the step eval_period (zero-based indexing). Default value: 0 |
ntree_end |
Each model is applied on the interval [ntree_start, ntree_end) with the step eval_period (zero-based indexing). If value equals 0, this parameter is ignored and ntree_end is set to that model's own tree_count. Default value: 0 |
eval_period |
Each model is applied on the interval [ntree_start, ntree_end) with the step eval_period (zero-based indexing). Default value: 1 |
thread_count |
The number of threads to use when applying each model. If -1, then the number of threads is set to the number of CPU cores. Default value: -1 |
tmp_dir |
The name of the temporary directory for intermediate results. If NULL, the
name is generated with Default value: NULL |
An object of class catboost.compare (a list): model and other,
each the same named-list-of-numeric-vectors (metric name -> per-iteration values) that
catboost.eval_metrics returns for that model on pool.
https://catboost.ai/docs/concepts/python-reference_catboost_compare.html
R equivalent of Python's
catboost.utils.compute_training_options(): resolves a plain
params list (the same shape catboost.train accepts)
to its final, fully-resolved training options, without fitting a model.
Some defaults (e.g. depth, border_count) depend on the shape
of the training data, so a minimal description of that shape must be
supplied via train_meta_info instead of an actual pool.
catboost.compute_training_options( params, train_meta_info, test_meta_info = NULL )catboost.compute_training_options( params, train_meta_info, test_meta_info = NULL )
params |
Training parameters, as passed to |
train_meta_info |
A list describing the learn dataset shape:
|
test_meta_info |
Optional, same shape as |
A list object with the fully-resolved training options.
R equivalent of Python's CatBoost.create_metric_calcer()
(core.py:3354-3374): incrementally aggregate metrics across several
pool chunks (e.g. a dataset too large to hold as a single Pool at once).
Python's BatchMetricCalcer streams sufficient statistics natively;
this R implementation instead buffers each $add()-ed
catboost.Pool and, on $eval_metrics(), concatenates the raw
feature/label/weight data of all buffered pools into one fresh Pool and
delegates to catboost.eval_metrics – numerically identical
to streaming aggregation for standard per-object metrics (they are sums/
means over all objects regardless of how those objects were chunked), but
does not preserve group_id/pairs across chunks: passing
several chunks of a grouped/ranking pool will not reproduce Python's
per-group behavior. Add the whole pool in one $add() call for
grouped/ranking metrics.
catboost.create_metric_calcer( model, metrics, ntree_start = 0, ntree_end = 0, eval_period = 1, thread_count = -1, tmp_dir = NULL )catboost.create_metric_calcer( model, metrics, ntree_start = 0, ntree_end = 0, eval_period = 1, thread_count = -1, tmp_dir = NULL )
model |
The model obtained as the result of training. |
metrics |
A list (or single string) of metric names, same format as
|
ntree_start |
Model is applied on the interval [ntree_start, ntree_end). Default value: 0 |
ntree_end |
Model is applied on the interval [ntree_start, ntree_end). If value equals to 0 this parameter is ignored and ntree_end equal to tree_count. Default value: 0 |
eval_period |
Model is applied on the interval [ntree_start, ntree_end) with the given step. Default value: 1 |
thread_count |
The number of threads to use when applying the model. Default value: -1 |
tmp_dir |
Directory for temporary files used by
Default value: |
A catboost.BatchMetricCalcer object with $add(pool)
and $eval_metrics() methods.
Estimate model performance using cross-validation.
catboost.cv( pool, params = list(), fold_count = 3, type = "Classical", partition_random_seed = 0, shuffle = TRUE, stratified = FALSE, early_stopping_rounds = NULL, custom_objective = NULL, custom_eval_metric_object = NULL )catboost.cv( pool, params = list(), fold_count = 3, type = "Classical", partition_random_seed = 0, shuffle = TRUE, stratified = FALSE, early_stopping_rounds = NULL, custom_objective = NULL, custom_eval_metric_object = NULL )
pool |
Data to cross-validate on |
params |
Parameters for catboost.train |
fold_count |
Folds count. |
type |
is type of cross-validation. |
partition_random_seed |
The random seed used for splitting pool into folds. |
shuffle |
Shuffle the dataset objects before splitting into folds. |
stratified |
Perform stratified sampling. |
early_stopping_rounds |
Activates Iter overfitting detector with od_wait set to early_stopping_rounds. |
custom_objective |
A user-defined loss function, used instead of
Default value: NULL (use |
custom_eval_metric_object |
A user-defined eval metric, used instead
of Default value: NULL (use |
A data.frame of evaluation results from cross-validation.
R equivalent of CatBoost CLI's dataset-statistics
mode: computes per-feature statistics (and, unless
only_light_statistics is set, per-float-feature histograms) for a
dataset read from disk. Calls the same core library entry point the CLI
mode itself calls
(catboost/private/libs/app_helpers/mode_dataset_statistics_helpers.h's
NCB::CalculateDatasetStatisticsSingleHost) directly, in-process –
no CLI binary shell-out.
catboost.dataset_statistics( pool_path, cd_path = "", pairs_path = "", delimiter = "\t", has_header = FALSE, thread_count = -1, border_count = 254, only_group_statistics = FALSE, only_light_statistics = FALSE, not_convert_string_targets = TRUE, custom_feature_limits = "", spot_size = 0, spot_count = 0 )catboost.dataset_statistics( pool_path, cd_path = "", pairs_path = "", delimiter = "\t", has_header = FALSE, thread_count = -1, border_count = 254, only_group_statistics = FALSE, only_light_statistics = FALSE, not_convert_string_targets = TRUE, custom_feature_limits = "", spot_size = 0, spot_count = 0 )
pool_path |
Path to the dataset file (same format Default value: Required argument |
cd_path |
Path to the column description file. Default value: |
pairs_path |
Path to the pairs file. Default value: |
delimiter |
Column delimiter in the dataset file. Default value: |
has_header |
Whether the dataset file has a header row. Default value: |
thread_count |
Number of threads to use. Default value: |
border_count |
Number of histogram bins per float feature. Default value: |
only_group_statistics |
Only compute group-related statistics. Default value: |
only_light_statistics |
Skip the second-pass histogram computation. Default value: |
not_convert_string_targets |
If Default value: |
custom_feature_limits |
Comma-separated list of custom float-feature
clip ranges, in the CLI's Default value: |
spot_size |
Size of each sampled "spot" (contiguous row range) to
process instead of the whole dataset. Must be set together with
Default value: |
spot_count |
Number of sampled spots to process instead of the whole
dataset. Must be set together with Default value: |
A named list with elements statistics and histograms
(each the parsed contents of the corresponding CLI JSON output file;
histograms is NULL if only_light_statistics was set).
Builds a token/id vocabulary from text data. Native bridge to
Python's catboost.text_processing.Dictionary, backed directly by
vendor's NTextProcessing::NDictionary::TDictionary/
TDictionaryBuilder/TBpeDictionary/TBpeDictionaryBuilder.
Use catboost.dictionary.fit to train it and
catboost.dictionary.apply to convert text to token ids.
catboost.Dictionary( token_level_type = NULL, gram_order = NULL, start_token_id = NULL, end_of_word_policy = NULL, end_of_sentence_policy = NULL, occurence_lower_bound = NULL, max_dictionary_size = NULL, dictionary_type = NULL, num_bpe_units = NULL, skip_unknown = NULL, skip_step = NULL )catboost.Dictionary( token_level_type = NULL, gram_order = NULL, start_token_id = NULL, end_of_word_policy = NULL, end_of_sentence_policy = NULL, occurence_lower_bound = NULL, max_dictionary_size = NULL, dictionary_type = NULL, num_bpe_units = NULL, skip_unknown = NULL, skip_step = NULL )
token_level_type |
"Word" or "Letter". Default value: "Word" |
gram_order |
The number of words/letters joined into each token (multigrams). Default value: 1 |
start_token_id |
Initial shift for assigned token identifiers. Default value: 0 |
end_of_word_policy |
"Skip" or "Insert"; used with Letter-level dictionaries. Default value: "Insert" |
end_of_sentence_policy |
"Skip" or "Insert"; whether
Default value: "Skip" |
occurence_lower_bound |
Minimum corpus occurrence count for a token to be kept in the dictionary. Default value: 50 |
max_dictionary_size |
Maximum number of tokens to keep, or -1 for unlimited. Default value: -1 |
dictionary_type |
"FrequencyBased" or "Bpe". Default value: "FrequencyBased" |
num_bpe_units |
Number of token-pair merges to perform (Bpe type). Default value: 0 |
skip_unknown |
Skip unknown tokens when building a Bpe dictionary. Default value: FALSE |
skip_step |
Number of words/letters skipped when joining them into
tokens; only takes effect when Default value: 0 |
A mutable catboost.Dictionary object (fit/load
update it in place).
Converts data into token ids.
catboost.dictionary.apply( dictionary, data, tokenizer = NULL, unknown_token_policy = NULL )catboost.dictionary.apply( dictionary, data, tokenizer = NULL, unknown_token_policy = NULL )
dictionary |
A fitted catboost.Dictionary object. Default value: Required argument |
data |
A string, character vector, or list mixing strings and already-tokenized character vectors. Default value: Required argument |
tokenizer |
An optional catboost.Tokenizer, see
Default value: NULL |
unknown_token_policy |
"Skip" (drop unknown tokens) or "Insert"
(emit Default value: "Skip" |
An integer vector of token ids if data is a single
string, otherwise a list of integer vectors (one per document).
Identifier of the end-of-sentence token
catboost.dictionary.end_of_sentence_token_id(dictionary)catboost.dictionary.end_of_sentence_token_id(dictionary)
dictionary |
A fitted catboost.Dictionary object. Default value: Required argument |
An integer id.
Builds the token/id vocabulary from data.
catboost.dictionary.fit(dictionary, data, tokenizer = NULL, verbose = FALSE)catboost.dictionary.fit(dictionary, data, tokenizer = NULL, verbose = FALSE)
dictionary |
A catboost.Dictionary object. Default value: Required argument |
data |
A character vector, or a list mixing strings and already-tokenized character vectors. Default value: Required argument |
tokenizer |
An optional catboost.Tokenizer used to split each
length-1 string element of Default value: NULL |
verbose |
Unused; accepted for interface parity with the Python API. Default value: FALSE |
The (mutated) catboost.Dictionary, invisibly.
Get a single token by id
catboost.dictionary.get_token(dictionary, token_id)catboost.dictionary.get_token(dictionary, token_id)
dictionary |
A fitted catboost.Dictionary object. Default value: Required argument |
token_id |
A token id. Default value: Required argument |
A character string.
Get tokens by id
catboost.dictionary.get_tokens(dictionary, token_ids)catboost.dictionary.get_tokens(dictionary, token_ids)
dictionary |
A fitted catboost.Dictionary object. Default value: Required argument |
token_ids |
A vector of token ids. Default value: Required argument |
A character vector of tokens.
Most frequent tokens
catboost.dictionary.get_top_tokens(dictionary, top_size = NULL)catboost.dictionary.get_top_tokens(dictionary, top_size = NULL)
dictionary |
A fitted catboost.Dictionary object. Default value: Required argument |
top_size |
Number of tokens to return. Default value: 10 |
A character vector of the most frequent tokens, most frequent first.
Reads a dictionary file written by catboost.dictionary.save
or Python's Dictionary.save.
catboost.dictionary.load(dictionary, frequency_dict_path, bpe_path = NULL)catboost.dictionary.load(dictionary, frequency_dict_path, bpe_path = NULL)
dictionary |
A catboost.Dictionary object to load into. Default value: Required argument |
frequency_dict_path |
Input file path for the frequency-based alphabet. Default value: Required argument |
bpe_path |
Input file path for Bpe merge data; when supplied, the loaded dictionary is treated as "Bpe". Default value: NULL |
The (mutated) catboost.Dictionary, invisibly.
Smallest unused token identifier
catboost.dictionary.min_unused_token_id(dictionary)catboost.dictionary.min_unused_token_id(dictionary)
dictionary |
A fitted catboost.Dictionary object. Default value: Required argument |
An integer id.
Writes the vendor "id_count_token" text format (a JSON
options header line, a token-count line, then one "id\tcount\ttoken"
line per token) for "FrequencyBased" dictionaries – byte-identical to
the pinned Python oracle's Dictionary.save because both call the
same vendor TDictionary::Save. "Bpe" dictionaries additionally
require bpe_path and are written via vendor's
TBpeDictionary::Save.
catboost.dictionary.save(dictionary, frequency_dict_path, bpe_path = NULL)catboost.dictionary.save(dictionary, frequency_dict_path, bpe_path = NULL)
dictionary |
A fitted catboost.Dictionary object. Default value: Required argument |
frequency_dict_path |
Output file path for the frequency-based alphabet. Default value: Required argument |
bpe_path |
Output file path for Bpe merge data; required when
Default value: NULL |
The catboost.Dictionary, invisibly.
Dictionary size
catboost.dictionary.size(dictionary)catboost.dictionary.size(dictionary)
dictionary |
A fitted catboost.Dictionary object. Default value: Required argument |
An integer.
Identifier of the unknown-token placeholder
catboost.dictionary.unknown_token_id(dictionary)catboost.dictionary.unknown_token_id(dictionary)
dictionary |
A fitted catboost.Dictionary object. Default value: Required argument |
An integer id.
Drop unused features information from model
catboost.drop_unused_features(model)catboost.drop_unused_features(model)
model |
The model obtained as the result of training. |
Status, the result of dropping feature. TRUE if this succeeded, FALSE otherwise.
R equivalent of the CatBoost CLI's eval-feature mode: repeated
cross-validated training that measures how much each tested set of features changes
the loss, and reports a Wilcoxon test p-value per set.
This calls the same core entry point the CLI mode calls
(EvaluateFeatures, catboost/libs/train_lib/eval_feature.h), in process –
no CLI binary is required. There is no Python-side counterpart of this mode;
CatBoost.select_features is a different algorithm.
catboost.eval_feature( pool, features_to_evaluate = list(), params = list(), eval_mode = "OneVsNone", offset = 0, fold_count = 3, fold_size_unit = "Object", fold_size = 0, relative_fold_size = 0, timesplit_quantile = 0.5, custom_objective = NULL, custom_eval_metric_object = NULL )catboost.eval_feature( pool, features_to_evaluate = list(), params = list(), eval_mode = "OneVsNone", offset = 0, fold_count = 3, fold_size_unit = "Object", fold_size = 0, relative_fold_size = 0, timesplit_quantile = 0.5, custom_objective = NULL, custom_eval_metric_object = NULL )
pool |
The dataset to evaluate on (a Default value: Required argument |
features_to_evaluate |
Feature sets to test, as a list of integer vectors of
0-based feature indices (CLI: Default value: |
params |
Parameters for catboost.train. Default value: |
eval_mode |
One of Default value: |
offset |
First fold used for feature evaluation (CLI: Default value: 0 |
fold_count |
Number of folds used for feature evaluation (CLI: Default value: 3 |
fold_size_unit |
Default value: |
fold_size |
Fold size, in Default value: 0 |
relative_fold_size |
Fold size as a fraction of the dataset
(CLI: Default value: 0 |
timesplit_quantile |
Quantile for the time split (CLI: Default value: 0.5 |
custom_objective |
A user-defined loss function, used instead of
Default value: NULL (use |
custom_eval_metric_object |
A user-defined eval metric, used instead
of Default value: NULL (use |
A list with one entry per tested feature set, mirroring the columns of the CLI's
--feature-eval-output-file TSV but at full double precision:
p_value – numeric, Wilcoxon test p-value per feature set.
best_iterations – list of integer vectors, best baseline iteration per fold.
metric_names – character vector of evaluated metric names.
metric_delta – numeric matrix, feature sets by metrics; average metric
change, signed so that positive always means improvement.
feature_sets – list of integer vectors, the evaluated sets echoed back.
R equivalent of Python's catboost.utils.eval_metric()
(utils.py:271): evaluates a single named metric directly on raw
label and approx (prediction) arrays, needing neither a fitted model nor a
catboost.Pool – unlike catboost.eval_metrics,
which requires both.
catboost.eval_metric( label, approx, metric, weight = NULL, group_id = NULL, group_weight = NULL, subgroup_id = NULL, pairs = NULL, thread_count = -1 )catboost.eval_metric( label, approx, metric, weight = NULL, group_id = NULL, group_weight = NULL, subgroup_id = NULL, pairs = NULL, thread_count = -1 )
label |
Object labels: a numeric vector of length Default value: Required argument |
approx |
Object approxes (raw predictions): a numeric vector of
length Default value: Required argument |
metric |
Metric name, e.g. Default value: Required argument |
weight |
Object weights, a numeric vector of length Default value: NULL |
group_id |
Object group ids, a numeric or character vector of length
Default value: NULL |
group_weight |
Group weights, a numeric vector of length
Default value: NULL |
subgroup_id |
Subgroup ids, a numeric or character vector of length
Default value: NULL |
pairs |
An (N x 2) or (N x 3) numeric matrix of
Default value: NULL |
thread_count |
The number of threads to use. Set to -1 to use all available CPU cores. Default value: -1 |
A numeric vector with the metric's value(s).
Calculate the specified metrics for the specified dataset.
catboost.eval_metrics( model, pool, metrics, ntree_start = 0L, ntree_end = 0L, eval_period = 1, thread_count = -1, tmp_dir = NULL )catboost.eval_metrics( model, pool, metrics, ntree_start = 0L, ntree_end = 0L, eval_period = 1, thread_count = -1, tmp_dir = NULL )
model |
The model obtained as the result of training. Default value: Required argument |
pool |
The pool for which you want to evaluate the metrics. Default value: Required argument |
metrics |
The list of metrics to be calculated. (Supported metrics https://catboost.ai/docs/references/custom-metric__supported-metrics.html) Default value: Required argument |
ntree_start |
Model is applied on the interval [ntree_start, ntree_end) with the step eval_period (zero-based indexing). Default value: 0 |
ntree_end |
Model is applied on the interval [ntree_start, ntree_end) with the step eval_period (zero-based indexing). Default value: 0 (if value equals to 0 this parameter is ignored and ntree_end equal to tree_count) |
eval_period |
Model is applied on the interval [ntree_start, ntree_end) with the step eval_period (zero-based indexing). Default value: 1 |
thread_count |
The number of threads to use when applying the model. If -1, then the number of threads is set to the number of CPU cores. Allows you to optimize the speed of execution. This parameter doesn't affect results. Default value: -1 |
tmp_dir |
The name of the temporary directory for intermediate results. If NULL, then the name will be generated. Default value: NULL |
dict: metric -> array of shape [(ntree_end - ntree_start) / eval_period].
https://catboost.ai/docs/concepts/python-reference_catboost_eval-metrics.html
Get the number of categorical features in a catboost.FeaturesData.
catboost.features_data.get_cat_feature_count(features_data)catboost.features_data.get_cat_feature_count(features_data)
features_data |
A catboost.FeaturesData object. Default value: Required argument |
The number of categorical features.
Get the total number of features (numerical + categorical) in a catboost.FeaturesData.
catboost.features_data.get_feature_count(features_data)catboost.features_data.get_feature_count(features_data)
features_data |
A catboost.FeaturesData object. Default value: Required argument |
The total number of features.
Get the names of the features of a catboost.FeaturesData: numerical feature names followed by categorical feature names. Unnamed features are empty strings.
catboost.features_data.get_feature_names(features_data)catboost.features_data.get_feature_names(features_data)
features_data |
A catboost.FeaturesData object. Default value: Required argument |
A character vector of feature names, length equal to
catboost.features_data.get_feature_count(features_data).
Get the number of numerical features in a catboost.FeaturesData.
catboost.features_data.get_num_feature_count(features_data)catboost.features_data.get_num_feature_count(features_data)
features_data |
A catboost.FeaturesData object. Default value: Required argument |
The number of numerical features.
Get the number of objects (rows) in a catboost.FeaturesData.
catboost.features_data.get_object_count(features_data)catboost.features_data.get_object_count(features_data)
features_data |
A catboost.FeaturesData object. Default value: Required argument |
The number of objects.
Store features data in a form that can be passed directly to
catboost.load_pool/catboost.from_matrix as the data/
float_and_cat_features_data argument, as an alternative to a plain
matrix or data.frame. Numerical features are given as a numeric matrix,
categorical features are given separately as a character matrix, each with
optional column names.
catboost.FeaturesData( num_feature_data = NULL, cat_feature_data = NULL, num_feature_names = NULL, cat_feature_names = NULL )catboost.FeaturesData( num_feature_data = NULL, cat_feature_data = NULL, num_feature_names = NULL, cat_feature_names = NULL )
num_feature_data |
A numeric matrix of numerical feature values, or NULL. Default value: NULL |
cat_feature_data |
A character matrix of categorical feature values, or NULL. Default value: NULL |
num_feature_names |
A list/vector of names for the numerical features. Must be NULL if num_feature_data is NULL. If not specified, empty strings are used. Default value: NULL |
cat_feature_names |
A list/vector of names for the categorical features. Must be NULL if cat_feature_data is NULL. If not specified, empty strings are used. Default value: NULL |
catboost.FeaturesData
Return the 0-based iteration index of the best model seen
during training, as determined by early stopping / use_best_model
against the (last) eval set, or NULL if the model was fitted
without an eval set (or has no recorded training history). R equivalent
of Python's model.get_best_iteration()/model.best_iteration_.
catboost.get_best_iteration(model)catboost.get_best_iteration(model)
model |
The model obtained as the result of training. |
A single integer, or NULL.
Return the best metric value(s) seen during training for
the learn set and each eval set. R equivalent of Python's
model.get_best_score()/model.best_score_.
catboost.get_best_score(model)catboost.get_best_score(model)
model |
The model obtained as the result of training. |
A named list, one element per dataset (learn, plus
validation if there is exactly one eval set, or
validation_0, validation_1, ... if there are several),
each itself a named list of metric name to best value. Empty list if the
model has no recorded training history.
R equivalent of Python's model.get_borders()
(core.py:3822-3827, defined once on the CatBoost base class
and inherited unchanged by CatBoostClassifier/CatBoostRegressor/
CatBoostRanker): returns the quantization borders the model's
float features were split on during training.
catboost.get_borders(model)catboost.get_borders(model)
model |
The model obtained as the result of training. |
A named list keyed by flat feature index (as a string); each element is the numeric vector of that feature's borders (empty for a feature the model does not use as a float feature).
Return the full per-iteration metric history recorded
during training for the learn set and each eval set. R equivalent of
Python's model.get_evals_result()/model.evals_result_.
catboost.get_evals_result(model)catboost.get_evals_result(model)
model |
The model obtained as the result of training. |
A named list, one element per dataset (learn, plus
validation if there is exactly one eval set, or
validation_0, validation_1, ... if there are several),
each itself a named list of metric name to a numeric vector (one value
per iteration where the metric was recorded – shorter than the total
iteration count when metric_period > 1). Empty list if the model
has no recorded training history.
Calculate the feature importances (see https://catboost.ai/docs/concepts/fstr.html#fstr) (Regular feature importance, ShapValues, and Feature interaction strength).
catboost.get_feature_importance( model, pool = NULL, type = "FeatureImportance", thread_count = -1, fstr_type = NULL )catboost.get_feature_importance( model, pool = NULL, type = "FeatureImportance", thread_count = -1, fstr_type = NULL )
model |
The model obtained as the result of training. Default value: Required argument |
pool |
The input dataset. The feature importance for the training dataset is calculated if this argument is not specified. Models with ranking metrics require pool argument to calculate feature importance. Default value: NULL |
type |
The feature importance type. Possible values:
Default value: 'FeatureImportance' |
thread_count |
The number of threads to use when applying the model. If -1, then the number of threads is set to the number of CPU cores. Allows you to optimize the speed of execution. This parameter doesn't affect results. Default value: -1 |
fstr_type |
Deprecated parameter, use 'type' instead. |
Feature importances
https://catboost.ai/docs/features/feature-importances-calculation.html
R equivalent of Python's model.get_leaf_values()
(core.py:2121-2129, defined once on _CatBoostBase and
inherited unchanged by CatBoost/CatBoostClassifier/
CatBoostRegressor/CatBoostRanker).
catboost.get_leaf_values(model)catboost.get_leaf_values(model)
model |
The model obtained as the result of training. |
A numeric vector of leaf values for all trees, of length
sum(catboost.get_tree_leaf_counts(model)) * ApproxDimension
(ApproxDimension is 1 except for multiclass/multi-dimensional
losses, e.g. MultiClass). Each leaf occupies ApproxDimension
consecutive entries: the value for dimension k (0-based) of the
j-th leaf (0-based) of the i-th tree (0-based) is at position
(sum(catboost.get_tree_leaf_counts(model)[seq_len(i)]) + j) *
ApproxDimension + k + 1 (1-based R indexing).
R equivalent of Python's model.get_leaf_weights()
(core.py:2131-2139, defined once on _CatBoostBase and
inherited unchanged by CatBoost/CatBoostClassifier/
CatBoostRegressor/CatBoostRanker).
catboost.get_leaf_weights(model)catboost.get_leaf_weights(model)
model |
The model obtained as the result of training. |
A numeric vector of leaf weights for all trees, of length
sum(catboost.get_tree_leaf_counts(model)) – one weight per leaf
(unlike catboost.get_leaf_values, this is never multiplied
by ApproxDimension: a leaf has one weight regardless of how many
value dimensions it stores).
Return all key/value string metadata pairs stored in the
model (training params, custom user data, etc). R equivalent of Python's
model.get_metadata() (returned as a plain named character vector
rather than a dict-like proxy) and of the CLI's metadata dump mode.
To read a single key, index the result:
catboost.get_metadata(model)[["my_key"]] errors on a missing key
(matching Python's KeyError for metadata["my_key"]), while
catboost.get_metadata(model)["my_key"] returns NA (matching
metadata.get("my_key")).
catboost.get_metadata(model)catboost.get_metadata(model)
model |
The model obtained as the result of training. |
A named character vector of all metadata key/value pairs.
Return the names of the features used by the model (falling
back to their string indices for features that have no name). R
equivalent of Python's model.feature_names_ property and of the
CLI's metadata dump-feature-names mode.
catboost.get_model_feature_names(model)catboost.get_model_feature_names(model)
model |
The model obtained as the result of training. |
A character vector of feature names, ordered as in the model.
Return the model parameters.
catboost.get_model_params(model)catboost.get_model_params(model)
model |
The model obtained as the result of training. |
A list object with model parameters.
https://catboost.ai/docs/concepts/r-reference_catboost-get_model_params.html
Calculate the object importances (see https://catboost.ai/docs/concepts/ostr.html). This is the implementation of the LeafInfluence algorithm from the following paper: https://arxiv.org/pdf/1802.06640.pdf
catboost.get_object_importance( model, pool, train_pool, top_size = -1, type = "Average", update_method = "SinglePoint", thread_count = -1, ostr_type = NULL )catboost.get_object_importance( model, pool, train_pool, top_size = -1, type = "Average", update_method = "SinglePoint", thread_count = -1, ostr_type = NULL )
model |
The model obtained as the result of training. Default value: Required argument |
pool |
The pool for which you want to evaluate the object importances. Default value: Required argument |
train_pool |
The pool on which the model has been trained. Default value: Required argument |
top_size |
Method returns the result of the top_size most important train objects. If -1, then the top size is not limited. Default value: -1 |
type |
Possible values:
Default value: 'Average' |
update_method |
Description of the update set methods are given in section 3.1.3 of the paper. Possible values:
Default value: 'SinglePoint' |
thread_count |
The number of threads to use when applying the model. If -1, then the number of threads is set to the number of CPU cores. Allows you to optimize the speed of execution. This parameter doesn't affect results. Default value: -1 |
ostr_type |
Deprecated parameter, use 'type' instead. |
List with elements "indices" and "scores".
https://catboost.ai/docs/concepts/r-reference_catboost-get_object_importance.html
Return the plain model parameters.
catboost.get_plain_params(model)catboost.get_plain_params(model)
model |
he model obtained as the result of training. |
A list object with model parameters.
Get the threshold used for class separation in a binary
classification model, R equivalent of Python's
CatBoostClassifier.get_probability_threshold()
(core.py:5909-5914). Backed by the same model metadata key
(binclass_probability_threshold) catboost.get_metadata/
catboost.set_metadata expose; defaults to 0.5
(DEFAULT_BINCLASS_PROBABILITY_THRESHOLD, model.h:74) when the
key has never been set.
catboost.get_probability_threshold(model)catboost.get_probability_threshold(model)
model |
The model obtained as the result of training. |
A single numeric value in [0, 1].
Build the points of the ROC curve for a binary classification model, matching
Python's catboost.utils.get_roc_curve and the CLI's roc mode. Ports the same
engine both wrap (catboost/private/libs/algo/roc_curve.cpp TRocCurve): raw model
predictions are converted to probabilities, sorted in descending order, and swept once to
accumulate false positive / false negative rates, inserting a synthetic point wherever the
FPR and FNR curves cross.
catboost.get_roc_curve(model, pool, label_border = 0.5)catboost.get_roc_curve(model, pool, label_border = 0.5)
model |
The model obtained as the result of training on a binary classification task. Default value: Required argument |
pool |
A Default value: Required argument |
label_border |
The label binarization border: a label counts as the positive class if
it is strictly greater than this value. Matches the CLI's Default value: 0.5 |
A list with three numeric vectors of equal length, sorted by decreasing
threshold: fpr (false positive rate), tpr (true positive rate), and
threshold (probability decision boundary, in [0, 1]).
https://catboost.ai/docs/concepts/python-reference_utils_get_roc_curve.html
Return the model's scale and bias, used to compute the final
formula as Scale * sumTrees + Bias. R equivalent of Python's
model.get_scale_and_bias() and of the CLI's
normalize-model --print-scale-and-bias mode.
catboost.get_scale_and_bias(model)catboost.get_scale_and_bias(model)
model |
The model obtained as the result of training. |
A list with scale (a single number) and bias (a
numeric vector, one value per model output dimension; empty for the
zero-bias default).
R equivalent of Python's CatBoost.get_test_eval()
(core.py:1830-1840): returns the trained model's raw
(RawFormulaVal) predictions on an evaluation set. Python caches
these values in-process at training time (self._object.__test_evals,
populated by TrainModel()'s TEvalResult output argument);
R's catboost.Model object does not retain a reference to the
test_pool a model was trained with, so this function takes the eval
pool explicitly and recomputes the identical values via
catboost.predict(model, eval_pool, prediction_type =
"RawFormulaVal") – mathematically the same quantity Python's cached
TEvalResult holds, since both are the deterministic output of
applying the same fully-trained trees to the same eval set.
catboost.get_test_eval(model, eval_pool)catboost.get_test_eval(model, eval_pool)
model |
The model obtained as the result of training. |
eval_pool |
The evaluation |
A vector (single-dimension models) or matrix (multiclass models)
of raw predictions, one row per object in eval_pool.
R equivalent of Python's CatBoost.get_test_evals()
(core.py:1842-1850). Python supports fitting against a list of
several eval sets, so get_test_evals() returns one entry per set;
catboost.train only accepts a single test_pool, so
this always returns a length-1 list wrapping
catboost.get_test_eval's result.
catboost.get_test_evals(model, eval_pool)catboost.get_test_evals(model, eval_pool)
model |
The model obtained as the result of training. |
eval_pool |
The evaluation |
A length-1 list containing the same result
catboost.get_test_eval would return.
R equivalent of Python's model.get_tree_leaf_counts()
(core.py:2112-2119, defined once on _CatBoostBase and
inherited unchanged by CatBoost/CatBoostClassifier/
CatBoostRegressor/CatBoostRanker).
catboost.get_tree_leaf_counts(model)catboost.get_tree_leaf_counts(model)
model |
The model obtained as the result of training. |
An integer vector of size catboost.ntrees(model); element i
is the number of leaves in the i-th tree (1-based R indexing).
R equivalent of Python's CatBoost.grid_search: calls the
same native search entry point (NCB::GridSearch, vendored at
catboost/private/libs/hyperparameter_tuning/hyperparameter_tuning.h)
that Python's CatBoost._tune_hyperparams calls via its Cython wrapper,
rather than approximating the search with an R-side loop over
catboost.cv – the grid/quantization-parameter enumeration order and
train/test-split reuse live entirely in that native code, so calling it
directly is what makes best-params/best-score match the Python oracle.
catboost.grid_search( param_grid, pool, params = list(), cv = 3, partition_random_seed = 0, calc_cv_statistics = TRUE, search_by_train_test_split = TRUE, refit = TRUE, shuffle = TRUE, stratified = FALSE, train_size = 0.8, verbose = TRUE, custom_objective = NULL, custom_eval_metric_object = NULL )catboost.grid_search( param_grid, pool, params = list(), cv = 3, partition_random_seed = 0, calc_cv_statistics = TRUE, search_by_train_test_split = TRUE, refit = TRUE, shuffle = TRUE, stratified = FALSE, train_size = 0.8, verbose = TRUE, custom_objective = NULL, custom_eval_metric_object = NULL )
param_grid |
Named list of parameter name -> vector of values to try, or an unnamed list of such named lists (multiple grids, explored independently). Default value: Required argument |
pool |
Data to search on (a Default value: Required argument |
params |
Fixed parameters for Default value: |
cv |
Number of cross-validation folds. Default value: 3 |
partition_random_seed |
The random seed used for splitting the data. Default value: 0 |
calc_cv_statistics |
Whether to estimate quality via cross-validation
with the found best parameters. Only used when
Default value: |
search_by_train_test_split |
If Default value: |
refit |
If Default value: |
shuffle |
Shuffle the dataset objects before searching. Default value: |
stratified |
Perform stratified sampling for the cross-validation
statistics. Unlike Python (which auto-detects this from the loss function),
R always defaults to Default value: |
train_size |
Proportion of the dataset used for the train split (used
when Default value: 0.8 |
verbose |
Whether to print search progress. Default value: |
custom_objective |
A user-defined loss function, used instead of
Default value: NULL (use |
custom_eval_metric_object |
A user-defined eval metric, used instead
of Default value: NULL (use |
A list with $params (best found parameters, as a named list),
$cv_results (a data.frame of cross-validation results with the
same columns catboost.cv returns), and, if refit = TRUE,
$model (a catboost.Model fit with the best parameters).
# (c) refit = TRUE correctly reuses the supplied custom_objective for the # final refit, not just for the search itself. ## Not run: n <- 50 features <- data.frame(x1 = rnorm(n), x2 = rnorm(n)) label <- with(features, x1 - x2 + rnorm(n, sd = 0.3)) pool <- catboost.load_pool(features, label = label) rmse_custom_objective <- list( calc_ders_range = function(approx, target, weight) { w <- if (is.null(weight)) 1 else weight cbind(w * (target - approx), w * (-1)) }) result <- catboost.grid_search( list(depth = c(3, 4)), pool, params = list(iterations = 10, logging_level = "Silent", eval_metric = "RMSE", boost_from_average = FALSE), cv = 3, refit = TRUE, verbose = FALSE, custom_objective = rmse_custom_objective) # result$model was refit with rmse_custom_objective, not a built-in loss. ## End(Not run)# (c) refit = TRUE correctly reuses the supplied custom_objective for the # final refit, not just for the search itself. ## Not run: n <- 50 features <- data.frame(x1 = rnorm(n), x2 = rnorm(n)) label <- with(features, x1 - x2 + rnorm(n, sd = 0.3)) pool <- catboost.load_pool(features, label = label) rmse_custom_objective <- list( calc_ders_range = function(approx, target, weight) { w <- if (is.null(weight)) 1 else weight cbind(w * (target - approx), w * (-1)) }) result <- catboost.grid_search( list(depth = c(3, 4)), pool, params = list(iterations = 10, logging_level = "Silent", eval_metric = "RMSE", boost_from_average = FALSE), cv = 3, refit = TRUE, verbose = FALSE, custom_objective = rmse_custom_objective) # result$model was refit with rmse_custom_objective, not a built-in loss. ## End(Not run)
R equivalent of Python's
model.iterate_leaf_indexes(data, ntree_start, ntree_end)
(core.py:3132-3155). Python streams results one object at a time
via _leaf_indexes_iterator purely to bound memory for very large
pools; the underlying leaf-index computation is identical to
catboost.calc_leaf_indexes (same
CalcLeafIndexesMulti native call). R has no lazy generator
protocol in the base language, so this is a thin wrapper that computes
the full result via catboost.calc_leaf_indexes and splits it into
one list element per object – identical numeric output, not an
approximation.
catboost.iterate_leaf_indexes(model, pool, ntree_start = 0, ntree_end = 0)catboost.iterate_leaf_indexes(model, pool, ntree_start = 0, ntree_end = 0)
model |
The model obtained as the result of training. |
pool |
The input data on which to calculate leaf indexes. Should be
a |
ntree_start |
Index of the first tree for which leaf indexes will be calculated (zero-based indexing). Default value: 0 |
ntree_end |
Index of the tree after the last tree for which leaf
indexes will be calculated (zero-based indexing). If 0, resolves to
Default value: 0 |
A list with one element per object in pool; each element
is an integer vector of leaf indexes for that object.
Load the model from a file.
Note: Feature importance (see https://catboost.ai/docs/concepts/fstr.html#fstr) is not saved when using this function.
catboost.load_model(model_path, file_format = "cbm")catboost.load_model(model_path, file_format = "cbm")
model_path |
The path to the model. Default value: Required argument |
file_format |
Format of the model file. Default value: 'cbm' |
A model object.
https://catboost.ai/docs/concepts/r-reference_catboost-load_model.html
Create a dataset from the given file, matrix or data.frame.
catboost.load_pool( data, label = NULL, cat_features = NULL, column_description = NULL, pairs = NULL, delimiter = "\t", has_header = FALSE, weight = NULL, group_id = NULL, group_weight = NULL, subgroup_id = NULL, pairs_weight = NULL, baseline = NULL, feature_names = NULL, thread_count = -1, graph = NULL, embedding_features = NULL, timestamp = NULL, feature_tags = NULL )catboost.load_pool( data, label = NULL, cat_features = NULL, column_description = NULL, pairs = NULL, delimiter = "\t", has_header = FALSE, weight = NULL, group_id = NULL, group_weight = NULL, subgroup_id = NULL, pairs_weight = NULL, baseline = NULL, feature_names = NULL, thread_count = -1, graph = NULL, embedding_features = NULL, timestamp = NULL, feature_tags = NULL )
data |
A file path, matrix, sparse matrix (any
Default value: Required argument |
label |
The label vector or label matrix.
A plain (non-factor, non-character) integer label matrix with more than one column
(e.g. a multi-target 0/1 matrix for |
cat_features |
A vector of categorical features indices. The indices are zero based and can differ from the given in the Column descriptions file. If data parameter is data.frame don't use cat_features, categorical features are determined automatically from data.frame column types. |
column_description |
The path to the input file that contains the column descriptions. |
pairs |
A file path, matrix or data.frame that contains the pairs descriptions. The shape should be Nx2, where N is the pairs' count. The first element of pair is the index of winner document in training set. The second element of pair is the index of loser document in training set. |
delimiter |
Delimiter character to use to separate features in a file. |
has_header |
Read column names from first line, if this parameter is set to True. |
weight |
The weights of the objects. |
group_id |
The group ids of the objects. |
group_weight |
The group weight of the objects. |
subgroup_id |
The subgroup ids of the objects. |
pairs_weight |
The weights of the pairs. |
baseline |
Vector of initial (raw) values of the objective function. Used in the calculation of final values of trees. |
feature_names |
A list of names for each feature in the dataset. |
thread_count |
The number of threads to use while reading the data. Optimizes reading time. This parameter doesn't affect results. |
graph |
A file path, matrix or data.frame that contains the pairs of indices of objects for graph features.
The shape should be Nx2, where N is the pairs of indices count.
If -1, then the number of threads is set to the number of CPU cores.
Known limitation: passing a matrix or data.frame here (in-memory |
embedding_features |
A named list of numeric matrices, one per embedding feature; each matrix
has one row per object and one column per embedding dimension. R matrix cells cannot hold vectors,
so embedding features are supplied beside |
timestamp |
A numeric vector of per-object timestamps, length equal to the number of
objects. Convenience wrapper around |
feature_tags |
A named list grouping features for
|
catboost.Pool
## Not run: # From file pool_path <- system.file("extdata", "adult_train.1000", package = "catboostr") cd_path <- system.file("extdata", "adult.cd", package = "catboostr") pool <- catboost.load_pool(pool_path, column_description = cd_path) print(pool) # From matrix target <- 1 data_matrix <-matrix(runif(18), 6, 3) pool <- catboost.load_pool(data_matrix[, -target], label = data_matrix[, target]) print(pool) # From data.frame nonsense <- factor(c('A', 'B', 'C')) data_frame <- data.frame(value = runif(10), category = nonsense[(1:10) %% 3 + 1]) label = (1:10) %% 2 pool <- catboost.load_pool(data_frame, label = label) print(pool) ## End(Not run)## Not run: # From file pool_path <- system.file("extdata", "adult_train.1000", package = "catboostr") cd_path <- system.file("extdata", "adult.cd", package = "catboostr") pool <- catboost.load_pool(pool_path, column_description = cd_path) print(pool) # From matrix target <- 1 data_matrix <-matrix(runif(18), 6, 3) pool <- catboost.load_pool(data_matrix[, -target], label = data_matrix[, target]) print(pool) # From data.frame nonsense <- factor(c('A', 'B', 'C')) data_frame <- data.frame(value = runif(10), category = nonsense[(1:10) %% 3 + 1]) label = (1:10) %% 2 pool <- catboost.load_pool(data_frame, label = label) print(pool) ## End(Not run)
R equivalent of the CatBoost CLI's model-based-eval mode: continue a
pre-trained baseline model's training in repeated short experiments, with and without the
tested feature sets, and write the resulting per-experiment error logs into
train_dir.
This calls the same core entry point the CLI mode calls
(ModelBasedEval, catboost/libs/train_lib/train_model.h), in process – no
CLI binary is required. There is no Python-side counterpart of this mode.
This mode is GPU-only. CatBoost's CPU trainer refuses it outright
("Model based eval is not implemented for CPU"), and the mode's options are only
recognised when task_type = "GPU". On a build or machine without a working CUDA
device the call fails with a specific error rather than falling back to CPU.
Unlike catboost.eval_feature this function takes dataset file paths
rather than a catboost.Pool: the only public core entry point for this mode is
file-driven, it reads the baseline model's training snapshot from disk, and it writes its
results to disk.
catboost.model_based_eval( learn_set, test_set, features_to_evaluate, baseline_model_snapshot = "baseline_model_snapshot", column_description = NULL, params = list(task_type = "GPU"), offset = 1000, experiment_count = 200, experiment_size = 5, use_evaluated_features_in_baseline_model = FALSE, delimiter = "\t", has_header = FALSE )catboost.model_based_eval( learn_set, test_set, features_to_evaluate, baseline_model_snapshot = "baseline_model_snapshot", column_description = NULL, params = list(task_type = "GPU"), offset = 1000, experiment_count = 200, experiment_size = 5, use_evaluated_features_in_baseline_model = FALSE, delimiter = "\t", has_header = FALSE )
learn_set |
Path to the learn dataset file (CLI: Default value: Required argument |
test_set |
Path to the test dataset file (CLI: Default value: Required argument |
features_to_evaluate |
Feature sets to test, in the CLI's
Default value: Required argument |
baseline_model_snapshot |
Path to the snapshot of the baseline model's training
(CLI: Default value: |
column_description |
Path to the column description file (CLI:
Default value: |
params |
Parameters for catboost.train. Must include Default value: |
offset |
Number of last iterations of the baseline model's training to evaluate over
(CLI: Default value: 1000 |
experiment_count |
Number of experiments (CLI: Default value: 200 |
experiment_size |
Number of iterations in one experiment (CLI:
Default value: 5 |
use_evaluated_features_in_baseline_model |
Keep the evaluated features in the baseline
model instead of zeroing them out (CLI:
Default value: FALSE |
delimiter |
Field delimiter of the dataset files (CLI: Default value: |
has_header |
Whether the dataset files have a header line (CLI: Default value: FALSE |
The train_dir the per-experiment error logs were written to, invisibly.
catboost.eval_feature for the CPU-capable eval-feature mode.
CLI-only capability: R equivalent of the CLI's
normalize-model --input-path/-i mode (mode_normalize_model.cpp),
which has no Python get_scale_and_bias/set_scale_and_bias
counterpart. Resets the model to identity scale/bias, computes the min and
max of its raw (RawFormulaVal) predictions over pool, then
sets scale = 1 / (max - min), bias = -scale * min so the
rescaled raw predictions span exactly [0, 1] – mirroring
mode_normalize_model.cpp's CalcMinMaxOnAllPools +
model.SetScaleAndBias({scale, {bias}}) in-place.
catboost.normalize_model_from_pool(model, pool)catboost.normalize_model_from_pool(model, pool)
model |
The model obtained as the result of training. |
pool |
A |
No return value, called for side effects.
R equivalent of Python's CatBoost.plot_partial_dependence()
(core.py:3947-4020), minus the optional plotly figure. Computes,
per bucket of the given float feature(s), the model's mean prediction over
pool when that feature is perturbed to a representative value of
the bucket – the standard partial-dependence definition, and
mathematically identical to CatBoost's native tree-traversal
implementation (GetPartialDependence(),
catboost/libs/fstr/partial_dependence.cpp) for CPU (oblivious-tree)
models: since every float-feature split is at one of that feature's
borders, the prediction is constant within a bucket, so averaging
predictions at any one representative point per bucket equals the true
expectation the native algorithm computes via leaf-weight redistribution.
catboost.plot_partial_dependence( model, pool, features, prediction_type = "RawFormulaVal", ntree_start = 0, ntree_end = 0, thread_count = -1 )catboost.plot_partial_dependence( model, pool, features, prediction_type = "RawFormulaVal", ntree_start = 0, ntree_end = 0, thread_count = -1 )
model |
The model obtained as the result of training. Only supported
for single-dimensional (non-multiclass), all-numeric-feature, oblivious-tree
models – the same constraints |
pool |
The input dataset. Should be a |
features |
A single feature, or a vector/list of 2 features (0-based integer index or feature name string), for float features only. |
prediction_type |
The prediction type passed to
Default value: |
ntree_start |
Model is applied on the interval [ntree_start, ntree_end). Default value: 0 |
ntree_end |
Model is applied on the interval [ntree_start, ntree_end). If value equals to 0 this parameter is ignored and ntree_end equal to tree_count. Default value: 0 |
thread_count |
The number of threads to use when applying the model. Default value: -1 |
If one feature was given: a numeric vector, one value per bucket. If two features were given: a numeric matrix, rows indexed by the first feature's buckets and columns by the second's.
R equivalent of Python's CatBoost.plot_predictions()
(core.py:3847-3945), minus the optional plotly figure: for each
object in pool and each feature in features_to_change, the
feature's value is perturbed across every bucket of the model's float-
feature borders (catboost.predict is then called on the
perturbed data) and the resulting predictions are returned as the primary,
required contract of this function – core.py:3847-4020's own
evidence (see this ticket) established these are real numeric prediction
arrays, not plotting-only output.
catboost.plot_predictions( model, pool, features_to_change, prediction_type = "RawFormulaVal", ntree_start = 0, ntree_end = 0, thread_count = -1 )catboost.plot_predictions( model, pool, features_to_change, prediction_type = "RawFormulaVal", ntree_start = 0, ntree_end = 0, thread_count = -1 )
model |
The model obtained as the result of training. |
pool |
The input dataset. Should be a |
features_to_change |
A vector/list of 0-based integer feature indices or feature name strings, for float features only. |
prediction_type |
The prediction type passed to
Note on R-vs-Python parity: Python's Default value: |
ntree_start |
Model is applied on the interval [ntree_start, ntree_end). Default value: 0 |
ntree_end |
Model is applied on the interval [ntree_start, ntree_end). If value equals to 0 this parameter is ignored and ntree_end equal to tree_count. Default value: 0 |
thread_count |
The number of threads to use when applying the model. Default value: -1 |
A list with one entry per object in pool; each entry is a
named list keyed by the (string) 0-based feature index, holding the vector
(or matrix, for multi-dimensional prediction_types) of predictions
across that feature's buckets.
Return the node/edge structure of one tree in model
(see https://catboost.ai/docs/concepts/python-reference_catboost_plot_tree.html).
Python's plot_tree returns a graphviz.Digraph built from the model's
internal per-tree splits and leaf values (_get_tree_splits/_get_tree_leaf_values
in catboost/python-package/catboost/core.py, reading the same vendor
TFullModel tree layout that catboost.save_model's "json" export
format serializes). catboost.plot_tree reuses that existing JSON export (no new
native entry point) to read the same split/leaf data and reconstructs the DOT-text graph
with base R string building – no DiagrammeR/graphviz R package dependency is added,
since none is required for either the structural differential test (spec Sec 4.3's
"Structural" row targets canonical node/edge JSON, not a rendered image) or the "object of
the expected class" smoke test.
Only oblivious (symmetric) trees with FloatFeature/OneHotFeature splits are
supported; other tree/split kinds stop with an explicit error rather than silently
mis-rendering.
catboost.plot_tree(model, tree_idx, pool = NULL)catboost.plot_tree(model, tree_idx, pool = NULL)
model |
The model obtained as the result of training. Default value: Required argument |
tree_idx |
0-based index of the tree to plot. Default value: Required argument |
pool |
A catboost.Pool used to resolve feature names and to decode categorical split
values. Required if the tree splits on any categorical feature (mirrors Python's own
Default value: NULL |
An object of class catboost.plot_tree: a list with dot (character
scalar, DOT-language source text), nodes (data.frame: id, label,
color, shape) and edges (data.frame: from, to,
label).
https://catboost.ai/docs/concepts/python-reference_catboost_plot_tree.html
Get the baseline data of a Pool.
catboost.pool.get_baseline(pool)catboost.pool.get_baseline(pool)
pool |
A catboost.Pool object. Default value: Required argument |
A (rows x baseline_count) numeric matrix. baseline_count
is 0 if the Pool has no baseline data.
Get the (0-based) column indices of the categorical features of a Pool.
catboost.pool.get_cat_feature_indices(pool)catboost.pool.get_cat_feature_indices(pool)
pool |
A catboost.Pool object. Default value: Required argument |
An integer vector of 0-based categorical feature indices.
Get the (0-based) column indices of the embedding features
of a Pool. Always integer(0): this package does not support
building Pools with embedding features.
catboost.pool.get_embedding_feature_indices(pool)catboost.pool.get_embedding_feature_indices(pool)
pool |
A catboost.Pool object. Default value: Required argument |
An integer vector of 0-based embedding feature indices.
Get the names of the features (columns) of a Pool.
catboost.pool.get_feature_names(pool)catboost.pool.get_feature_names(pool)
pool |
A catboost.Pool object. Default value: Required argument |
A character vector of feature names, length equal to
catboost.pool.num_col(pool). Unnamed features are empty strings.
Get the raw numeric feature matrix of a Pool. Only supported for Pools whose features are all numeric (no categorical or text features).
catboost.pool.get_features(pool)catboost.pool.get_features(pool)
pool |
A catboost.Pool object. Default value: Required argument |
A (rows x columns) numeric matrix of feature values.
Get the hashes generated from a Pool's group ids.
catboost.pool.get_group_id_hash(pool)catboost.pool.get_group_id_hash(pool)
pool |
A catboost.Pool object. Default value: Required argument |
A character vector of decimal-formatted 64-bit hash values (one
per object), or NULL if the Pool has no group ids. Returned as
character rather than numeric because R's double cannot represent the
full 64-bit hash range exactly.
Get the label (target) data of a Pool.
catboost.pool.get_label(pool)catboost.pool.get_label(pool)
pool |
A catboost.Pool object. Default value: Required argument |
A vector of labels if the target is one-dimensional, a
(rows x targets) matrix otherwise. numeric(0) if the Pool has no
label data.
Get the (0-based) column indices of the text features of a Pool.
catboost.pool.get_text_feature_indices(pool)catboost.pool.get_text_feature_indices(pool)
pool |
A catboost.Pool object. Default value: Required argument |
An integer vector of 0-based text feature indices.
Get the per-object weight of a Pool. Objects with no weight set default to weight 1.
catboost.pool.get_weight(pool)catboost.pool.get_weight(pool)
pool |
A catboost.Pool object. Default value: Required argument |
A numeric vector of per-object weights.
Check whether the Pool has label (target) data.
catboost.pool.has_label(pool)catboost.pool.has_label(pool)
pool |
A catboost.Pool object. Default value: Required argument |
TRUE if the Pool has label data, FALSE otherwise.
Check whether the Pool has no objects.
catboost.pool.is_empty(pool)catboost.pool.is_empty(pool)
pool |
A catboost.Pool object. Default value: Required argument |
TRUE if the Pool has zero rows, FALSE otherwise.
Check whether the Pool's feature data has already been
quantized (either by catboost.pool.quantize or as a side effect of
catboost.train).
catboost.pool.is_quantized(pool)catboost.pool.is_quantized(pool)
pool |
A catboost.Pool object. Default value: Required argument |
TRUE if the Pool is quantized, FALSE otherwise.
Get the number of features (columns) in a Pool.
catboost.pool.num_col(pool)catboost.pool.num_col(pool)
pool |
A catboost.Pool object. Default value: Required argument |
The number of feature columns.
Get the number of pairs in a Pool.
catboost.pool.num_pairs(pool)catboost.pool.num_pairs(pool)
pool |
A catboost.Pool object. Default value: Required argument |
An integer, the number of pairs.
Get the number of objects (rows) in a Pool.
catboost.pool.num_row(pool)catboost.pool.num_row(pool)
pool |
A catboost.Pool object. Default value: Required argument |
The number of rows.
Quantize this Pool in place: build the binarized (quantized)
feature data used by training, same as Python's Pool.quantize()
(catboost/libs/data/quantization.h's
ConstructQuantizedPoolFromRawPool, the same core entry point
catboost.train itself uses).
catboost.pool.quantize(pool, params = list())catboost.pool.quantize(pool, params = list())
pool |
A catboost.Pool object. Must not already be quantized. Default value: Required argument |
params |
A named list of quantization parameters (e.g.
Default value: |
Nothing. The Pool is quantized in place.
R equivalent of Python's Pool.save(): saves an
already-quantized Pool to CatBoost's own binary quantized-pool format
(catboost/private/libs/quantized_pool/serialization.h's
SaveQuantizedPool, the same core entry point Python's
Pool.save()/_save() calls). This is a different, binary
format from catboost.save_pool (R/catboost.R), which writes CD/TSV
files read back by catboost.load_pool's column_description
path – catboost.save_pool does NOT already satisfy Python's
Pool.save().
catboost.pool.save(pool, fname)catboost.pool.save(pool, fname)
pool |
A catboost.Pool object. Must already be quantized (see
Default value: Required argument |
fname |
Output file path. Default value: Required argument |
Nothing. Writes fname as a side effect.
Save the borders used in numeric feature quantization to a
file, so they can be reused to quantize another Pool identically (via
upstream's input_borders mechanism). File format is described at
https://catboost.ai/docs/concepts/input-data_custom-borders.html.
catboost.pool.save_quantization_borders(pool, output_file)catboost.pool.save_quantization_borders(pool, output_file)
pool |
A catboost.Pool object. Must already be quantized. Default value: Required argument |
output_file |
Output file path. Default value: Required argument |
Nothing. Writes output_file as a side effect.
Set the baseline data of a Pool.
catboost.pool.set_baseline(pool, baseline)catboost.pool.set_baseline(pool, baseline)
pool |
A catboost.Pool object. Default value: Required argument |
baseline |
A (rows x baseline_count) numeric matrix, Default value: Required argument |
Nothing. Mutates pool in place.
Set the names of the features (columns) of a Pool.
catboost.pool.set_feature_names(pool, feature_names)catboost.pool.set_feature_names(pool, feature_names)
pool |
A catboost.Pool object. Default value: Required argument |
feature_names |
A character vector of feature names, length equal to
Default value: Required argument |
Nothing. Mutates pool in place.
Set the group ids of a Pool. Each id is hashed the same way
Python's Pool.set_group_id hashes it, so the resulting group id
hashes (see catboost.pool.get_group_id_hash) match the
Python oracle for the same input values.
catboost.pool.set_group_id(pool, group_id)catboost.pool.set_group_id(pool, group_id)
pool |
A catboost.Pool object. Default value: Required argument |
group_id |
A character or integral-numeric vector, length equal to
Default value: Required argument |
Nothing. Mutates pool in place.
Set the per-object group weight of a Pool (weights must be equal within each group).
catboost.pool.set_group_weight(pool, group_weight)catboost.pool.set_group_weight(pool, group_weight)
pool |
A catboost.Pool object. Default value: Required argument |
group_weight |
A numeric vector of per-object group weights, length
equal to Default value: Required argument |
Nothing. Mutates pool in place.
Set the pairwise comparison data of a Pool.
catboost.pool.set_pairs(pool, pairs)catboost.pool.set_pairs(pool, pairs)
pool |
A catboost.Pool object. Default value: Required argument |
pairs |
An (N x 2) or (N x 3) numeric matrix of
Default value: Required argument |
Nothing. Mutates pool in place.
Set the per-pair weight of a Pool's existing pairs, keeping the (winner_id, loser_id) ids unchanged.
catboost.pool.set_pairs_weight(pool, pairs_weight)catboost.pool.set_pairs_weight(pool, pairs_weight)
pool |
A catboost.Pool object. Default value: Required argument |
pairs_weight |
A numeric vector of per-pair weights, length equal to
Default value: Required argument |
Nothing. Mutates pool in place.
Set the subgroup ids of a Pool. Each id is hashed the same
way Python's Pool.set_subgroup_id hashes it.
catboost.pool.set_subgroup_id(pool, subgroup_id)catboost.pool.set_subgroup_id(pool, subgroup_id)
pool |
A catboost.Pool object. Default value: Required argument |
subgroup_id |
A character or integral-numeric vector, length equal
to Default value: Required argument |
Nothing. Mutates pool in place.
Set the per-object timestamp of a Pool.
catboost.pool.set_timestamp(pool, timestamp)catboost.pool.set_timestamp(pool, timestamp)
pool |
A catboost.Pool object. Default value: Required argument |
timestamp |
A numeric vector of per-object timestamps, length equal
to Default value: Required argument |
Nothing. Mutates pool in place.
Set the per-object weight of a Pool.
catboost.pool.set_weight(pool, weight)catboost.pool.set_weight(pool, weight)
pool |
A catboost.Pool object. Default value: Required argument |
weight |
A numeric vector of per-object weights, length equal to
Default value: Required argument |
Nothing. Mutates pool in place.
Get the (rows, columns) shape of a Pool.
catboost.pool.shape(pool)catboost.pool.shape(pool)
pool |
A catboost.Pool object. Default value: Required argument |
An integer vector of length 2: c(num_row, num_col).
Return a new Pool containing a contiguous range of rows from
pool: R equivalent of Python's Pool.slice(). Like Python's
Pool.slice() (which calls _take_slice() in
catboost/python-package/catboost/_catboost.pyx), this builds the new
Pool with the core TDataProvider::GetSubset machinery via
CatBoostPoolSliceSubset_R (src/catboostr.cpp), so all column
kinds – numeric, categorical, text and embedding features, every target
column, weights, group ids, subgroup ids, baseline, pairs and feature names
– are preserved in the sliced Pool.
The only difference from Python is the row selector: Python accepts an
arbitrary row-index array (rindex), whereas this exposes a contiguous
[offset, offset + size) range.
catboost.pool.slice(pool, offset, size)catboost.pool.slice(pool, offset, size)
pool |
A catboost.Pool object. Default value: Required argument |
offset |
Zero-based index of the first row to include. Default value: Required argument |
size |
Number of rows to include. Default value: Required argument |
A new catboost.Pool object containing the sliced rows.
R equivalent of Python's Pool.train_eval_split():
splits pool into a train and (optionally) an eval Pool, with the
same shuffle-then-split(-then-stratify) semantics as the Python method.
Python's own implementation (TrainEvalSplit() in
catboost/python-package/catboost/helpers.cpp) lives in the
python-package tree (not a core lib) and includes Python.h, so it
is not directly callable from R; CatBoostPoolTrainEvalSplit_R
(src/catboostr.cpp) reimplements its body against the same core
entry points it itself calls.
catboost.pool.train_eval_split( pool, has_time = FALSE, is_classification = FALSE, eval_fraction = 0.2, save_eval_pool = TRUE )catboost.pool.train_eval_split( pool, has_time = FALSE, is_classification = FALSE, eval_fraction = 0.2, save_eval_pool = TRUE )
pool |
A catboost.Pool object. Default value: Required argument |
has_time |
If Default value: |
is_classification |
If Default value: |
eval_fraction |
Fraction of rows (in Default value: |
save_eval_pool |
If Default value: |
A named list with elements train and eval (each a
catboost.Pool, or NULL for eval if save_eval_pool is
FALSE).
Get predictions from a CatBoost model on new data.
In case of multiclassification the prediction is returned in the form of a matrix. Each row of this matrix contains the predictions for one row of the input dataset.
## S3 method for class 'catboost.Model' predict( object, newdata, verbose = FALSE, prediction_type = "RawFormulaVal", ntree_start = 0, ntree_end = 0, thread_count = -1 ) catboost.predict( model, pool, verbose = FALSE, prediction_type = "RawFormulaVal", ntree_start = 0, ntree_end = 0, thread_count = -1 )## S3 method for class 'catboost.Model' predict( object, newdata, verbose = FALSE, prediction_type = "RawFormulaVal", ntree_start = 0, ntree_end = 0, thread_count = -1 ) catboost.predict( model, pool, verbose = FALSE, prediction_type = "RawFormulaVal", ntree_start = 0, ntree_end = 0, thread_count = -1 )
object |
The model obtained as the result of training. Default value: Required argument |
newdata |
The input data on which to make predictions. Should be a 'catboost.Pool' object. Default value: Required argument |
verbose |
Verbose output to stdout. Default value: FALSE (not used) |
prediction_type |
The format for displaying approximated values in output data (see https://catboost.ai/docs/concepts/output-data.html). Possible values:
Default value: 'RawFormulaVal' Note on R-vs-Python parity: R exposes a single |
ntree_start |
Model is applied on the interval [ntree_start, ntree_end) (zero-based indexing). Default value: 0 |
ntree_end |
Model is applied on the interval [ntree_start, ntree_end) (zero-based indexing). Default value: 0 (if value equals to 0 this parameter is ignored and ntree_end equal to tree_count) |
thread_count |
The number of threads to use when applying the model. If -1, then the number of threads is set to the number of CPU cores. Allows you to optimize the speed of execution. This parameter doesn't affect results. Default value: 1 |
model |
The model obtained as the result of training. Default value: Required argument |
pool |
The input data on which to make predictions. Should be a 'catboost.Pool' object. Default value: Required argument |
The function 'catboost.predict' is a synonym for 'predict.catboost.Model', which is an S3 method (i.e. called like 'predict(model, newdata)').
Vector of predictions (matrix for multi-class classification).
https://catboost.ai/docs/concepts/r-reference_catboost-predict.html
Predict class log-probabilities, R equivalent of Python's
CatBoostClassifier.predict_log_proba() (core.py:5655-5697).
A thin wrapper over catboost.predict with
prediction_type = "Probability" followed by log() – exactly
Python's own implementation (self._predict(data, 'LogProbability',
...) resolves, for a binary classifier, to log() of the same
two-column [P(class 0), P(class 1)] representation
predict_proba() returns), not a separately re-derived computation.
R's catboost.predict(..., prediction_type = "Probability") collapses
the binary case to a single P(class 1) column (see
catboost.predict), so for a binary model this function
reconstructs the two-column [log(1 - p), log(p)] matrix Python
always returns; for a multiclass model catboost.predict() already
returns the full probability matrix and log() is applied directly.
catboost.predict_log_proba( model, pool, ntree_start = 0, ntree_end = 0, thread_count = -1 )catboost.predict_log_proba( model, pool, ntree_start = 0, ntree_end = 0, thread_count = -1 )
model |
The model obtained as the result of training. |
pool |
The input dataset. Should be a |
ntree_start |
Model is applied on the interval [ntree_start, ntree_end) (zero-based indexing). Default value: 0 |
ntree_end |
Model is applied on the interval [ntree_start, ntree_end) (zero-based indexing). If value equals to 0 this parameter is ignored and ntree_end equal to tree_count. Default value: 0 |
thread_count |
The number of threads to use when applying the model. If -1, then the number of threads is set to the number of CPU cores. Default value: -1 |
Matrix of per-class log-probabilities (rows = objects, columns = classes).
R equivalent of Python's CatBoost.randomized_search:
calls the same native search entry point (NCB::RandomizedSearch,
vendored at
catboost/private/libs/hyperparameter_tuning/hyperparameter_tuning.h)
that Python's CatBoost._tune_hyperparams calls via its Cython wrapper.
In contrast to catboost.grid_search, not all parameter values are
tried: a fixed number (n_iter) of settings is sampled uniformly from
param_distributions (the native sampler seeds its shuffle from a fixed
constant, so the sampled combinations – not just the winner – are
reproducible across calls with the same grid and n_iter).
Sampling from continuous distributions (Python's scipy.stats-style
rvs() objects) is not supported: param_distributions entries
must be plain value vectors, sampled uniformly by the native code.
catboost.randomized_search( param_distributions, pool, params = list(), cv = 3, n_iter = 10, partition_random_seed = 0, calc_cv_statistics = TRUE, search_by_train_test_split = TRUE, refit = TRUE, shuffle = TRUE, stratified = FALSE, train_size = 0.8, verbose = TRUE, custom_objective = NULL, custom_eval_metric_object = NULL )catboost.randomized_search( param_distributions, pool, params = list(), cv = 3, n_iter = 10, partition_random_seed = 0, calc_cv_statistics = TRUE, search_by_train_test_split = TRUE, refit = TRUE, shuffle = TRUE, stratified = FALSE, train_size = 0.8, verbose = TRUE, custom_objective = NULL, custom_eval_metric_object = NULL )
param_distributions |
Named list of parameter name -> vector of values to sample from, or an unnamed list of such named lists. Default value: Required argument |
pool |
Data to search on (a Default value: Required argument |
params |
Fixed parameters for Default value: |
cv |
Number of cross-validation folds. Default value: 3 |
n_iter |
Number of parameter settings sampled. Default value: 10 |
partition_random_seed |
The random seed used for splitting the data. Default value: 0 |
calc_cv_statistics |
Whether to estimate quality via cross-validation
with the found best parameters. Only used when
Default value: |
search_by_train_test_split |
If Default value: |
refit |
If Default value: |
shuffle |
Shuffle the dataset objects before searching. Default value: |
stratified |
Perform stratified sampling for the cross-validation
statistics. Unlike Python (which auto-detects this from the loss function),
R always defaults to Default value: |
train_size |
Proportion of the dataset used for the train split (used
when Default value: 0.8 |
verbose |
Whether to print search progress. Default value: |
custom_objective |
A user-defined loss function, used instead of
Default value: NULL (use |
custom_eval_metric_object |
A user-defined eval metric, used instead
of Default value: NULL (use |
A list with $params (best found parameters, as a named list),
$cv_results (a data.frame of cross-validation results with the
same columns catboost.cv returns), and, if refit = TRUE,
$model (a catboost.Model fit with the best parameters).
After de-serializing a model object through R base's functions ('readRDS', 'load'), its underlying object will not exist in the computer's memory anymore, and needs to be restored from the raw bytes that the model stores.
This is automatically done internally when calling functions such as catboost.predict, but the process is repeated at each call, which makes them slower than if using a fresh model object and increases memory usage inbetween calls to the garbage collector. This function allows restoring the internal object beforehand so as to avoid restoring the object multiple times.
Note that the model object needs to be re-assigned as the output of this function, as the modifications are not done in-place.
catboost.restore_handle(model)catboost.restore_handle(model)
model |
The model obtained as the result of training which has been serialized and is now de-serialized. |
The model object with its handle pointing to a valid object in memory.
R equivalent of the CatBoost CLI's run-worker mode:
blocks the calling process, acting as a distributed-training worker
awaiting commands from a master node over the network, until stopped.
There is no R-level stop mechanism beyond what the CLI mode itself
provides – killing the process, or the master sending a stop-slave
command through the par protocol.
Call this from a separate R process (or session) on each worker machine,
before starting the master-side training call. On the master side,
pass params = list(node_type = "Master", file_with_hosts = <path>,
node_port = <port>) to catboost.train (see its
Distributed training section) or to
catboost.select_features. file_with_hosts is a plain
text file with one host:port line per worker, where each
port matches that worker's own node_port below.
catboost.run_worker(node_port, thread_count = parallel::detectCores())catboost.run_worker(node_port, thread_count = parallel::detectCores())
node_port |
TCP port for this worker. Must match this worker's line
in the master's Default value: Required argument |
thread_count |
The number of threads used by this worker. Default value: number of CPU cores ( |
No value is returned; this call blocks until the worker stops.
https://catboost.ai/docs/features/distributed-training.html
## Not run: # Run on each worker machine; blocks until killed or stopped by the master. catboost.run_worker(node_port = 12345) ## End(Not run)## Not run: # Run on each worker machine; blocks until killed or stopped by the master. catboost.run_worker(node_port = 12345) ## End(Not run)
R port of Python's module-level catboost.sample_gaussian_process.
Implements Gaussian Process posterior sampling (Kernel Gradient Boosting /
Algorithm 4) from "Gradient Boosting Performs Gaussian Process Inference"
(https://arxiv.org/abs/2206.05608). Produces samples from the GP
posterior under the prior assumption f ~ GP(0, sigma^2 K + delta^2 I).
Takes a catboost.Pool rather than the separate X/y/
cat_features/text_features/embedding_features
arguments Python's version takes – every other R training entry point
(catboost.train, catboost.cv, ...) is
Pool-based, and the Pool already carries that information.
Reproduces the Python algorithm's two-stage fit – a near-zero-signal
"prior" model whose leaf values are then randomized by direct JSON model
surgery, then a "posterior" model fit to the residual – with the same
fitting hyperparameters. Both stages need to fit learn_pool's
features against a boosting label other than its own (pure noise for the
prior, a residual for the posterior); this package's Pool object has no
set_label entry point (unlike Python's X/y arrays,
which Python simply resubmits with a different y each stage), so
each stage instead builds a throwaway catboost.Pool from
learn_pool's features (catboost.pool.get_features)
plus the desired label, carrying over learn_pool's weight
(catboost.pool.get_weight) and group id
(catboost.pool.get_group_id_hash/
catboost.pool.set_group_id) if either is set – the same
"extract features, rebuild pool with something else changed" idiom
already used by
catboost.plot_predictions/catboost.plot_partial_dependence.
As with those, this restricts learn_pool to all-numeric features
(get_features's own restriction); an earlier revision instead kept
one shared pool and retargeted its label via a temporary
catboost.pool.set_baseline (which supports categorical/text/
embedding features), but CatBoost's native trainer silently zeroes out
model_shrink_rate whenever a baseline column is present ("Model
shrinkage in combination with baseline column is not implemented yet"),
which would silently drop a term the paper's Algorithm 4 requires – not
an acceptable substitution. learn_pool's own baseline and pairs (if
either is set) are NOT propagated onto the rebuilt Pools and trigger a
warning, not a silent drop; group weight/subgroup id have no accessor
anywhere in this package to even detect, so they can't be checked either.
RNG note: draws a seeded, deterministic sequence from random_seed
(default 0), scoped to this call only – the caller's global RNG stream is
saved before and restored after, so this function has no observable RNG
side effect (unlike Python's local np.random.default_rng, R has no
non-global RNG object, so this is done by save/restore of
.Random.seed instead). Reproducible within this package, but not
byte-identical to the Python implementation – R has no generator matching
numpy's PCG64 default_rng bit-for-bit (same caveat as this
package's embedding_processing LDA calcer; see
catboost.train).
catboost.sample_gaussian_process( learn_pool, test_pool = NULL, random_seed = NULL, samples = 10, posterior_iterations = 900, prior_iterations = 100, learning_rate = 0.1, depth = 6, sigma = 0.1, delta = 0, random_strength = 0.1, random_score_type = "Gumbel", eps = 0.0001, verbose = FALSE )catboost.sample_gaussian_process( learn_pool, test_pool = NULL, random_seed = NULL, samples = 10, posterior_iterations = 900, prior_iterations = 100, learning_rate = 0.1, depth = 6, sigma = 0.1, delta = 0, random_strength = 0.1, random_score_type = "Gumbel", eps = 0.0001, verbose = FALSE )
learn_pool |
A catboost.Pool with a single-dimensional label and
all-numeric features (no categorical/text/embedding features – the same
restriction Default value: Required argument |
test_pool |
A catboost.Pool or NULL. Validation dataset for metrics/early
stopping during posterior training only, as in Default value: NULL |
random_seed |
NULL (mapped to 0) or a single integer. Default value: NULL |
samples |
Number of posterior samples (models) to produce. Range: Default value: 10 |
posterior_iterations |
Number of boosting iterations for each posterior model. Range: Default value: 900 |
prior_iterations |
Number of boosting iterations for each prior model. Range: Default value: 100 |
learning_rate |
Learning rate of the posterior model. Range: Default value: 0.1 |
depth |
Tree depth. Range: Default value: 6 |
sigma |
Scale of the GP kernel (lower values give lower posterior variance). Range: Default value: 0.1 |
delta |
Scale of homogeneous noise added to the kernel (label noise). Range: Default value: 0 |
random_strength |
Corresponds to beta in the paper; higher values give faster
posterior convergence. Range: Default value: 0.1 |
random_score_type |
Type of random noise added to split scores. Possible values:
Default value: 'Gumbel' |
eps |
Technical parameter controlling precision of the prior estimate. Range: Default value: 1e-4 |
verbose |
Verbosity of posterior model training output, same convention as
Default value: FALSE |
A list of samples trained catboost.Model objects, each the sum
(via catboost.sum_models) of that sample's prior and posterior model.
https://arxiv.org/abs/2206.05608
R equivalent of Python's model.save_borders(fname)
(core.py:3809-3820, _save_borders()): writes the model's float
feature quantization borders to a file in the format described at
https://catboost.ai/docs/concepts/input-data_custom-borders.html,
so they can be reused to quantize another Pool identically (upstream's
input_borders mechanism). Unlike
catboost.pool.save_quantization_borders (which requires an
already-quantized Pool), this reads borders directly off a trained model.
catboost.save_borders(model, output_file)catboost.save_borders(model, output_file)
model |
The model obtained as the result of training. |
output_file |
Output file path. |
No return value, called for side effects.
Save the model to a file.
Note: Feature importance (see https://catboost.ai/docs/concepts/fstr.html#fstr) is not saved when using this function.
catboost.save_model( model, model_path, file_format = "cbm", export_parameters = NULL, pool = NULL )catboost.save_model( model, model_path, file_format = "cbm", export_parameters = NULL, pool = NULL )
model |
The model to be saved. Default value: Required argument |
model_path |
The path to the resulting binary file with the model description. Used for solving other machine learning problems (for instance, applying a model). Default value: Required argument |
file_format |
specified format model from a file. Possible values:
Default value: 'cbm' |
export_parameters |
are a parameters for CoreML or PMML export. |
pool |
is training pool. |
Status, the result of model shrinking. TRUE if shrinking succeeded, FALSE otherwise.
https://catboost.ai/docs/features/export-model-to-core-ml.html
Save the dataset to the CatBoost format. Files with the following data are created:
Dataset description
Column descriptions
Use the catboost.load_pool function to read the resulting files. These files can also be used in the Command-line version and the Python library.
catboost.save_pool( data, label = NULL, weight = NULL, baseline = NULL, pool_path = "data.pool", cd_path = "cd.pool" )catboost.save_pool( data, label = NULL, weight = NULL, baseline = NULL, pool_path = "data.pool", cd_path = "cd.pool" )
data |
A data.frame with features. The following column types are supported:
Default value: Required argument |
label |
The label vector. |
weight |
The weights of the label vector. |
baseline |
Vector of initial (raw) values of the label function for the object. Used in the calculation of final values of trees. |
pool_path |
The path to the output file that contains the dataset description. |
cd_path |
The path to the output file that contains the column descriptions. |
Nothing. This method writes a dataset to disk.
R equivalent of Python's CatBoost.select_features: trains
repeatedly while eliminating the weakest features, and reports which features
survived.
This calls the same native entry point Python's select_features calls
(NCB::SelectFeatures, vendored at
catboost/libs/features_selection/select_features.h), so the
elimination loop, its per-step retraining, the SHAP-based feature strengths
and the final model all come from vendor code rather than an R-side
reimplementation.
This is a different algorithm from catboost.eval_feature, which
scores caller-supplied feature sets by cross-validation instead of
eliminating features.
Feature selection by feature tags (Python's grouping = "ByTags")
is supported via grouping/features_tags_for_select/
num_features_tags_to_select: attach tags to learn_pool with
catboost.load_pool's feature_tags argument, then select
among them here.
catboost.select_features( learn_pool, features_for_select = NULL, num_features_to_select = NULL, test_pool = NULL, params = list(), algorithm = NULL, steps = NULL, shap_calc_type = NULL, train_final_model = TRUE, custom_eval_metric_object = NULL, grouping = NULL, features_tags_for_select = NULL, num_features_tags_to_select = NULL )catboost.select_features( learn_pool, features_for_select = NULL, num_features_to_select = NULL, test_pool = NULL, params = list(), algorithm = NULL, steps = NULL, shap_calc_type = NULL, train_final_model = TRUE, custom_eval_metric_object = NULL, grouping = NULL, features_tags_for_select = NULL, num_features_tags_to_select = NULL )
learn_pool |
The dataset to select features on (a Default value: Required argument |
features_for_select |
(for Default value: Required argument when |
num_features_to_select |
(for Default value: Required argument when |
test_pool |
Validation dataset used to measure the loss during
elimination (a Default value: |
params |
Parameters for Default value: |
algorithm |
One of Default value: |
steps |
How many times a full model is trained during the elimination.
More steps give more accurate results. Default value: |
shap_calc_type |
One of Default value: |
train_final_model |
Whether to fit a model on the selected features and return it. Default value: |
custom_eval_metric_object |
A user-defined eval metric, used instead
of Default value: NULL (use |
grouping |
One of Default value: |
features_tags_for_select |
(for Default value: Required argument when |
num_features_tags_to_select |
(for Default value: Required argument when |
A list with the fields of the vendor's selection summary:
selected_features – 0-based indices of the kept features.
selected_features_names – their names.
eliminated_features – 0-based indices of the dropped features.
eliminated_features_names – their names.
selected_features_tags/eliminated_features_tags –
present only when grouping = "ByTags": the kept/dropped tag names.
loss_graph – list with removed_features_count,
loss_values and main_indices (the graph points whose loss
was measured by fitting a model rather than estimated from fstr).
model – the fitted catboost.Model, present only when
train_final_model = TRUE.
R equivalent of Python's
model.set_leaf_values(new_leaf_values) (core.py:2141-2152,
defined once on _CatBoostBase and inherited unchanged by
CatBoost/CatBoostClassifier/CatBoostRegressor/
CatBoostRanker). The change is held in memory only; call
catboost.save_model to persist it, same calling convention
as catboost.set_scale_and_bias.
catboost.set_leaf_values(model, new_leaf_values)catboost.set_leaf_values(model, new_leaf_values)
model |
The model obtained as the result of training. |
new_leaf_values |
A numeric vector with new leaf values for all
trees. Its length must equal |
No return value, called for side effects.
Set a single string metadata key/value pair on the model, in
place. R equivalent of Python's model.get_metadata()[key] = value
and of the CLI's metadata set --key --value mode. The change is
held in memory only; call catboost.save_model to persist it,
matching Python's calling convention.
catboost.set_metadata(model, key, value)catboost.set_metadata(model, key, value)
model |
The model obtained as the result of training. |
key |
The metadata key name. |
value |
The metadata value. |
No return value, called for side effects.
Set (or discard) the threshold used for class separation in a
binary classification model, R equivalent of Python's
CatBoostClassifier.set_probability_threshold()
(core.py:5891-5906). Held in the same model metadata key
(binclass_probability_threshold) catboost.get_metadata/
catboost.set_metadata expose; the change is in-memory only,
same calling convention as catboost.set_metadata.
catboost.set_probability_threshold( model, binclass_probability_threshold = NULL )catboost.set_probability_threshold( model, binclass_probability_threshold = NULL )
model |
The model obtained as the result of training. |
binclass_probability_threshold |
A single numeric value in [0, 1], or
Default value: |
No return value, called for side effects.
Set the model's scale and bias, in place. R equivalent of
Python's model.set_scale_and_bias(scale, bias) and of the CLI's
normalize-model --set-scale --set-bias mode. The change is held in
memory only; call catboost.save_model to persist it, matching
Python's calling convention.
catboost.set_scale_and_bias(model, scale, bias)catboost.set_scale_and_bias(model, scale, bias)
model |
The model obtained as the result of training. |
scale |
The model scale, a single number. |
bias |
The model bias: a single number, or a numeric vector with one value per model output dimension. |
No return value, called for side effects.
Shrink the model
catboost.shrink(model, ntree_end, ntree_start = 0)catboost.shrink(model, ntree_end, ntree_start = 0)
model |
The model obtained as the result of training. |
ntree_end |
Leave the trees with indices from the interval [ntree_start, ntree_end) (zero-based indexing). |
ntree_start |
Leave the trees with indices from the interval [ntree_start, ntree_end) (zero-based indexing). |
Status, the result of model shrinking. TRUE if shrinking succeeded, FALSE otherwise.
https://catboost.ai/docs/concepts/r-reference_catboost-shrink.html
Apply the model to the given dataset and calculate the results for each i-th tree of the model taking into consideration only the trees in the range [1;i].
Peculiarities: In case of multiclassification the prediction is returned in the form of a matrix. Each line of this matrix contains the predictions for one object of the input dataset.
catboost.staged_predict( model, pool, verbose = FALSE, prediction_type = "RawFormulaVal", ntree_start = 0L, ntree_end = 0L, eval_period = 1, thread_count = -1 )catboost.staged_predict( model, pool, verbose = FALSE, prediction_type = "RawFormulaVal", ntree_start = 0L, ntree_end = 0L, eval_period = 1, thread_count = -1 )
model |
The model obtained as the result of training. Default value: Required argument |
pool |
The input dataset. Default value: Required argument |
verbose |
Verbose output to stdout. Default value: FALSE (not used) |
prediction_type |
The format for displaying approximated values in output data (see https://catboost.ai/docs/concepts/output-data.html). Possible values:
Default value: 'RawFormulaVal' Note on R-vs-Python parity: same rationale as |
ntree_start |
Model is applied on the interval [ntree_start, ntree_end) with the step eval_period (zero-based indexing). Default value: 0 |
ntree_end |
Model is applied on the interval [ntree_start, ntree_end) with the step eval_period (zero-based indexing). Default value: 0 (if value equals to 0 this parameter is ignored and ntree_end equal to tree_count) |
eval_period |
Model is applied on the interval [ntree_start, ntree_end) with the step eval_period (zero-based indexing). Default value: 1 |
thread_count |
The number of threads to use when applying the model. If -1, then the number of threads is set to the number of CPU cores. Allows you to optimize the speed of execution. This parameter doesn't affect results. Default value: 1 |
List object with predictions from one iteration.
https://catboost.ai/docs/concepts/r-reference_catboost-staged_predict.html
Predict class log-probabilities at each iteration, R
equivalent of Python's CatBoostClassifier.staged_predict_log_proba()
(core.py:5796-5835). A thin wrapper over
catboost.staged_predict with
prediction_type = "Probability": each iteration's result is
log()-transformed the same way catboost.predict_log_proba
transforms a single catboost.predict() call.
catboost.staged_predict_log_proba( model, pool, ntree_start = 0L, ntree_end = 0L, eval_period = 1, thread_count = -1 )catboost.staged_predict_log_proba( model, pool, ntree_start = 0L, ntree_end = 0L, eval_period = 1, thread_count = -1 )
model |
The model obtained as the result of training. |
pool |
The input dataset. Should be a |
ntree_start |
Model is applied on the interval [ntree_start, ntree_end) with the step eval_period (zero-based indexing). Default value: 0 |
ntree_end |
Model is applied on the interval [ntree_start, ntree_end) with the step eval_period (zero-based indexing). If value equals to 0 this parameter is ignored and ntree_end equal to tree_count. Default value: 0 |
eval_period |
Model is applied on the interval [ntree_start, ntree_end) with the step eval_period (zero-based indexing). Default value: 1 |
thread_count |
The number of threads to use when applying the model. If -1, then the number of threads is set to the number of CPU cores. Default value: -1 |
Iterator object; each nextElem() call returns the matrix of
per-class log-probabilities for the corresponding iteration.
Blend trees and counters of two or more trained CatBoost models into a new model. Leaf values can be individually weighted for each input model. For example, it may be useful to blend models trained on different validation datasets.
catboost.sum_models( models, weights = NULL, ctr_merge_policy = "IntersectingCountersAverage" )catboost.sum_models( models, weights = NULL, ctr_merge_policy = "IntersectingCountersAverage" )
models |
Models for the summation. Default value: Required argument |
weights |
The weights of the models. Default value: NULL (use weight 1 for every model) |
ctr_merge_policy |
The counters merging policy. Possible values:
Default value: 'IntersectingCountersAverage' |
Model object.
Splits a string into tokens ahead of catboost.Dictionary
fitting/application. Native bridge to Python's
catboost.text_processing.Tokenizer, backed directly by vendor's
NTextProcessing::NTokenizer::TTokenizer.
catboost.Tokenizer( lowercasing = NULL, number_process_policy = NULL, number_token = NULL, separator_type = NULL, delimiter = NULL, split_by_set = NULL, skip_empty = NULL, token_types = NULL, sub_tokens_policy = NULL, languages = NULL, lemmatizing = NULL )catboost.Tokenizer( lowercasing = NULL, number_process_policy = NULL, number_token = NULL, separator_type = NULL, delimiter = NULL, split_by_set = NULL, skip_empty = NULL, token_types = NULL, sub_tokens_policy = NULL, languages = NULL, lemmatizing = NULL )
lowercasing |
Lowercase each token. Default value: FALSE |
number_process_policy |
One of "Skip", "LeaveAsIs", "Replace". Default value: "LeaveAsIs" |
number_token |
Replacement token used when Default value: "🔢" (matches vendor default) |
separator_type |
Tokenization method: "ByDelimiter" or "BySense". Default value: "ByDelimiter" |
delimiter |
Delimiter string used to split tokens (ByDelimiter mode). Default value: " " |
split_by_set |
If TRUE, each individual character in Default value: FALSE |
skip_empty |
Skip empty tokens adjacent to delimiters (ByDelimiter mode). Default value: TRUE |
token_types |
Character vector of token types kept after tokenization (BySense mode). Possible values: "Word", "Digit", "Punctuation", "SentenceBreak", "ParagraphBreak", "Unknown". Default value: NULL (vendor default: c("Word", "Digit", "Unknown")) |
sub_tokens_policy |
Subtoken processing policy (BySense mode): one of "SingleToken", "SeveralTokens". Default value: "SingleToken" |
languages |
Character vector of language names used for lemmatizing/BySense tokenization. Default value: NULL (all languages) |
lemmatizing |
Apply lemmatization to tokens. Default value: FALSE |
catboost.Tokenizer
Split string into tokens using a catboost.Tokenizer.
catboost.tokenizer.tokenize(tokenizer, string, types = FALSE)catboost.tokenizer.tokenize(tokenizer, string, types = FALSE)
tokenizer |
A catboost.Tokenizer object. Default value: Required argument |
string |
Input string. Default value: Required argument |
types |
If TRUE, also return token types. Default value: FALSE |
A character vector of tokens, or (if types = TRUE) a
data.frame with token and type columns.
Train the model using a CatBoost dataset.
The list of parameters
Common parameters
fold_permutation_block
Objects in the dataset are grouped in blocks before the random permutations. This parameter defines the size of the blocks. The smaller is the value, the slower is the training. Large values may result in quality degradation.
Default value:
Default value differs depending on the dataset size and ranges from 1 to 256 inclusively
ignored_features
Identifiers of features to exclude from training. The non-negative indices that do not match any features are successfully ignored. For example, if five features are defined for the objects in the dataset and this parameter is set to "42", the corresponding non-existing feature is successfully ignored.
The identifier corresponds to the feature's index.
Feature indices used in train and feature importance are numbered from 0 to featureCount-1.
If a file is used as input data then any non-feature column types are ignored when calculating these
indices. For example, each row in the input file contains data in the following order:
"categorical feature<\t>label<\t>numerical feature". So for the row "rock<\t>0<\t>42",
the identifier for the "rock" feature is 0, and for the "42" feature it is 1.
The identifiers of features to exclude should be enumerated at vector.
For example, if training should exclude features with the identifiers 1, 2, 7, 42, 43, 44, 45, the value of this parameter should be set to c(1,2,7,42,43,44,45).
Default value:
None (use all features)
use_best_model
If this parameter is set, the number of trees that are saved in the resulting model is defined as follows:
Build the number of trees defined by the training parameters.
Identify the iteration with the optimal loss function value.
No trees are saved after this iteration.
This option requires a test dataset to be provided.
Default value:
FALSE (not used)
loss_function
The loss function (see https://catboost.ai/docs/concepts/loss-functions.html#loss-functions) to use in training. The specified value also determines the machine learning problem to solve.
Format:
<Loss function 1>[:<parameter 1>=<value>:..<parameter N>=<value>:]
Supported loss functions:
'Logloss'
'CrossEntropy'
'MultiClass'
'MultiClassOneVsAll'
'RMSE'
'MAE'
'Quantile'
'LogLinQuantile'
'MAPE'
'Poisson'
'Lq'
'PairLogit'
'PairLogitPairwise'
'YetiRank'
'YetiRankPairwise'
'QueryCrossEntropy'
'QueryRMSE'
'QuerySoftMax'
Supported parameters:
alpha - The coefficient used in quantile-based losses ('Quantile' and 'LogLinQuantile'). The default value is 0.5.
For example, if you need to calculate the value of Quantile with the coefficient , use the following construction:
'Quantile:alpha=0.1'
Default value:
'RMSE'
custom_loss
Loss function (see https://catboost.ai/docs/concepts/loss-functions.html#loss-functions) values to output during training. These functions are not used for optimization and are displayed for informational purposes only.
Format:
c(<Loss function 1>[:<parameter>=<value>],<Loss function 2>[:<parameter>=<value>],...,<Loss function N>[:<parameter>=<value>])
Supported loss functions:
'Logloss'
'CrossEntropy'
'Precision'
'Recall'
'F1'
'F'
'BalancedAccuracy'
'BalancedErrorRate'
'MCC'
'Accuracy'
'CtrFactor'
'AUC'
'BrierScore'
'HingeLoss'
'HammingLoss'
'ZeroOneLoss'
'Kappa'
'WKappa'
'LogLikelihoodOfPrediction'
'MultiClass'
'MultiClassOneVsAll'
'TotalF1'
'MAE'
'MAPE'
'Poisson'
'Quantile'
'RMSE'
'LogLinQuantile'
'Lq'
'NumErrors'
'SMAPE'
'R2'
'MSLE'
'MedianAbsoluteError'
'PairLogit'
'PairLogitPairwise'
'PairAccuracy'
'QueryCrossEntropy'
'QueryRMSE'
'QuerySoftMax'
'PFound'
'NDCG'
'AverageGain'
'PrecisionAt'
'RecallAt'
'MAP'
'MRR'
'ERR'
Supported parameters:
alpha - The coefficient used in quantile-based losses ('Quantile' and 'LogLinQuantile'). The default value is 0.5.
For example, if you need to calculate the value of CrossEntropy and Quantile with the coefficient , use the following construction:
c('CrossEntropy') or simply 'CrossEntropy'.
Values of all custom loss functions for learning and test datasets are saved to the Loss function (see https://catboost.ai/docs/concepts/output-data_loss-function.html#output-data_loss-function) output files (learn_error.tsv and test_error.tsv respectively). The catalog for these files is specified in the train-dir (train_dir) parameter.
Default value:
None (use one of the loss functions supported by the library)
eval_metric
The loss function used for overfitting detection (if enabled) and best model selection (if enabled).
Supported loss functions:
'Logloss'
'CrossEntropy'
'Precision'
'Recall'
'F1'
'F'
'BalancedAccuracy'
'BalancedErrorRate'
'MCC'
'Accuracy'
'CtrFactor'
'AUC'
'BrierScore'
'HingeLoss'
'HammingLoss'
'ZeroOneLoss'
'Kappa'
'WKappa'
'LogLikelihoodOfPrediction'
'MultiClass'
'MultiClassOneVsAll'
'TotalF1'
'MAE'
'MAPE'
'Poisson'
'Quantile'
'RMSE'
'LogLinQuantile'
'Lq'
'NumErrors'
'SMAPE'
'R2'
'MSLE'
'MedianAbsoluteError'
'PairLogit'
'PairLogitPairwise'
'PairAccuracy'
'QueryCrossEntropy'
'QueryRMSE'
'QuerySoftMax'
'PFound'
'NDCG'
'AverageGain'
'PrecisionAt'
'RecallAt'
'MAP'
'MRR'
'ERR'
Format:
metric_name:param=Value
Examples:
'R2'
'Quantile:alpha=0.3'
Default value:
Optimized objective is used
iterations
The maximum number of trees that can be built when solving machine learning problems.
When using other parameters that limit the number of iterations, the final number of trees may be less than the number specified in this parameter.
Default value:
1000
border
The target border. If the value is strictly greater than this threshold, it is considered a positive class. Otherwise it is considered a negative class.
The parameter is obligatory if the Logloss function is used, since it uses borders to transform any given target to a binary target.
Used in binary classification.
Default value:
0.5
leaf_estimation_iterations
The number of gradient steps when calculating the values in leaves.
Default value:
1
depth
Depth of the trees.
The value can be any integer up to 16. It is recommended to use values in the range [1; 10].
Default value:
6
learning_rate
The learning rate.
Used for reducing the gradient step.
Default value:
0.03
rsm
Random subspace method. The percentage of features to use at each iteration of building trees. At each iteration, features are selected over again at random.
The value must be in the range [0;1].
Default value:
1
random_seed
The random seed used for training.
Default value:
0
nan_mode
Way to process missing values.
Possible values:
'Min'
'Max'
'Forbidden'
Default value:
'Min'
od_pval
Use the Overfitting detector (see https://catboost.ai/docs/concepts/overfitting-detector.html#overfitting-detector) to stop training when the threshold is reached. Requires that a test dataset was input.
For best results, it is recommended to set a value in the range [10^-10; 10^-2].
The larger the value, the earlier overfitting is detected.
Default value:
The overfitting detection is turned off
od_type
The method used to calculate the values in leaves.
Possible values:
IncToDec
Iter
Restriction. Do not specify the overfitting detector threshold when using the Iter type.
Default value:
'IncToDec'
od_wait
The number of iterations to continue the training after the iteration with the optimal loss function value. The purpose of this parameter differs depending on the selected overfitting detector type:
IncToDec - Ignore the overfitting detector when the threshold is reached and continue learning for the specified number of iterations after the iteration with the optimal loss function value.
Iter - Consider the model overfitted and stop training after the specified number of iterations since the iteration with the optimal loss function value.
Default value:
20
leaf_estimation_method
The method used to calculate the values in leaves.
Possible values:
Newton
Gradient
Default value:
Default value depends on the selected loss function
grow_policy
GPU only. The tree growing policy. It describes how to perform greedy tree construction.
Possible values:
SymmetricTree
Lossguide
Depthwise
Default value:
SymmetricTree
min_data_in_leaf
GPU only. The minimum training samples count in leaf. CatBoost will not search for new splits in leaves with samples count less than min_data_in_leaf. This parameter is used only for Depthwise and Lossguide growing policies.
Default value:
1
max_leaves
GPU only. The maximum leaf count in resulting tree. Used only for Lossguide growing policy. This parameter is used only for Lossguide growing policy.
Default value:
31
score_function GPU only. Score that is used during tree construction to select the next tree split.
Possible values:
L2
Cosine
NewtonL2
NewtonCosine
Default value:
Cosine
For growing policy Lossguide default is NewtonL2.
l2_leaf_reg
L2 regularization coefficient. Used for leaf value calculation.
Any positive values are allowed.
Default value:
3
model_size_reg
Model size regularization coefficient. The influence coefficient of the model size for choosing tree structure. To get a smaller model size - increase this coefficient.
Any positive values are allowed.
Default value:
0.5
has_time
Use the order of objects in the input data (do not perform a random permutation of the dataset at the preprocessing stage)
Default value:
FALSE (not used; permute input dataset)
allow_const_label
To allow the constant label value in the dataset.
Default value:
FALSE
name
The experiment name to display in visualization tools (see https://catboost.ai/docs/features/visualization.html#visualization).
Default value:
experiment
prediction_type
The format for displaying approximated values in output data.
Possible values:
'Probability'
'Class'
'RawFormulaVal'
Default value:
'RawFormulaVal'
fold_len_multiplier
Coefficient for changing the length of folds.
The value must be greater than 1. The best validation result is achieved with minimum values.
With values close to 1 (for example, ), each iteration takes a quadratic amount of memory and time
for the number of objects in the iteration. Thus, low values are possible only when there is a small number of objects.
Default value:
2
class_weights
Classes weights. The values are used as multipliers for the object weights.
For example, for 3 class classification you could use:
c(0.85, 1.2, 1)
Default value:
None (the weight for all classes is set to 1)
classes_count
The upper limit for the numeric class label. Defines the number of classes for multiclassification.
Only non-negative integers can be specified. The given integer should be greater than any of the target values.
If this parameter is specified the labels for all classes in the input dataset should be smaller than the given value.
Default value:
maximum class label + 1
one_hot_max_size
Convert the feature to float if the number of different values that it takes exceeds the specified value. Ctrs are not calculated for such features.
The one-vs.-all delimiter is used for the resulting float features.
Default value:
FALSE
Do not convert features to float based on the number of different values
random_strength
Score standard deviation multiplier.
Default value:
1
bootstrap_type
Bootstrap type. Defines the method for sampling the weights of documents.
Possible values:
'Bayesian'
'Bernoulli'
'Poisson'
'MVS'
'No'
Poisson bootstrap is supported only on GPU.
Default value:
'Bayesian'
bagging_temperature
Controls intensity of Bayesian bagging. The higher the temperature the more aggressive bagging is.
Typical values are in the range (0 is for no bagging).
Possible values are in the range .
Default value:
1
subsample
Sample rate for bagging. This parameter can be used if one of the following bootstrap types is defined:
'Bernoulli'
Default value:
0.66
sampling_unit
The parameter allows to specify the sampling scheme: sample weights for each object individually or for an entire group of objects together.
Possible values:
'Object'
'Group'
Default value:
'Object'
sampling_frequency
Frequency to sample weights and objects when building trees.
Possible values:
'PerTree'
'PerTreeLevel'
Default value:
'PerTreeLevel'
model_shrink_rate
For i > 0 at the start of i-th iteration multiplies model by (1 - model_shrink_rate / i).
Possible values: [0, 1).
Default value: 0
CTR settings
simple_ctr
Binarization settings for categorical features (see https://catboost.ai/docs/concepts/algorithm-main-stages_cat-to-numberic.html).
Format:
c(CtrType[:TargetBorderCount=BorderCount][:TargetBorderType=BorderType][:CtrBorderCount=Count][:CtrBorderType=Type][:Prior=num_1/denum_1]..[:Prior=num_N/denum_N])
Components:
CTR types for training on CPU:
'Borders'
'Buckets'
'BinarizedTargetMeanValue'
'Counter'
CTR types for training on GPU:
'Borders'
'Buckets'
'FeatureFreq'
'FloatTargetMeanValue'
The number of borders for label value binarization. (see https://catboost.ai/docs/concepts/quantization.html) Only used for regression problems. Allowed values are integers from 1 to 255 inclusively. The default value is 1. This option is available for training on CPU only.
The binarization (see https://catboost.ai/docs/concepts/quantization.html) type for the label value. Only used for regression problems.
Possible values:
'Median'
'Uniform'
'UniformAndQuantiles'
'MaxLogSum'
'MinEntropy'
'GreedyLogSum'
By default, 'MinEntropy'
This option is available for training on CPU only.
The number of splits for categorical features. Allowed values are integers from 1 to 255 inclusively.
The binarization type for categorical features. Supported values for training on CPU:
'Uniform'
Supported values for training on GPU:
'Median'
'Uniform'
'UniformAndQuantiles'
'MaxLogSum'
'MinEntropy'
'GreedyLogSum'
Priors to use during training (several values can be specified) Possible formats:
'One number - Adds the value to the numerator.'
'Two slash-delimited numbers (for GPU only) - Use this format to set a fraction. The number is added to the numerator and the second is added to the denominator.'
combinations_ctr
Binarization settings for combinations of categorical features (see https://catboost.ai/docs/concepts/algorithm-main-stages_cat-to-numberic.html).
Format:
c(CtrType[:TargetBorderCount=BorderCount][:TargetBorderType=BorderType][:CtrBorderCount=Count][:CtrBorderType=Type][:Prior=num_1/denum_1]..[:Prior=num_N/denum_N])
Components:
CTR types for training on CPU:
'Borders'
'Buckets'
'BinarizedTargetMeanValue'
'Counter'
CTR types for training on GPU:
'Borders'
'Buckets'
'FeatureFreq'
'FloatTargetMeanValue'
The number of borders for target binarization. (see https://catboost.ai/docs/concepts/quantization.html) Only used for regression problems. Allowed values are integers from 1 to 255 inclusively. The default value is 1. This option is available for training on CPU only.
The binarization (see https://catboost.ai/docs/concepts/quantization.html) type for the target. Only used for regression problems.
Possible values:
'Median'
'Uniform'
'UniformAndQuantiles'
'MaxLogSum'
'MinEntropy'
'GreedyLogSum'
By default, 'MinEntropy'
This option is available for training on CPU only.
The number of splits for categorical features. Allowed values are integers from 1 to 255 inclusively.
The binarization type for categorical features. Supported values for training on CPU:
'Uniform'
Supported values for training on GPU:
'Median'
'Uniform'
'UniformAndQuantiles'
'MaxLogSum'
'MinEntropy'
'GreedyLogSum'
Priors to use during training (several values can be specified) Possible formats:
'One number - Adds the value to the numerator.'
'Two slash-delimited numbers (for GPU only) - Use this format to set a fraction. The number is added to the numerator and the second is added to the denominator.'
ctr_target_border_count
Maximum number of borders used in target binarization for categorical features that need it. If TargetBorderCount is specified in 'simple_ctr', 'combinations_ctr' or 'per_feature_ctr' option it overrides this value.
Default value:
1
counter_calc_method
The method for calculating the Counter CTR type for the test dataset.
Possible values:
'Full'
'FullTest'
'PrefixTest'
'SkipTest'
Default value: 'PrefixTest'
max_ctr_complexity
The maximum number of categorical features that can be combined.
Default value:
4
ctr_leaf_count_limit
The maximum number of leaves with categorical features.
If the number of leaves exceeds the specified limit, some leaves are discarded.
The value must be positive (for zero limit use ignored_features parameter).
The leaves to be discarded are selected as follows:
The leaves are sorted by the frequency of the values.
The top N leaves are selected, where N is the value specified in the parameter.
All leaves starting from N+1 are discarded.
This option reduces the resulting model size and the amount of memory required for training. Note that the resulting quality of the model can be affected.
Default value:
None (The number of leaves with categorical features is not limited)
store_all_simple_ctr
Ignore categorical features, which are not used in feature combinations, when choosing candidates for exclusion.
Use this parameter with ctr-leaf-count-limit only.
Default value:
FALSE (Both simple features and feature combinations are taken in account when limiting the number of leaves with categorical features)
Binarization settings
border_count
The number of splits for numerical features. Allowed values are integers from 1 to 255 inclusively.
Default value:
254 for training on CPU or 128 for training on GPU
feature_border_type
The binarization mode (see https://catboost.ai/docs/concepts/quantization.html) for numerical features.
Possible values:
'Median'
'Uniform'
'UniformAndQuantiles'
'MaxLogSum'
'MinEntropy'
'GreedyLogSum'
Default value:
'MinEntropy'
Performance settings
thread_count
The number of threads to use when applying the model.
Allows you to optimize the speed of execution. This parameter doesn't affect results.
Default value:
The number of CPU cores.
Output settings
logging_level
Possible values:
'Silent'
'Verbose'
'Info'
'Debug'
Default value:
'Silent'
metric_period
The frequency of iterations to print the information to stdout. The value should be a positive integer.
Default value:
1
train_dir
The directory for storing the files generated during training.
Default value:
None (current catalog)
save_snapshot
Enable snapshotting for restoring the training progress after an interruption.
Default value:
None
snapshot_file
Settings for recovering training after an interruption (see https://catboost.ai/docs/features/snapshots.html).
Depending on whether the file specified exists in the file system:
Missing - write information about training progress to the specified file.
Exists - load data from the specified file and continue training from where it left off.
Default value:
File can't be generated or read. If the value is omitted, the file name is experiment.cbsnapshot.
snapshot_interval
Interval between saving snapshots (seconds)
Default value:
600
allow_writing_files
If this flag is set to FALSE, no files with different diagnostic info will be created during training. With this flag set to FALSE no snapshotting can be done. Plus visualisation will not work, because visualisation uses files that are created and updated during training.
Default value:
TRUE
approx_on_full_history
If this flag is set to TRUE, each approximated value is calculated using all the preceding rows in the fold (slower, more accurate). If this flag is set to FALSE, each approximated value is calculated using only the beginning 1/fold_len_multiplier fraction of the fold (faster, slightly less accurate).
Default value:
FALSE
boosting_type
Boosting scheme. Possible values: - 'Ordered' - Gives better quality, but may slow down the training. - 'Plain' - The classic gradient boosting scheme. May result in quality degradation, but does not slow down the training.
Default value:
Depends on object count and feature count in train dataset and on learning mode.
dev_score_calc_obj_block_size
CPU only. Size of block of samples in score calculation. Should be > 0 Used only for learning speed tuning. Changing this parameter can affect results in pairwise scoring mode due to numerical accuracy differences
Default value:
5000000
dev_efb_max_buckets
CPU only. Maximum bucket count in exclusive features bundle. Should be in an integer between 0 and 65536. Used only for learning speed tuning.
Default value:
1024
sparse_features_conflict_fraction
CPU only. Maximum allowed fraction of conflicting non-default values for features in exclusive features bundle. Should be a real value in [0, 1) interval.
Default value:
0.0
leaf_estimation_backtracking
Type of backtracking during gradient descent. Possible values: - 'No' - never backtrack; supported on CPU and GPU - 'AnyImprovement' - reduce the descent step until the value of loss function is less than before the step; supported on CPU and GPU - 'Armijo' - reduce the descent step until Armijo condition is satisfied; supported on GPU only
Default value:
'AnyImprovement'
catboost.train( learn_pool, test_pool = NULL, params = list(), init_model = NULL, custom_objective = NULL, custom_eval_metric_object = NULL )catboost.train( learn_pool, test_pool = NULL, params = list(), init_model = NULL, custom_objective = NULL, custom_eval_metric_object = NULL )
learn_pool |
The dataset used for training the model. Default value: Required argument |
test_pool |
The dataset used for testing the quality of the model. Default value: NULL (not used) |
params |
The list of parameters to start training with. If omitted, default values are used (see The list of parameters). If set, the passed list of parameters overrides the default values. Default value: Required argument |
init_model |
Continue training starting from an existing model. Accepts a Default value: NULL (train a new model from scratch) |
custom_objective |
A user-defined loss function, used instead of
Reimplements the two-method contract of Python's
Default value: NULL (use |
custom_eval_metric_object |
A user-defined eval metric, used instead
of
Reimplements the four-method contract of Python's
Default value: NULL (use |
Custom objective / custom eval metric support matrix.
Every entry point below shares the same
custom_objective/custom_eval_metric_object argument contract
documented under catboost.train's own custom_objective and
custom_eval_metric_object params:
catboost.train Both custom_objective and
custom_eval_metric_object.
catboost.cv Both.
catboost.grid_search Both – forwarded to the search
itself and, when refit = TRUE, to the refit.
catboost.randomized_search Both – same forwarding as
catboost.grid_search.
catboost.eval_feature Both.
catboost.select_features custom_eval_metric_object
only. There is no custom_objective argument: the
native entry point it calls, NCB::SelectFeatures (vendored at
catboost/libs/features_selection/select_features.h), takes no
TCustomObjectiveDescriptor parameter anywhere in its signature
or in recursive_features_elimination.* – there is no C++-side
slot to wire a custom objective into, so the omission is structural,
not a missing feature.
Multithreading preservation. CatBoost's own engine parallelizes
derivative/metric computation across TBB worker threads
(NPar::TTbbLocalExecutor), but R's C API may only be called from R's
own main thread. The naive fix – forcing params$thread_count = 1
whenever a custom objective/metric is supplied – was rejected: it would
silently kill CatBoost's own training parallelism for every custom-loss
user, trading a correctness problem for a performance regression. Instead,
training runs on a background std::thread while R's real main
thread (the .Call frame the user invoked) runs a drain loop that
services R-closure-invocation requests queued by any worker thread; each
request blocks its own thread on a condition variable until the main
thread has executed it and posted the result back
(src/r_callback_bridge.h). TBB's own parallel scheduling of the
surrounding derivative/metric computation is untouched – only the R
closure invocation itself is serialized onto the main thread, not the
whole computation. params$thread_count is therefore never forced
to 1 for a custom objective/metric run.
Ctrl-C during a bridged run. Detecting the
interrupt on the drain loop's polling thread consumes it – R clears its
pending-interrupt flag before the drain loop observes it, so nothing is
left for R to deliver afterwards. Ctrl-C during a custom-objective/metric
run therefore surfaces as an ordinary R error, not an R interrupt
condition: tryCatch(..., interrupt = ) will not fire on it.
Restoring true interrupt semantics is tracked as a follow-up, not pursued
here due to CRAN R CMD check NOTE risk in the required mechanism.
Distributed training. params accepts the native
node_type, node_port and file_with_hosts keys used to
run multi-machine training: start a worker process on each remote machine
with catboost.run_worker, then set node_type =
"Master", file_with_hosts = <path to a "host:port"-per-line file>
and node_port = <the par-framework port on this machine> in the
master-side params list. Setting any node_type other than
"SingleHost" routes the call to the native distributed training
engine (the same one the command-line client's --node-type Master
fit uses); the default single-host path is untouched by this and behaves
exactly as before.
Distributed training shards the dataset across the workers and builds each
split's histograms per shard, so a distributed model is not bit-for-bit
identical to a single-host model trained on the same data with the same
seed – it is statistically equivalent, not reproducible against it.
node_type = "Master" requires task_type = "CPU" (the
default); it is rejected for GPU training.
Model object.
All 139 hyperparameters from the machine-generated capability inventory, and how catboostr accepts each one.
Unrecognized params keys are rejected with an error naming the
offending key(s). To use a newer vendor-core parameter not yet listed
below, set options(catboostr.allow_unknown_params = TRUE) to bypass
this check.
Supplied via learn_pool/test_pool (see catboost.load_pool), not the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Supplied via catboost.load_pool (Pool construction), not the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Python-only (a native training-progress convenience distinct from callbacks); no catboostr equivalent.
A list of functions, each taking a single info argument (a list with iteration and metrics elements, the latter shaped like catboost.get_evals_result's return value) and returning TRUE to continue training or FALSE to stop it early. Training continues only while every callback returns TRUE, matching Python's callbacks kwarg.
Supplied via catboost.load_pool (Pool construction), not the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Alias of rsm (see process_synonyms); resolved automatically.
Supplied via catboost.load_pool (Pool construction), not the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Supplied via catboost.load_pool (Pool construction), not the params list.
Alias of learning_rate (see process_synonyms); resolved automatically.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Supplied via the test_pool argument of catboost.train, not the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Supplied via catboost.load_pool (Pool construction), not the params list.
Supplied via catboost.load_pool (Pool construction), not the params list.
Supplied via catboost.load_pool (Pool construction), not the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Supplied via the init_model argument of catboost.train, not the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Python-only; no catboostr equivalent.
Python-only; no catboostr equivalent.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Alias of border_count (see process_synonyms); resolved automatically.
Native training parameter accepted in the params list.
Alias of depth (see process_synonyms); resolved automatically.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Alias of min_data_in_leaf (see process_synonyms); resolved automatically.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Alias of iterations (see process_synonyms); resolved automatically.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Alias of iterations (see process_synonyms); resolved automatically.
Alias of max_leaves (see process_synonyms); resolved automatically.
Alias of iterations (see process_synonyms); resolved automatically.
Alias of loss_function (see process_synonyms); resolved automatically.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Supplied via catboost.load_pool (Pool construction), not the params list.
Supplied via catboost.load_pool (Pool construction), not the params list.
Refers to the params argument itself.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Python-only; no catboostr equivalent.
Python-only; no catboostr equivalent.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Alias of random_seed (see process_synonyms); resolved automatically.
Native training parameter accepted in the params list.
Alias of l2_leaf_reg (see process_synonyms); resolved automatically.
Native training parameter accepted in the params list.
Supplied via catboost.load_pool (Pool construction), not the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Client-side convenience translated to logging_level ("Silent" if TRUE, "Verbose" if FALSE) before export to native, matching Python's silent kwarg. Mutually exclusive with logging_level/verbose/verbose_eval.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Supplied via catboost.load_pool (Pool construction), not the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Supplied via catboost.load_pool (Pool construction), not the params list.
Native training parameter accepted in the params list.
Supplied via catboost.load_pool (Pool construction), not the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Native training parameter accepted in the params list.
Alias of verbose (see process_synonyms); resolved automatically.
Supplied via learn_pool/test_pool (see catboost.load_pool), not the params list.
If params$class_names is set and learn_pool/
test_pool was built from a factor or character label, this
function temporarily retargets that Pool object's internal target
representation for the duration of this call (needed to match native's
classification target converter against string class names), then
restores it before returning – including on error – so the Pool is
left exactly as it was and remains safe to retrain, read via
catboost.pool.get_label/train_eval_split, or reuse as both
learn_pool and test_pool. This class_names +
string-label combination is currently only supported via
catboost.train; catboost.cv/catboost.grid_search/
catboost.select_features/etc. do not yet apply the same promotion.
https://catboost.ai/docs/concepts/r-reference_catboost-train.html
## Not run: train_pool_path <- system.file("extdata", "adult_train.1000", package = "catboostr") test_pool_path <- system.file("extdata", "adult_test.1000", package = "catboostr") cd_path <- system.file("extdata", "adult.cd", package = "catboostr") train_pool <- catboost.load_pool(train_pool_path, column_description = cd_path) test_pool <- catboost.load_pool(test_pool_path, column_description = cd_path) fit_params <- list( iterations = 100, loss_function = 'Logloss', ignored_features = c(4, 9), border_count = 32, depth = 5, learning_rate = 0.03, l2_leaf_reg = 3.5, train_dir = 'train_dir') model <- catboost.train(train_pool, test_pool, fit_params) ## End(Not run) # (a) custom_objective: reimplement RMSE's own derivatives (matches # calc_ders_range's contract -- weight is applied by the closure itself, # unlike the built-in dispatcher, which multiplies by weight for you). ## Not run: n <- 50 features <- data.frame(x1 = rnorm(n), x2 = rnorm(n)) label <- with(features, x1 - x2 + rnorm(n, sd = 0.3)) pool <- catboost.load_pool(features, label = label) rmse_custom_objective <- list( calc_ders_range = function(approx, target, weight) { w <- if (is.null(weight)) 1 else weight cbind(w * (target - approx), w * (-1)) }) model <- catboost.train( pool, params = list(iterations = 10, depth = 3, logging_level = "Silent", eval_metric = "RMSE", boost_from_average = FALSE), custom_objective = rmse_custom_objective) ## End(Not run) # (b) custom_eval_metric_object: reimplement RMSE's own Eval/GetFinalError. ## Not run: n <- 50 features <- data.frame(x1 = rnorm(n), x2 = rnorm(n)) label <- with(features, x1 - x2 + rnorm(n, sd = 0.3)) pool <- catboost.load_pool(features, label = label) rmse_custom_eval_metric <- list( evaluate = function(approx, target, weight) { w <- if (is.null(weight)) rep(1, length(target)) else weight diff <- approx[, 1] - target list(error = sum(w * diff^2), weight = sum(w)) }, is_max_optimal = function() FALSE, get_final_error = function(error) sqrt(error[1] / (error[2] + 1e-38))) model <- catboost.train( pool, params = list(iterations = 10, depth = 3, logging_level = "Silent"), custom_eval_metric_object = rmse_custom_eval_metric) ## End(Not run)## Not run: train_pool_path <- system.file("extdata", "adult_train.1000", package = "catboostr") test_pool_path <- system.file("extdata", "adult_test.1000", package = "catboostr") cd_path <- system.file("extdata", "adult.cd", package = "catboostr") train_pool <- catboost.load_pool(train_pool_path, column_description = cd_path) test_pool <- catboost.load_pool(test_pool_path, column_description = cd_path) fit_params <- list( iterations = 100, loss_function = 'Logloss', ignored_features = c(4, 9), border_count = 32, depth = 5, learning_rate = 0.03, l2_leaf_reg = 3.5, train_dir = 'train_dir') model <- catboost.train(train_pool, test_pool, fit_params) ## End(Not run) # (a) custom_objective: reimplement RMSE's own derivatives (matches # calc_ders_range's contract -- weight is applied by the closure itself, # unlike the built-in dispatcher, which multiplies by weight for you). ## Not run: n <- 50 features <- data.frame(x1 = rnorm(n), x2 = rnorm(n)) label <- with(features, x1 - x2 + rnorm(n, sd = 0.3)) pool <- catboost.load_pool(features, label = label) rmse_custom_objective <- list( calc_ders_range = function(approx, target, weight) { w <- if (is.null(weight)) 1 else weight cbind(w * (target - approx), w * (-1)) }) model <- catboost.train( pool, params = list(iterations = 10, depth = 3, logging_level = "Silent", eval_metric = "RMSE", boost_from_average = FALSE), custom_objective = rmse_custom_objective) ## End(Not run) # (b) custom_eval_metric_object: reimplement RMSE's own Eval/GetFinalError. ## Not run: n <- 50 features <- data.frame(x1 = rnorm(n), x2 = rnorm(n)) label <- with(features, x1 - x2 + rnorm(n, sd = 0.3)) pool <- catboost.load_pool(features, label = label) rmse_custom_eval_metric <- list( evaluate = function(approx, target, weight) { w <- if (is.null(weight)) rep(1, length(target)) else weight diff <- approx[, 1] - target list(error = sum(w * diff^2), weight = sum(w)) }, is_max_optimal = function() FALSE, get_final_error = function(error) sqrt(error[1] / (error[2] + 1e-38))) model <- catboost.train( pool, params = list(iterations = 10, depth = 3, logging_level = "Silent"), custom_eval_metric_object = rmse_custom_eval_metric) ## End(Not run)
Apply the model to the given dataset using several independent truncated models - virtual ensembles. Each tree in ensemble predicts its own value for each document from pool.
Peculiarities: Return value varies on prediction_type: array for 'VirtEnsembles' and matrix for 'TotalUncertainty'
catboost.virtual_ensembles_predict( model, pool, verbose = FALSE, prediction_type = "VirtEnsembles", ntree_end = 0L, virtual_ensembles_count = 10, thread_count = -1 )catboost.virtual_ensembles_predict( model, pool, verbose = FALSE, prediction_type = "VirtEnsembles", ntree_end = 0L, virtual_ensembles_count = 10, thread_count = -1 )
model |
The model obtained as the result of training. Default value: Required argument |
pool |
The input dataset. Default value: Required argument |
verbose |
Verbose output to stdout. Default value: FALSE (not used) |
prediction_type |
The format for displaying approximated values in output data (see https://catboost.ai/docs/concepts/python-reference_virtual_ensembles_predict.html#python-reference_catboostclassifier_predict__output-format). Possible values:
Default value: 'VirtEnsembles' |
ntree_end |
Index of the first tree not to be used when applying the model or calculating the metrics (zero-based indexing). Default value: 0 (the index of the last tree to use equals to the number of trees in the model minus one) |
virtual_ensembles_count |
Number of tree ensembles to use. Each virtual ensemble can be considered as truncated model. Default value: 10 |
thread_count |
The number of threads to use when applying the model. If -1, then the number of threads is set to the number of CPU cores. Allows you to optimize the speed of execution. This parameter doesn't affect results. Default value: -1 |
Matrix or Array of predictions (for 'TotalUncertainty' and 'VirtEnsembles' prediction_type correspondingly)
https://catboost.ai/docs/concepts/python-reference_virtual_ensembles_predict.html?lang=en
Get dimensions of a Pool.
## S3 method for class 'catboost.Pool' dim(x)## S3 method for class 'catboost.Pool' dim(x)
x |
The input dataset. Default value: Required argument |
Returns a vector of row numbers and column numbers in an catboost.Pool.
Get dimension names of a Pool.
Column names are read from the Pool's own (C++-side) feature layout, so
they stay in sync with catboost.pool.get_feature_names() after a
catboost.pool.set_feature_names() call, which mutates that layout in
place and cannot update an R-side attribute of the caller's object.
## S3 method for class 'catboost.Pool' dimnames(x)## S3 method for class 'catboost.Pool' dimnames(x)
x |
The input dataset. Default value: Required argument |
A list with the two elements. The second element contains the column
names, or NULL if the Pool has no feature names.
Return a list with the first n objects of the dataset.
Each line of this list contains the following information for each object:
The label value.
The weight value.
The feature values.
## S3 method for class 'catboost.Pool' head(x, n = 10, ...)## S3 method for class 'catboost.Pool' head(x, n = 10, ...)
x |
The input dataset. Default value: Required argument |
n |
The quantity of the first objects in the dataset to be returned. Default value: 10 |
... |
not currently used |
A matrix containing the first n objects of the dataset.
Displays the most general characteristics of a CatBoost model.
## S3 method for class 'catboost.Model' print(x, ...)## S3 method for class 'catboost.Model' print(x, ...)
x |
The model obtained as the result of training. |
... |
Not used |
The same model that was passed as input.
Print dimensions of catboost.Pool.
## S3 method for class 'catboost.Pool' print(x, ...)## S3 method for class 'catboost.Pool' print(x, ...)
x |
a catboost.Pool object Default value: Required argument |
... |
not currently used |
Nothing. This method prints pool dimensions.
Displays the most general characteristics of a CatBoost model (same as 'print').
## S3 method for class 'catboost.Model' summary(object, ...)## S3 method for class 'catboost.Model' summary(object, ...)
object |
The model obtained as the result of training. |
... |
Not used |
The same model that was passed as input.
Return a list with the last n objects of the dataset.
Each line of this list contains the following information for each object:
The target value.
The weight value.
The feature values.
## S3 method for class 'catboost.Pool' tail(x, n = 10, ...)## S3 method for class 'catboost.Pool' tail(x, n = 10, ...)
x |
The input dataset. Default value: Required argument |
n |
The quantity of the last objects in the dataset to be returned. Default value: 10 |
... |
not currently used |
A matrix containing the last n objects of the dataset.