FrequencyEncoder(normalize=true) counts missing values in the denominator, so frequencies no longer sum to 1
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 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時間
- マージ済み PR(30日)
- 6
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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 件 · 担当者 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 件 · 担当者 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 件 ·
メンテナーはふだん 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
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
oscar-system/Oscar.jl#6572 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
-
question
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
brown-ccv/Chamber.jl#272 ·