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

# Classification: objectives and metrics

- [Objectives and metrics](#objectives-and-metrics)
- [Used for optimization](#usage-information)

## Objectives and metrics

### Logloss {#Logit}

$\displaystyle\frac{ - \sum\limits_{i=1}^N w_{i}\left(c_i \log(p_{i}) + (1-c_{i}) \log(1 - p_{i})\right)}{\sum\limits_{i = 1}^{N} w_{i}}$

**Usage information**  See [more](#usage-information).

**User-defined parameters**

<!-- source: en/_includes/work_src/reusage-loss-functions/use-weights__desc__with__default__value.md -->
{% cut "use_weights" %}

Use object/group weights to calculate metrics if the specified value is <q>true</q> and set all weights to <q>1</q> regardless of the input data if the specified value is <q>false</q>.

_Default:_ true

{% endcut %}
<!-- endsource: en/_includes/work_src/reusage-loss-functions/use-weights__desc__with__default__value.md -->


### CrossEntropy {#CrossEntropy}

$\displaystyle\frac{- \sum\limits_{i=1}^N w_{i} \left(t_{i} \log(p_{i}) + (1 - t_{i}) \log(1 - p_{i})\right)}{\sum\limits_{i = 1}^{N} w_{i}}$

**Usage information**  See [more](#usage-information).

**User-defined parameters**

<!-- source: en/_includes/work_src/reusage-loss-functions/use-weights__desc__with__default__value.md -->
{% cut "use_weights" %}

Use object/group weights to calculate metrics if the specified value is <q>true</q> and set all weights to <q>1</q> regardless of the input data if the specified value is <q>false</q>.

_Default:_ true

{% endcut %}
<!-- endsource: en/_includes/work_src/reusage-loss-functions/use-weights__desc__with__default__value.md -->


### Precision {#Precision}

$\frac{TP}{TP + FP}$

**Can't be used for optimization.**  See [more](#usage-information).

**User-defined parameters**

<!-- source: en/_includes/work_src/reusage-loss-functions/use-weights__desc__with__default__value.md -->
{% cut "use_weights" %}

Use object/group weights to calculate metrics if the specified value is <q>true</q> and set all weights to <q>1</q> regardless of the input data if the specified value is <q>false</q>.

_Default:_ true

{% endcut %}
<!-- endsource: en/_includes/work_src/reusage-loss-functions/use-weights__desc__with__default__value.md -->


### Recall {#Recall}

$\frac{TP}{TP+FN}$

**Can't be used for optimization.**  See [more](#usage-information).

**User-defined parameters**

<!-- source: en/_includes/work_src/reusage-loss-functions/use-weights__desc__with__default__value.md -->
{% cut "use_weights" %}

Use object/group weights to calculate metrics if the specified value is <q>true</q> and set all weights to <q>1</q> regardless of the input data if the specified value is <q>false</q>.

_Default:_ true

{% endcut %}
<!-- endsource: en/_includes/work_src/reusage-loss-functions/use-weights__desc__with__default__value.md -->


### F {#F}

$(1 + \beta^2) \cdot  \frac{Precision * Recall}{(\beta^2 \cdot Precision) + Recall}$

**Can't be used for optimization.**  See [more](#usage-information).

**User-defined parameters**

<!-- source: en/_includes/work_src/reusage-loss-functions/beta_for_F__desc.md -->
{% cut "beta" %}

The $\beta$ parameter of the F metric.

Valid values are real numbers in the following range:  $(0; +\infty)$.

_Default:_ This parameter is obligatory (the default value is not defined)

{% endcut %}
<!-- endsource: en/_includes/work_src/reusage-loss-functions/beta_for_F__desc.md -->

<!-- source: en/_includes/work_src/reusage-loss-functions/use-weights__desc__with__default__value.md -->
{% cut "use_weights" %}

Use object/group weights to calculate metrics if the specified value is <q>true</q> and set all weights to <q>1</q> regardless of the input data if the specified value is <q>false</q>.

_Default:_ true

{% endcut %}
<!-- endsource: en/_includes/work_src/reusage-loss-functions/use-weights__desc__with__default__value.md -->


### F1 {#F1}

$2 \frac{Precision * Recall}{Precision + Recall}$

**Can't be used for optimization.**  See [more](#usage-information).

**User-defined parameters**

<!-- source: en/_includes/work_src/reusage-loss-functions/use-weights__desc__with__default__value.md -->
{% cut "use_weights" %}

Use object/group weights to calculate metrics if the specified value is <q>true</q> and set all weights to <q>1</q> regardless of the input data if the specified value is <q>false</q>.

_Default:_ true

{% endcut %}
<!-- endsource: en/_includes/work_src/reusage-loss-functions/use-weights__desc__with__default__value.md -->

### BalancedAccuracy {#BalancedAccuracy}

$\frac{1}{2} \left(\frac{TP}{P} + \frac{TN}{N} \right)$
User-defined parameters:

**Can't be used for optimization.**  See [more](#usage-information).

**User-defined parameters**

<!-- source: en/_includes/work_src/reusage-loss-functions/use-weights__desc__with__default__value.md -->
{% cut "use_weights" %}

Use object/group weights to calculate metrics if the specified value is <q>true</q> and set all weights to <q>1</q> regardless of the input data if the specified value is <q>false</q>.

_Default:_ true

{% endcut %}
<!-- endsource: en/_includes/work_src/reusage-loss-functions/use-weights__desc__with__default__value.md -->

### BalancedErrorRate {#BalancedErrorRate}

$\frac{1}{2} \left( \displaystyle\frac{FP}{TN + FP} + \displaystyle\frac{FN}{FN + TP} \right)$

**Can't be used for optimization.**  See [more](#usage-information).

**User-defined parameters**

<!-- source: en/_includes/work_src/reusage-loss-functions/use-weights__desc__with__default__value.md -->
{% cut "use_weights" %}

Use object/group weights to calculate metrics if the specified value is <q>true</q> and set all weights to <q>1</q> regardless of the input data if the specified value is <q>false</q>.

_Default:_ true

{% endcut %}
<!-- endsource: en/_includes/work_src/reusage-loss-functions/use-weights__desc__with__default__value.md -->


### MCC {#MCC}

$\displaystyle\frac{TP * TN - FP * FN}{\sqrt{(TP + FP)(TP + FN)(TN + FP)(TN + FN)}}$

**Can't be used for optimization.**  See [more](#usage-information).

**User-defined parameters**

<!-- source: en/_includes/work_src/reusage-loss-functions/use-weights__desc__with__default__value.md -->
{% cut "use_weights" %}

Use object/group weights to calculate metrics if the specified value is <q>true</q> and set all weights to <q>1</q> regardless of the input data if the specified value is <q>false</q>.

_Default:_ true

{% endcut %}
<!-- endsource: en/_includes/work_src/reusage-loss-functions/use-weights__desc__with__default__value.md -->


### Accuracy {#Accuracy}

$\frac{TP + TN}{\sum\limits_{i=1}^{N} w_{i}}$

**Can't be used for optimization.**  See [more](#usage-information).

**User-defined parameters**

<!-- source: en/_includes/work_src/reusage-loss-functions/use-weights__desc__with__default__value.md -->
{% cut "use_weights" %}

Use object/group weights to calculate metrics if the specified value is <q>true</q> and set all weights to <q>1</q> regardless of the input data if the specified value is <q>false</q>.

_Default:_ true

{% endcut %}
<!-- endsource: en/_includes/work_src/reusage-loss-functions/use-weights__desc__with__default__value.md -->


### CtrFactor {#CtrFactor}

$\displaystyle\frac{\left(\sum\limits_{i = 1}^{N} w_{i} t_{i}/N\right)}{\left(\sum\limits_{i = 1}^{N} w_{i} p_{i} /N\right)}$

**Can't be used for optimization.**  See [more](#usage-information).

**User-defined parameters**

<!-- source: en/_includes/work_src/reusage-loss-functions/use-weights__desc__with__default__value.md -->
{% cut "use_weights" %}

Use object/group weights to calculate metrics if the specified value is <q>true</q> and set all weights to <q>1</q> regardless of the input data if the specified value is <q>false</q>.

_Default:_ true

{% endcut %}
<!-- endsource: en/_includes/work_src/reusage-loss-functions/use-weights__desc__with__default__value.md -->

### AUC {#AUC}

The calculation of this metric is disabled by default for the training dataset to speed up the training. Use the `hints=skip_train~false` parameter to enable the calculation.

#### Classic

$\displaystyle\frac{\sum I(a_{i}, a_{j}) \cdot w_{i} \cdot w_{j}} {\sum w_{i} \cdot w_{j}}$
The sum is calculated on all pairs of objects $(i,j)$ such that:
- $t_{i} = 0$
- $t_{j} = 1$
- $I(x, y) = \begin{cases} 0 { , } & x < y \\ 0.5 { , } & x=y \\ 1 { , } & x>y \end{cases}$

Refer to the [Wikipedia article](https://en.wikipedia.org/wiki/Receiver_operating_characteristic#Area_under_the_curve) for details.

If the target type is not binary, then every object with target value $t$ and weight $w$ is replaced with two objects for the metric calculation:

- $o_{1}$ with weight $t \cdot w$ and target value 1
- $o_{2}$ with weight $(1 – t) \cdot w$ and target value 0.

Target values must be in the range [0; 1].

#### Ranking

$\displaystyle\frac{\sum I(a_{i}, a_{j}) \cdot w_{i} \cdot w_{j}} {\sum w_{i} * w_{j}}$

The sum is calculated on all pairs of objects $(i,j)$ such that:
- $t_{i} < t_{j}$
- $I(x, y) = \begin{cases} 0 { , } & x < y \\ 0.5 { , } & x=y \\ 1 { , } & x>y \end{cases}$

**User-defined parameters**

{% cut "type" %}

<!-- source: en/_includes/work_src/reusage-loss-functions/type_of_auc__p.md -->
The type of AUC. Defines the metric calculation principles.
<!-- endsource: en/_includes/work_src/reusage-loss-functions/type_of_auc__p.md -->

_Default_: `Ranking`.
_Possible values:_ `Classic`, `Ranking`.
_Examples:_ `AUC:type=Classic`, `AUC:type=Ranking`.

{% endcut %}

{% cut "use_weights" %}

<!-- source: en/_includes/work_src/reusage-loss-functions/use-weights__desc__without__note.md -->
Use object/group weights to calculate metrics if the specified value is <q>true</q> and set all weights to <q>1</q> regardless of the input data if the specified value is <q>false</q>.
<!-- endsource: en/_includes/work_src/reusage-loss-functions/use-weights__desc__without__note.md -->

_Default_: `False`.
_Examples_: `QueryAUC:type=Ranking;use_weights=False`.

{% endcut %}

<!-- source: en/_includes/concepts/query-auc.md -->
### QueryAUC {#QueryAUC}

#### Classic type

$\displaystyle\frac{ \sum_q \sum_{i, j \in q}  \sum I(a_{i}, a_{j}) \cdot w_{i} \cdot w_{j}} { \sum_q \sum_{i, j \in q}
\sum w_{i} \cdot w_{j}}$
The sum is calculated on all pairs of objects $(i,j)$ such that:
- $t_{i} = 0$
- $t_{j} = 1$
- $I(x, y) = \begin{cases} 0 { , } & x < y \\ 0.5 { , } & x=y \\ 1 { , } & x>y \end{cases}$

Refer to the [Wikipedia article](https://en.wikipedia.org/wiki/Receiver_operating_characteristic#Area_under_the_curve) for details.

If the target type is not binary, then every object with target value $t$ and weight $w$ is replaced with two objects for the metric calculation:

- $o_{1}$ with weight $t \cdot w$ and target value 1
- $o_{2}$ with weight $(1 – t) \cdot w$ and target value 0.

Target values must be in the range [0; 1].

#### Ranking type

$\displaystyle\frac{ \sum_q \sum_{i, j \in q}  \sum I(a_{i}, a_{j}) \cdot w_{i} \cdot w_{j}} { \sum_q \sum_{i, j \in q} \sum w_{i} * w_{j}}$

The sum is calculated on all pairs of objects $(i,j)$ such that:
- $t_{i} < t_{j}$
- $I(x, y) = \begin{cases} 0 { , } & x < y \\ 0.5 { , } & x=y \\ 1 { , } & x>y \end{cases}$

**Can't be used for optimization.** See [more](#optimization).

**User-defined parameters**

{% cut "type" %}

The type of QueryAUC. Defines the metric calculation principles.

_Default_: `Ranking`.
_Possible values_: `Classic`, `Ranking`.
_Examples_: `QueryAUC:type=Classic`, `QueryAUC:type=Ranking`.

{% endcut %}

{% cut "use_weights" %}

<!-- source: en/_includes/work_src/reusage-loss-functions/use-weights__desc__without__note.md -->
Use object/group weights to calculate metrics if the specified value is <q>true</q> and set all weights to <q>1</q> regardless of the input data if the specified value is <q>false</q>.
<!-- endsource: en/_includes/work_src/reusage-loss-functions/use-weights__desc__without__note.md -->

_Default_: `False`.
_Examples_: `QueryAUC:type=Ranking;use_weights=False`.

{% endcut %}
<!-- endsource: en/_includes/concepts/query-auc.md -->

<!-- source: en/_includes/concepts/pr-auc.md -->
### PRAUC {#PRAUC}

PRAUC is the area under the curve $Precision(q)$ vs $Recall(q)$ for $q \in [0,1]$ where $Precision(q)$ and $Recall(q)$ are defined as follows.
$$Precision(q) = \frac{TP(q)}{TP(q) + FP(q)}, Recall(q) = \frac{TP(q)}{TP(q) + FN(q)}$$

Above $TP(q)$, $FP(q)$, $FN(q)$ are weights of the true positive, false positive, and false negative samples, respectively.

To calculate PRAUC for a binary classification model, specify type `Classic`.
In this case, $TP(q)=\sum w_i [p_i > q] c_i$, etc.

To calculate PRAUC for a multi-classification model, specify type `OneVsAll`.
In this case, positive samples are samples having class 0, all other samples are negative, and $TP(q)=\sum w_i [p_{i0} > q] [c_i = 0]$, etc.

{% cut "type" %}

The type of PRAUC. Defines the metric calculation principles.

Type `Classic` is compatible with binary classification models.
Type `OneVsAll` is compatible with multi-classification models.

_Default_: `Classic`.
_Possible values_: `Classic`, `OneVsAll`.
_Examples_: `PRAUC:type=Classic`, `PRAUC:type=OneVsAll`.

{% endcut %}

{% cut "use_weights" %}

<!-- source: en/_includes/work_src/reusage-loss-functions/use-weights__desc__without__note.md -->
Use object/group weights to calculate metrics if the specified value is <q>true</q> and set all weights to <q>1</q> regardless of the input data if the specified value is <q>false</q>.
<!-- endsource: en/_includes/work_src/reusage-loss-functions/use-weights__desc__without__note.md -->

_Default_: `False`.
_Examples_: `PRAUC:type=Classic;use_weights=False`.

{% endcut %}
<!-- endsource: en/_includes/concepts/pr-auc.md -->

### NormalizedGini {#NormalizedGini}

See AUC.

$2 AUC - 1$

**Can't be used for optimization.**  See [more](#usage-information).

**User-defined parameters**

<!-- source: en/_includes/work_src/reusage-loss-functions/use-weights__desc__with__default__value.md -->
{% cut "use_weights" %}

Use object/group weights to calculate metrics if the specified value is <q>true</q> and set all weights to <q>1</q> regardless of the input data if the specified value is <q>false</q>.

_Default:_ true

{% endcut %}
<!-- endsource: en/_includes/work_src/reusage-loss-functions/use-weights__desc__with__default__value.md -->


### BrierScore {#Brierscore}

$\displaystyle\frac{\sum\limits_{i=1}^{N} w_{i}\left(p_{i} - t_{i} \right)^{2}}{\sum\limits_{i=1}^{N} w_{i}}$

**Can't be used for optimization.**  See [more](#usage-information).

**User-defined parameters**

<!-- source: en/_includes/work_src/reusage-loss-functions/use-weights__desc__with__default__value.md -->
{% cut "use_weights" %}

Use object/group weights to calculate metrics if the specified value is <q>true</q> and set all weights to <q>1</q> regardless of the input data if the specified value is <q>false</q>.

_Default:_ true

{% endcut %}
<!-- endsource: en/_includes/work_src/reusage-loss-functions/use-weights__desc__with__default__value.md -->

### HingeLoss {#HingeLoss}

$\displaystyle\frac{\sum\limits_{i=1}^{N} w_{i} max\{1 - t_{i} p_{i}, 0\}}{\sum\limits_{i=1}^{N} w_{i}} , t_{i} = \pm 1$

**Can't be used for optimization.**  See [more](#usage-information).

**User-defined parameters**

<!-- source: en/_includes/work_src/reusage-loss-functions/use-weights__desc__with__default__value.md -->
{% cut "use_weights" %}

Use object/group weights to calculate metrics if the specified value is <q>true</q> and set all weights to <q>1</q> regardless of the input data if the specified value is <q>false</q>.

_Default:_ true

{% endcut %}
<!-- endsource: en/_includes/work_src/reusage-loss-functions/use-weights__desc__with__default__value.md -->


### HammingLoss {#HammingLoss}

$\displaystyle\frac{\sum\limits_{i = 1}^{N} w_{i} [[p_{i} > 0.5] == t_{i}]]}{\sum\limits_{i=1}^{N} w_{i}}$

**Can't be used for optimization.**  See [more](#usage-information).

**User-defined parameters**

<!-- source: en/_includes/work_src/reusage-loss-functions/use-weights__desc__with__default__value.md -->
{% cut "use_weights" %}

Use object/group weights to calculate metrics if the specified value is <q>true</q> and set all weights to <q>1</q> regardless of the input data if the specified value is <q>false</q>.

_Default:_ true

{% endcut %}
<!-- endsource: en/_includes/work_src/reusage-loss-functions/use-weights__desc__with__default__value.md -->


### ZeroOneLoss {#ZeroOneLoss}

$1 - Accuracy$

**Can't be used for optimization.**  See [more](#usage-information).

**User-defined parameters**

<!-- source: en/_includes/work_src/reusage-loss-functions/use-weights__desc__with__default__value.md -->
{% cut "use_weights" %}

Use object/group weights to calculate metrics if the specified value is <q>true</q> and set all weights to <q>1</q> regardless of the input data if the specified value is <q>false</q>.

_Default:_ true

{% endcut %}
<!-- endsource: en/_includes/work_src/reusage-loss-functions/use-weights__desc__with__default__value.md -->


### Kappa {#Kappa}

$1 - \displaystyle\frac{1 - Accuracy}{1 - RAccuracy}$

$RAccuracy = \displaystyle\frac{(TN + FP) (TN + FN) + (FN + TP) (FP + TP)}{(\sum\limits_{i=1}^{N} w_{i})^{2}}$

**Can't be used for optimization.**  See [more](#usage-information).

**User-defined parameters**

<!-- source: en/_includes/work_src/reusage-loss-functions/use-weights__desc__with__default__value.md -->
{% cut "use_weights" %}

Use object/group weights to calculate metrics if the specified value is <q>true</q> and set all weights to <q>1</q> regardless of the input data if the specified value is <q>false</q>.

_Default:_ true

{% endcut %}
<!-- endsource: en/_includes/work_src/reusage-loss-functions/use-weights__desc__with__default__value.md -->


### WKappa {#WKappa}

See the formula on page 3 of the [A note on the linearly weighted kappa coefficient for ordinal scales](https://orbi.uliege.be/bitstream/2268/2262/1/STATMED-174.pdf) paper.

**Can't be used for optimization.**  See [more](#usage-information).

**User-defined parameters**

<!-- source: en/_includes/work_src/reusage-loss-functions/use-weights__desc__with__default__value.md -->
{% cut "use_weights" %}

Use object/group weights to calculate metrics if the specified value is <q>true</q> and set all weights to <q>1</q> regardless of the input data if the specified value is <q>false</q>.

_Default:_ true

{% endcut %}
<!-- endsource: en/_includes/work_src/reusage-loss-functions/use-weights__desc__with__default__value.md -->


### LogLikelihoodOfPrediction {#LLP}

The calculation consists of the following steps:

1. Define the sum of weights ($W$) and the mean target ($\bar{t}$):

    $W = \sum\limits_{i} w_{i}$

    $\bar{t} = \frac{1}{W} \sum\limits_{i} t_{i} w_{i}$

1. Denote log-likelihood of a constant prediction:

    $ll_0 = \sum\limits_{i} w_{i} (\bar{t} \cdot log(\bar{t}) + (1 - \bar{t}) \cdot log(1 - \bar{t}))$

1. Calculate LogLikelihoodOfPrediction ($llp$), which reflects how the likelihood ($ll$) differs from the constant prediction:

    $llp = \displaystyle\frac{ll(t, w) - ll_0}{\sum\limits_{i} t_{i} w_{i}}$

**Can't be used for optimization.**  See [more](#usage-information).

**User-defined parameters**

<!-- source: en/_includes/work_src/reusage-loss-functions/use-weights__desc__with__default__value.md -->
{% cut "use_weights" %}

Use object/group weights to calculate metrics if the specified value is <q>true</q> and set all weights to <q>1</q> regardless of the input data if the specified value is <q>false</q>.

_Default:_ true

{% endcut %}
<!-- endsource: en/_includes/work_src/reusage-loss-functions/use-weights__desc__with__default__value.md -->



## Used for optimization {#usage-information}


| Name                                                        | Optimization            | GPU Support             |
--------------------------------------------------------------|-------------------------|-------------------------|
[Logloss](#Logit)                         |     +                   |     +                   |
[CrossEntropy](#CrossEntropy)           |     +                   |     +                   |
[Precision](#Precision)                 |     -                   |     +                   |
[Recall](#Recall)                       |     -                   |     +                   |
[F](#F)                                 |     -                   |     -                   |
[F1](#F1)                               |     -                   |     +                   |
[BalancedAccuracy](#BalancedAccuracy)   |     -                   |     -                   |
[BalancedErrorRate](#BalancedErrorRate) |     -                   |     -                   |
[MCC](#MCC)                             |     -                   |     +                   |
[Accuracy](#Accuracy)                   |     -                   |     +                   |
[CtrFactor](#CtrFactor)                 |     -                   |     -                   |
[AUC](#AUC)                             |     -                   |     -                   |
[QueryAUC](#QueryAUC)                   |     -                   |     -                   |
[NormalizedGini](#ormalizedGini)        |     -                   |     -                   |
[BrierScore](#Brierscore)               |     -                   |     -                   |
[HingeLoss](#HingeLoss)                 |     -                   |     -                   |
[HammingLoss](#HammingLoss)             |     -                   |     -                   |
[ZeroOneLoss](#ZeroOneLoss)             |     -                   |     +                   |
[Kappa](#Kappa)                         |     -                   |     -                   |
[WKappa](#WKappa)                       |     -                   |     -                   |
[LogLikelihoodOfPrediction](#LLP)                             |     -                   |     -                   |


