---
metadata:
  - name: generator
    content: Diplodoc Platform v5.52.0
alternate:
  - https://catboost.ai/docs/en/concepts/python-reference_utils_get_confusion_matrix.md
  - href: en/concepts/python-reference_utils_get_confusion_matrix.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

# get_confusion_matrix

<!-- source: en/_includes/work_src/reusage-python/get_confusion_matrix__desc.md -->
Build a confusion matrix $C$, such that $C_{i,j}$ is equal to the number of observations known to be in group $i$ but predicted to be in group $j$.
<!-- endsource: en/_includes/work_src/reusage-python/get_confusion_matrix__desc.md -->


## Method call format {#method-call-format}

```python
get_confusion_matrix(model, data, thread_count)
```

## Parameters {#parameters-list}

### model

#### Description

The trained model.

**Possible types**

catboost.CatBoost

**Default value**

Required parameter

### data

#### Description

A set of samples to build the confusion matrix with.

**Possible types**

catboost.Pool

**Default value**

Required parameter

### thread_count

#### Description

The number of threads to use.

**Possible types**

int

**Default value**

-1 (the number of threads is set to the number of CPU cores)


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

confusion matrix : array, shape = [n_classes, n_classes]

## Examples {#examples}

#### Multiclassification

```python
from catboost import Pool, CatBoostClassifier
from catboost.utils import get_confusion_matrix

train_data = [[1, 1924, 44],
              [1, 1932, 37],
              [0, 1980, 37],
              [1, 2012, 204]]

train_label = ["France", "USA", "USA", "UK"]

train_dataset = Pool(data=train_data,
                     label=train_label)

model = CatBoostClassifier(loss_function='MultiClass',
                           iterations=100,
                           verbose=False)

model.fit(train_dataset)

cm = get_confusion_matrix(model, Pool(train_data, train_label))
print(cm)

```

Output:

```bash
[[1. 0. 0.]
 [0. 1. 0.]
 [0. 0. 2.]]
```

#### Binary classification

```python
from catboost import Pool, CatBoostClassifier
from catboost.utils import get_confusion_matrix

train_data = [[1, 1924, 44],
              [1, 1932, 37],
              [0, 1980, 37],
              [1, 2012, 204]]

train_label = [0, 1, 1, 0]

train_dataset = Pool(data=train_data,
                     label=train_label)

model = CatBoostClassifier(loss_function='Logloss',
                           iterations=100,
                           verbose=False)

model.fit(train_dataset)

cm = get_confusion_matrix(model, Pool(train_data, train_label))
print(cm)

```

Output:

```bash
[[2. 0.]
 [0. 2.]]
```

