categoricalInformationValue
引入版本: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 值的学习模型的贡献大小。
语法
categoricalInformationValue(category1[, category2, ...,]tag)参数
返回值
返回一个 Float64 值数组,表示每种唯一类别组合的信息值。每个值都表明该类别组合对目标变量的预测能力。Array(Float64)
示例
分析年龄组与移动设备使用情况的基础用法
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;┌─────iv─┐
│ 0.8318 │
└────────┘结合用户人口统计信息的多个类别特征
-- 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;┌─iv─────────┐
│ [0.8318,0] │
└────────────┘