Skip to content

One-hot encoding flips binary labels #46

@unai-fa

Description

@unai-fa

Hi,

I noticed that the one_hot() function flips labels when applied to binary factors. Specifically, the function uses contrasts() and then drops one of the two columns in the binary case. This results in "0" being encoded as 1 and "1" as 0, which may be unexpected.

labels <- factor(c(0, 1, 1, 0))
one_hot(labels)
# Output: [1] 1 0 0 1
# Expected: [1] 0 1 1 0

This can lead to inconsistencies if the base model is trained on factor labels and the auditor uses one_hot().

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions