---
metadata:
  - name: generator
    content: Diplodoc Platform v5.52.0
alternate:
  - https://catboost.ai/docs/en/concepts/python-reference_catboostregressor_fit.md
  - href: en/concepts/python-reference_catboostregressor_fit.md
    type: text/markdown
    title: Markdown version
  - href: ../llms.txt
    type: text/markdown
    title: llms.txt
---
> **Documentation Index:** Fetch the complete configuration index at https://catboost.ai/docs/en/llms.txt

# fit

<!-- source: en/_includes/work_src/reusage/fit--purpose-desc.md -->
Train a model.
<!-- endsource: en/_includes/work_src/reusage/fit--purpose-desc.md -->


<!-- source: en/_includes/work_src/reusage-python/how-to-train-on-gpu.md -->
{% note info %}

Set the `task_type` parameter in the class constructor to GPU to train the model on GPU. Training on GPU requires NVIDIA Driver of version 450.xx or higher.

{% endnote %}
<!-- endsource: en/_includes/work_src/reusage-python/how-to-train-on-gpu.md -->


## Method call format {#call-format}

```python
fit(X,
    y=None,
    cat_features=None,
    text_features=None,
    embedding_features=None,
    sample_weight=None,
    baseline=None,
    use_best_model=None,
    eval_set=None,
    verbose=None,
    logging_level=None,
    plot=False,
    plot_file=None,
    column_description=None,
    verbose_eval=None,
    metric_period=None,
    silent=None,
    early_stopping_rounds=None,
    save_snapshot=None,
    snapshot_file=None,
    snapshot_interval=None,
    init_model=None,
    log_cout=sys.stdout,
    log_cerr=sys.stderr)
```

## Parameters {#parameters}

<!-- source: en/_includes/work_src/reusage/python--regressor--precedence-p.md -->
Some parameters duplicate the ones specified in the constructor of the [CatBoostRegressor](https://catboost.ai/docs/en/concepts/python-reference_catboostregressor.md) class. In these cases the values specified for the [fit](https://catboost.ai/docs/en/concepts/python-reference_catboostregressor_fit.md) method take precedence. The rest of the training parameters must be set in the constructor of the [CatBoostRegressor](https://catboost.ai/docs/en/concepts/python-reference_catboostregressor.md) class.
<!-- endsource: en/_includes/work_src/reusage/python--regressor--precedence-p.md -->

### X

#### Description

The description is different for each group of possible types.

**Possible types**

{% cut "catboost.Pool" %}

The input training dataset.

{% note info %}

If a nontrivial value of the `cat_features` parameter is specified in the constructor of this class, CatBoost checks the equivalence of categorical features indices specification from the constructor parameters and in this Pool class.

{% endnote %}

{% endcut %}


{% cut "list, numpy.ndarray, pandas.DataFrame, pandas.Series, polars.DataFrame" %}

The input training dataset in the form of a two-dimensional feature matrix.

{% endcut %}


{% cut "pandas.SparseDataFrame, scipy.sparse.spmatrix (all subclasses except dia_matrix)" %}

<!-- source: en/_includes/work_src/reusage-formats/libsvm__desc.md -->
The input training dataset in the form of a two-dimensional sparse feature matrix.
<!-- endsource: en/_includes/work_src/reusage-formats/libsvm__desc.md -->

{% endcut %}


**Default value**

Required parameter

**Supported processing units**

 CPU and GPU

### y

#### Description

<!-- source: en/_includes/work_src/reusage/label--short-desc-training.md -->
The target variables (in other words, the objects' label values) for the training dataset.
<!-- endsource: en/_includes/work_src/reusage/label--short-desc-training.md -->

<!-- source: en/_includes/work_src/reusage/label--detailed-desc-regression.md -->
Must be in the form of a one- or two- dimensional array. The type of data in the array depends on the machine learning task being solved:
- Regression — One-dimensional array of numeric values.
- Multiregression - Two-dimensional array of numeric values. The first index is for a dimension, the second index is for an object.
<!-- endsource: en/_includes/work_src/reusage/label--detailed-desc-regression.md -->

{% note info %}

Do not use this parameter if the input training dataset (specified in the `X` parameter) type is catboost.Pool.

{% endnote %}

<!-- source: en/_includes/work_src/reusage/label--possible-types-default-supported-processing-units.md -->
**Possible types**

- list
- numpy.ndarray
- pandas.DataFrame
- pandas.Series
- [polars.Series](https://docs.pola.rs/api/python/stable/reference/series/index.html)
- [polars.DataFrame](https://docs.pola.rs/api/python/stable/reference/dataframe/index.html)

**Default value**

None

**Supported processing units**

CPU and GPU
<!-- endsource: en/_includes/work_src/reusage/label--possible-types-default-supported-processing-units.md -->


### cat_features

#### Description

A one-dimensional array of categorical columns indices.

Use it only if the `X` parameter is a two-dimensional feature matrix (has one of the following types: list, numpy.ndarray, pandas.DataFrame, pandas.Series), polars.DataFrame.

{% note info %}

The `cat_features` parameter can also be specified in the constructor of the class. If it is, CatBoost checks the equivalence of the `cat_features` parameter specified in this method and in the constructor of the class.

{% endnote %}

**Possible types**

- list
- numpy.ndarray

**Default value**

<!-- source: en/_includes/concepts/default-value-none.md -->
**Default value**

None (all features are either considered numerical or of other types if specified precisely)
<!-- endsource: en/_includes/concepts/default-value-none.md -->

**Supported processing units**

CPU and GPU


### text_features

#### Description

A one-dimensional array of text columns indices (specified as integers) or names (specified as strings).

<!-- source: en/_includes/work_src/reusage/python__cat_features__description__non-catfeatures-text.md -->
Use only if the `data` parameter is a two-dimensional feature matrix (has one of the following types: list, numpy.ndarray, pandas.DataFrame, pandas.Series), polars.DataFrame.

If any elements in this array are specified as names instead of indices, names for all columns must be provided. To do this, either use the `feature_names` parameter of this constructor to explicitly specify them or pass a pandas.DataFrame, polars.DataFrame with column names specified in the `data` parameter.
<!-- endsource: en/_includes/work_src/reusage/python__cat_features__description__non-catfeatures-text.md -->


**Possible types**

- list
- numpy.ndarray

**Default value**

None (all features are either considered numerical or of other types if specified precisely)

**Supported processing units**

<!-- source: en/_includes/work_src/reusage-python/cpu-and-gpu.md -->
CPU and GPU
<!-- endsource: en/_includes/work_src/reusage-python/cpu-and-gpu.md -->



### embedding_features

#### Description

A one-dimensional array of embedding columns indices (specified as integers) or names (specified as strings).

<!-- source: en/_includes/work_src/reusage/python__cat_features__description__non-catfeatures-text.md -->
Use only if the `data` parameter is a two-dimensional feature matrix (has one of the following types: list, numpy.ndarray, pandas.DataFrame, pandas.Series), polars.DataFrame.

If any elements in this array are specified as names instead of indices, names for all columns must be provided. To do this, either use the `feature_names` parameter of this constructor to explicitly specify them or pass a pandas.DataFrame, polars.DataFrame with column names specified in the `data` parameter.
<!-- endsource: en/_includes/work_src/reusage/python__cat_features__description__non-catfeatures-text.md -->

**Possible types**

- list
- numpy.ndarray

**Default value**

<!-- source: en/_includes/concepts/default-value-none.md -->
**Default value**

None (all features are either considered numerical or of other types if specified precisely)
<!-- endsource: en/_includes/concepts/default-value-none.md -->

**Supported processing units**

CPU and GPU


### sample_weight

#### Description

<!-- source: en/_includes/work_src/reusage/python__weight__short-desc-intro.md -->
The weight of each object in the input data in the form of a one-dimensional array-like data.
<!-- endsource: en/_includes/work_src/reusage/python__weight__short-desc-intro.md -->


<!-- source: en/_includes/work_src/reusage/python__weight__short-desc__outro.md -->
By default, it is set to 1 for all objects.
<!-- endsource: en/_includes/work_src/reusage/python__weight__short-desc__outro.md -->

**Possible types**

- list
- numpy.ndarray
- pandas.DataFrame
- pandas.Series
- [polars.Series](https://docs.pola.rs/api/python/stable/reference/series/index.html)

**Default value**

None

**Supported processing units**

CPU and GPU

### baseline

#### Description

<!-- source: en/_includes/work_src/reusage/baseline--short-desc1.md -->
Array of formula values for all input objects. The training starts from these values for all input objects instead of starting from zero.
<!-- endsource: en/_includes/work_src/reusage/baseline--short-desc1.md -->


{% note info %}

Do not use this parameter if the input training dataset (specified in the `X` parameter) type is catboost.Pool.

{% endnote %}

**Possible types**

- list
- numpy.ndarray
- [polars.Series](https://docs.pola.rs/api/python/stable/reference/series/index.html)
- [polars.DataFrame](https://docs.pola.rs/api/python/stable/reference/dataframe/index.html)

**Default value**

None

**Supported processing units**

CPU and GPU

### use_best_model

#### Description

If this parameter is set, the number of trees that are saved in the resulting model is defined as follows:
1. Build the number of trees defined by the training parameters.
1. Use the validation dataset to identify the iteration with the optimal value of the metric specified in  `--eval-metric` (`--eval-metric`).

No trees are saved after this iteration.

This option requires a validation dataset to be provided.

**Possible types**

bool

**Default value**

True if validation sets are specified (the `eval_set` parameter is defined) and at least one of the label values of objects in the last validation dataset differs from the others. False otherwise.

**Supported processing units**

CPU and GPU

### eval_set

#### Description

The validation dataset or datasets used for the following processes:
- [overfitting detector](https://catboost.ai/docs/en/concepts/overfitting-detector.md)
- the best iteration selection
- monitoring metrics' changes

**Default value**

- catboost.Pool
- list of catboost.Pool
- tuple (X, y)
- list of tuples (X, y)
- string (path to the dataset file)
- list of strings (paths to dataset files)

**Default value**

None

**Supported processing units**

CPU and GPU


{% note info %}

GPU training does not support multiple validation datasets for now

{% endnote %}


### verbose

_Alias:_`verbose_eval`

#### Description

<!-- source: en/_includes/work_src/reusage/python__feature-importances__verbose__short-description__list-intro.md -->
The purpose of this parameter depends on the type of the given value:
<!-- endsource: en/_includes/work_src/reusage/python__feature-importances__verbose__short-description__list-intro.md -->


- bool — Defines the logging level:
    - <q>True</q>  corresponds to the Verbose logging level
    - <q>False</q> corresponds to the Silent logging level

- int — Use the Verbose logging level and set the logging period to the value of this parameter.

{% note alert %}

Do not use this parameter with the `logging_level` parameter.

{% endnote %}

**Possible types**

- bool
- int

**Default value**

1

**Supported processing units**

CPU and GPU


### logging_level

#### Description

The logging level to output to stdout.

Possible values:
- Silent — Do not output any logging information to stdout.

- Verbose — Output the following data to stdout:

    - optimized metric
    - elapsed time of training
    - remaining time of training

- Info — Output additional information and the number of trees.

- Debug — Output debugging information.


**Possible types**

string

**Default value**

None (corresponds to the Verbose logging level)

**Supported processing units**

CPU and GPU

### plot

#### Description

Plot the following information during training:
- the metric values;
- the custom loss values;
- the loss function change during feature selection;
- the time has passed since training started;
- the remaining time until the end of training.
This [option can be used](https://catboost.ai/docs/en/features/visualization_jupyter-notebook.md) if training is performed in Jupyter notebook.


**Possible types**

bool

**Default value**

False

**Supported processing units**

<!-- source: en/_includes/work_src/reusage-python/cpu.md -->
CPU
<!-- endsource: en/_includes/work_src/reusage-python/cpu.md -->


### plot_file

#### Description

Save a plot with the training progress information (metric values, custom loss values) to the file specified by this parameter.

**Possible types**

File-like object or string

**Default value**

None

**Supported processing units**

<!-- source: en/_includes/work_src/reusage-python/cpu-and-gpu.md -->
CPU and GPU
<!-- endsource: en/_includes/work_src/reusage-python/cpu-and-gpu.md -->


### column_description

#### Description

<!-- source: en/_includes/work_src/reusage/cd-short-desct.md -->
The path to the input file  that contains the [columns description](https://catboost.ai/docs/en/concepts/input-data_column-descfile.md).
<!-- endsource: en/_includes/work_src/reusage/cd-short-desct.md -->


The given file is used to build pools from the train and/or validation datasets, which are input from files.

**Possible types**

string

**Default value**

None

**Supported processing units**

CPU and GPU

### metric_period

#### Description

The frequency of iterations to calculate the values of [objectives and metrics](https://catboost.ai/docs/en/concepts/loss-functions.md). The value should be a positive integer.

The usage of this parameter speeds up the training.

{% note info %}

It is recommended to increase the value of this parameter to maintain training speed if a GPU processing unit type is used.

{% endnote %}

**Possible types**

int

**Default value**

1

**Supported processing units**

CPU and GPU


### silent

#### Description

Defines the logging level:
- <q>True</q> — corresponds to the Silent logging level
- <q>False</q> — corresponds to the Verbose logging level

**Possible types**

bool

**Default value**

False

**Supported processing units**

CPU and GPU


### early_stopping_rounds

#### Description

Sets the overfitting detector type to Iter and stops the training after the specified number of iterations since the iteration with the optimal metric value.

**Possible types**

int

**Default value**

False

**Supported processing units**

CPU and GPU


### save_snapshot

#### Description

Enable snapshotting for [restoring the training progress after an interruption](https://catboost.ai/docs/en/features/snapshots.md). If enabled, the default period for making snapshots is 600 seconds. Use the `snapshot_interval` parameter to change this period.

<!-- source: en/_includes/work_src/reusage-common-phrases/snapshot-not-working-for-cv.md -->
{% note info %}

This parameter is not supported in the `params` parameter of the [cv](https://catboost.ai/docs/en/concepts/python-reference_cv.md) function.

{% endnote %}
<!-- endsource: en/_includes/work_src/reusage-common-phrases/snapshot-not-working-for-cv.md -->

**Possible types**

bool

**Default value**

None

**Supported processing units**

CPU and GPU


### snapshot_file

#### Description

The name of the file to save the training progress information in. This file is used for [recovering training after an interruption](https://catboost.ai/docs/en/features/snapshots.md).

<!-- source: en/_includes/work_src/reusage/snapshot-filename-desc.md -->
Depending on whether the specified file 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.
<!-- endsource: en/_includes/work_src/reusage/snapshot-filename-desc.md -->


<!-- source: en/_includes/work_src/reusage-common-phrases/snapshot-not-working-for-cv.md -->
{% note info %}

This parameter is not supported in the `params` parameter of the [cv](https://catboost.ai/docs/en/concepts/python-reference_cv.md) function.

{% endnote %}
<!-- endsource: en/_includes/work_src/reusage-common-phrases/snapshot-not-working-for-cv.md -->

**Possible types**

string

**Default value**

experiment.cbsnapshot

**Supported processing units**

CPU and GPU


### snapshot_interval

#### Description

The interval between saving snapshots in seconds.

The first snapshot is taken after the specified number of seconds since the start of training. Every subsequent snapshot is taken after the specified number of seconds since the previous one. The last snapshot is taken at the end of the training.

<!-- source: en/_includes/work_src/reusage-common-phrases/snapshot-not-working-for-cv.md -->
{% note info %}

This parameter is not supported in the `params` parameter of the [cv](https://catboost.ai/docs/en/concepts/python-reference_cv.md) function.

{% endnote %}
<!-- endsource: en/_includes/work_src/reusage-common-phrases/snapshot-not-working-for-cv.md -->

**Possible types**

int

**Default value**

600
**Supported processing units**

CPU and GPU


### init_model

#### Description

The description is different for each group of possible types.

**Possible types**

The model to continue learning from.

{% note info %}

The initial model must have the same problem type as the one being solved in the current training (binary classification, multiclassification or regression/ranking).

{% endnote %}


{% cut "[catboost.CatBoost](https://catboost.ai/docs/en/concepts/python-reference_catboost.md), [catboost.CatBoostRegressor](https://catboost.ai/docs/en/concepts/python-reference_catboostregressor.md)" %}

The initial model object.

{% endcut %}


{% cut "string" %}

The path to the input file that contains the initial model.

{% endcut %}


**Default value**

None (incremental learning is not used)

**Supported processing units**

CPU

<!-- source: en/_includes/work_src/reusage-python/python__log-params.md -->
###  log_cout

Output stream or callback for logging.

**Possible types**

- callable Python object
- python object providing the `write()` method

**Default value**

sys.stdout

###  log_cerr

Error stream or callback for logging.

**Possible types**

- callable Python object
- python object providing the `write()` method

**Default value**

sys.stderr
<!-- endsource: en/_includes/work_src/reusage-python/python__log-params.md -->
