> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-vortex-format.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}
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 │
└────────┘
```

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

```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] │
└────────────┘
```
