跳转到主内容
跳转到主内容

categoricalInformationValue

categoricalInformationValue

引入版本:v20.1

计算分类特征相对于二元目标变量的信息值(Information Value,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 值的模型中的贡献程度。

语法

categoricalInformationValue(category1[, category2, ...,]tag)

参数

  • category1, category2, ... — 要分析的一个或多个类别型特征。每个类别应包含离散值。UInt8
  • tag — 用于预测的二元目标变量。应包含值 0 和 1。UInt8

返回值

返回一个 Float64 类型的数组,表示每种唯一类别组合的信息值。每个值表示该类别组合对目标变量的预测能力。Array(Float64)

示例

分析年龄段与移动端使用情况的基本用法

-- Using the metrica.hits dataset (available on https://sql.clickhouse.com/) to analyze age-mobile relationship
SELECT categoricalInformationValue(Age < 15, IsMobile)
FROM metrica.hits;
[0.0014814694805292418]

包含用户人口统计学信息的多个分类特征

SELECT categoricalInformationValue(
    Sex,                 -- 0=male, 1=female
    toUInt8(Age < 25),   -- 0=25+, 1=under 25
    toUInt8(IsMobile)    -- 0=desktop, 1=mobile
) AS iv_values
FROM metrica.hits
WHERE Sex IN (0, 1);
[0.00018965785460692887,0.004973668839403392]