> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-fbfa8bee.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 的概率

信息值是在预测建模中用于衡量分类特征与二元目标变量关系强弱的统计量。
绝对值越高，表示预测能力越强。

结果表示每个离散 (分类) 特征 `[category1, category2, ...]` 对预测 `tag` 值的学习模型的贡献大小。

**语法**

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

**参数**

* `category1, category2, ...` — 要分析的一个或多个分类特征。每个类别都应包含离散值。[`UInt8`](/zh/reference/data-types/int-uint)
* `tag` — 用于预测的二元目标变量。应包含 0 和 1 两个值。[`UInt8`](/zh/reference/data-types/int-uint)

**返回值**

返回一个 `Float64` 值数组，表示每种唯一类别组合的信息值。每个值都表明该类别组合对目标变量的预测能力。[`Array(Float64)`](/zh/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]
```
