FrequencyEncoder(normalize=true) counts missing values in the denominator, so frequencies no longer sum to 1
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 57/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 领域
- data
调研方向
Read src/encoders/frequency_encoding/frequency_encoding.jl around line 31 and src/transformers/cardinality_reducer/cardinality_reducer.jl around line 48, where the issue identifies the calculations involving missing values. Check the relevant tests for both models and verify normalized frequencies and float min_frequency use non-missing values while missing entries remain unchanged. Done means the reported frequency sums and level collapsing match the non-missing category values.
由索引模型根据 Issue 内容生成。
描述
FrequencyEncoder(normalize = true) computes the frequencies with proportionmap(col) (src/encoders/frequency_encoding/frequency_encoding.jl, line 31), and col still contains the missing entries. So missing rows end up in the denominator, even though missing never gets its own encoded value (it just passes through as missing). The result is that the per-level frequencies don't add up to 1, which the docstring says they should:
normalize=false: Whether to use normalized frequencies that sum to 1 over category values or to use raw counts.
It also means the encoding of a non-missing level changes depending on how many missing values were in the training data.
using MLJBase, MLJTransforms, CategoricalArrays
X = (color = categorical(["red", "red", "blue", missing, missing, missing]),)
mach = machine(FrequencyEncoder(normalize = true), X)
fit!(mach, verbosity = 0)
freqs = fitted_params(mach).statistic_given_feat_val[:color]
@show freqs
@show sum(values(freqs))
@show transform(mach, X).color
# same non-missing values, no missing rows
X2 = (color = categorical(["red", "red", "blue"]),)
mach2 = machine(FrequencyEncoder(normalize = true), X2)
fit!(mach2, verbosity = 0)
@show fitted_params(mach2).statistic_given_feat_val[:color]
Output:
freqs = Dict{String, Float32}("red" => 0.33333334, "blue" => 0.16666667)
sum(values(freqs)) = 0.5f0
(transform(mach, X)).color = Union{Missing, Float32}[0.33333334, 0.33333334, 0.16666667, missing, missing, missing]
(fitted_params(mach2)).statistic_given_feat_val[:color] = Dict{String, Float32}("red" => 0.6666667, "blue" => 0.33333334)
I expected red => 2/3 and blue => 1/3 in both cases, i.e. frequencies over the observed category values, which is what the docstring describes (and what e.g. pandas value_counts(normalize=True) gives by default). Instead they sum to 0.5 here.
CardinalityReducer has the same pattern when min_frequency is a float (src/transformers/cardinality_reducer/cardinality_reducer.jl, line 48), and there it changes which levels get collapsed. Below, "red" is 3 of the 4 non-missing values (0.75) but is still mapped to "Other" with min_frequency = 0.4, because it is compared as 3/8:
Y = (color = categorical(["red", "red", "red", "blue", missing, missing, missing, missing]),)
mach3 = machine(CardinalityReducer(min_frequency = 0.4), Y)
fit!(mach3, verbosity = 0)
@show unwrap.(transform(mach3, Y).color)
unwrap.((transform(mach3, Y)).color) = Union{Missing, String}["Other", "Other", "Other", "Other", missing, missing, missing, missing]
Since both models already leave missing untouched in transform, I think the frequencies should be computed over the non-missing values only, e.g. proportionmap(collect(skipmissing(col))) / countmap(skipmissing(col)). If counting missing rows in the denominator is intentional, it would be good to mention that in the docstrings instead.
Versions: Julia 1.13.4, MLJTransforms 0.2.4 (dev at d3e3db3), MLJBase 1.15.4, CategoricalArrays 1.1.1.
- 主要语言
- Julia
- 星标
- 1
- 派生
- 5
- 平均合并
- 1 天 4 小时
- 30 天内合并 PR
- 6
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
JuliaAI/MLJTransforms.jl 的其他 Issue
-
TargetEncoder: m = :auto uses the inverse of the empirical Bayes ratio and gives NaN for single-row levels可能已有人在做 @EssamWisam 于 1 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
JuliaAI/MLJTransforms.jl#113 · 1 个 reaction · 已指派 1 人 ·
维护者通常 1 天内回复
-
ContinuousEncoder docstring: wrong `drop_last` default and nonexistent `ordered_factors` option可能已有人在做 @ablaom 于 2 天前认领。 未关闭documentation
难度 1/5 1 小时以内 新手友好度 88/100
JuliaAI/MLJTransforms.jl#109 · 1 条评论 · 1 个 reaction · 已指派 1 人 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 90/100
JuliaAI/MLJTransforms.jl#108 · 1 条评论 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
JuliaAI/MLJTransforms.jl#107 · 1 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
-
next breaking release
难度 1/5 1 小时以内 新手友好度 58/100
JuliaAI/MLJTransforms.jl#111 ·
维护者通常 1 天内回复
查看 JuliaAI/MLJTransforms.jl 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 66/100
-
难度 2/5 1-3 小时 新手友好度 64/100
SciML/SciMLBenchmarks.jl#2044 · 2 条评论 ·
维护者通常 2 天内回复
-
难度 1/5 1 小时以内 新手友好度 84/100
维护者通常 1 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 65/100
oscar-system/Oscar.jl#6572 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
JuliaLang/LinearAlgebra.jl#2002 · 2 条评论 ·
维护者通常 1 天内回复