FrequencyEncoder(normalize=true) counts missing values in the denominator, so frequencies no longer sum to 1
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 57/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Lĩnh vực
- data
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Julia
- Star
- 1
- Fork
- 5
- Merge trung bình
- 1 ngày 4 giờ
- Pull request đã merge (30 ngày)
- 6
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của JuliaAI/MLJTransforms.jl
-
TargetEncoder: m = :auto uses the inverse of the empirical Bayes ratio and gives NaN for single-row levelsCó thể đã có người làm @EssamWisam đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
JuliaAI/MLJTransforms.jl#113 · 1 reaction · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
ContinuousEncoder docstring: wrong `drop_last` default and nonexistent `ordered_factors` optionCó thể đã có người làm @ablaom đã nhận 2 ngày trước. Đang mởdocumentation
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
JuliaAI/MLJTransforms.jl#109 · 1 bình luận · 1 reaction · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 90/100
JuliaAI/MLJTransforms.jl#108 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
JuliaAI/MLJTransforms.jl#107 · 1 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
next breaking release
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 58/100
JuliaAI/MLJTransforms.jl#111 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của JuliaAI/MLJTransforms.jl
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
oscar-system/Oscar.jl#6572 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
-
Overload == for ZGroupĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
-
question
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
brown-ccv/Chamber.jl#272 ·