> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-trino-dialect.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Calcula o valor de `(P(tag = 1) - P(tag = 0))(log(P(tag = 1)) - log(P(tag = 0)))` em cada categoria.

# categoricalInformationValue

<div id="categoricalInformationValue">
  ## categoricalInformationValue
</div>

Introduzido em: v20.1.0

Calcula o valor de informação (IV) para atributos categóricos em relação a uma variável-alvo binária.

Para cada categoria, a função calcula: `(P(tag = 1) - P(tag = 0)) × (log(P(tag = 1)) - log(P(tag = 0)))`

onde:

* P(tag = 1) é a probabilidade de que a variável-alvo seja igual a 1 para a categoria fornecida
* P(tag = 0) é a probabilidade de que a variável-alvo seja igual a 0 para a categoria fornecida

O Valor de Informação é uma estatística usada para medir a força da relação entre um atributo categórico e uma variável-alvo binária em modelagem preditiva.
Valores absolutos mais altos indicam maior poder preditivo.

O resultado indica o quanto cada atributo discreto (categórico) `[category1, category2, ...]` contribui para um modelo de aprendizado que prevê o valor de `tag`.

**Sintaxe**

```sql theme={null}
categoricalInformationValue(category1[, category2, ...,]tag)
```

**Argumentos**

* `category1, category2, ...` — Um ou mais atributos categóricos para analisar. Cada categoria deve conter valores discretos. [`UInt8`](/pt-BR/reference/data-types/int-uint)
* `tag` — Variável-alvo binária para previsão. Deve conter os valores 0 e 1. [`UInt8`](/pt-BR/reference/data-types/int-uint)

**Valor retornado**

Retorna um array de valores Float64 que representam o valor informativo de cada combinação única de categorias. Cada valor indica a força preditiva dessa combinação de categorias para a variável-alvo. [`Array(Float64)`](/pt-BR/reference/data-types/array)

**Exemplos**

**Uso básico: análise de grupos etários em relação ao uso de dispositivos móveis**

```sql title=Query theme={null}
CREATE TABLE visits (is_young UInt8, is_female UInt8, is_mobile UInt8) ENGINE = Memory;

-- 80 of the 100 young visitors browse on a mobile device, and only 20 of the 100 older ones do,
-- while the sex of a visitor says nothing about the device.
INSERT INTO visits SELECT 1, number % 2, number < 80 FROM numbers(100);
INSERT INTO visits SELECT 0, number % 2, number < 20 FROM numbers(100);

SELECT round(categoricalInformationValue(is_young, is_mobile)[1], 4) AS iv FROM visits;
```

```response title=Response theme={null}
┌─────iv─┐
│ 0.8318 │
└────────┘
```

**Múltiplas variáveis categóricas com dados demográficos do usuário**

```sql title=Query theme={null}
-- The age of a visitor predicts the device, the sex of a visitor does not.
SELECT arrayMap(x -> round(x, 4), categoricalInformationValue(is_young, is_female, is_mobile)) AS iv
FROM visits;
```

```response title=Response theme={null}
┌─iv─────────┐
│ [0.8318,0] │
└────────────┘
```
