---
metadata:
  - name: generator
    content: Diplodoc Platform v5.50.3
alternate:
  - https://catboost.ai/docs/en/concepts/python-reference_catboostclassifier_get_best_iteration.md
---
> **Documentation Index:** Fetch the complete configuration index at https://catboost.ai/docs/en/llms.txt

# get_best_iteration

<!-- source: en/_includes/work_src/reusage/python__method__get_best_iteration__desc.md -->
Return the identifier of the iteration with the best result of the evaluation metric or loss function on the last validation set.
<!-- endsource: en/_includes/work_src/reusage/python__method__get_best_iteration__desc.md -->


## Method call format {#call-format}

```no-highlight
get_best_iteration()
```

## Type of return value {#output-format}

<!-- source: en/_includes/work_src/reusage/python__method__get_best_iteration__type__p.md -->
int or None if the validation dataset is not specified.
<!-- endsource: en/_includes/work_src/reusage/python__method__get_best_iteration__type__p.md -->


## Usage examples {#usage-examples}

<!-- source: en/_includes/work_src/reusage/python__method__get_best_iteration__usage-example__div.md -->
```python
from catboost import CatBoostClassifier, Pool

train_data = [[0, 3],
              [4, 1],
              [8, 1],
              [9, 1]]

train_labels = [0, 0, 1, 1]

eval_data = [[2, 1],
             [3, 1],
             [9, 0],
             [5, 3]]

eval_labels = [0, 1, 1, 0]

eval_dataset = Pool(eval_data,
                    eval_labels)

model = CatBoostClassifier(learning_rate=0.03,
                           eval_metric='AUC')

model.fit(train_data,
          train_labels,
          eval_set=eval_dataset,
          verbose=False)

print(model.get_best_iteration())

```
<!-- endsource: en/_includes/work_src/reusage/python__method__get_best_iteration__usage-example__div.md -->

