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

> カテゴリごとに、`(P(tag = 1) - P(tag = 0))(log(P(tag = 1)) - log(P(tag = 0)))` の値を計算します。

# categoricalInformationValue

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

導入バージョン: v20.1.0

二値のターゲット変数に対するカテゴリ特徴量の情報価値 (IV) を計算します。

各カテゴリについて、この関数は次を計算します: `(P(tag = 1) - P(tag = 0)) × (log(P(tag = 1)) - log(P(tag = 0)))`

ここで:

* P(tag = 1) は、指定されたカテゴリにおいてターゲットが 1 である確率です
* P(tag = 0) は、指定されたカテゴリにおいてターゲットが 0 である確率です

Information Value は、予測モデリングにおいて、カテゴリ特徴量と二値ターゲット変数の関係の強さを測るために使われる統計量です。
絶対値が大きいほど、予測力が高いことを示します。

この結果は、離散的な (カテゴリ) 特徴量 `[category1, category2, ...]` の各要素が、`tag` の値を予測する学習モデルにどの程度寄与するかを示します。

**構文**

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

**引数**

* `category1, category2, ...` — 分析対象のカテゴリ特徴量を 1 つ以上指定します。各カテゴリは離散値である必要があります。[`UInt8`](/ja/reference/data-types/int-uint)
* `tag` — 予測対象となる二値の目的変数です。値は 0 と 1 である必要があります。[`UInt8`](/ja/reference/data-types/int-uint)

**戻り値**

カテゴリの一意な組み合わせごとの information value を表す Float64 値の配列を返します。各値は、そのカテゴリの組み合わせが目的変数に対して持つ予測力の強さを示します。[`Array(Float64)`](/ja/reference/data-types/array)

**例**

**年齢層とモバイル利用状況を分析する基本的な使い方**

```sql title=Query theme={null}
-- metrica.hits データセット（https://sql.clickhouse.com/ で利用可能）を使用して年齢とモバイルの関係を分析
SELECT categoricalInformationValue(Age < 15, IsMobile)
FROM metrica.hits;
```

```response title=Response theme={null}
[0.0014814694805292418]
```

**ユーザー属性を含む複数のカテゴリ特徴量**

```sql title=Query theme={null}
SELECT categoricalInformationValue(
    Sex,                 -- 0=男性, 1=女性
    toUInt8(Age < 25),   -- 0=25歳以上, 1=25歳未満
    toUInt8(IsMobile)    -- 0=デスクトップ, 1=モバイル
) AS iv_values
FROM metrica.hits
WHERE Sex IN (0, 1);
```

```response title=Response theme={null}
[0.00018965785460692887,0.004973668839403392]
```
