Skip to content

bug if levels of factor column are not already in 'alpha' order#7

Open
fazetu wants to merge 1 commit intogravesee:masterfrom
fazetu:master
Open

bug if levels of factor column are not already in 'alpha' order#7
fazetu wants to merge 1 commit intogravesee:masterfrom
fazetu:master

Conversation

@fazetu
Copy link

@fazetu fazetu commented Apr 11, 2019

Bug in reordering of factor levels if they are not already in "alphabetical" order e.g. c(1, 6, 12) gets changed to c(1, 12, 6).

Reprex:

library(onehot)

test <- data.frame(
  fct = factor(c(1, 6, 12, 999, NA), levels = c(1, 6, 12, 999, NA))
)
test$fct_chr <- as.character(test$fct)
test$fct_chr_fct <- factor(test$fct_chr)
test2 <- test[1:2, ] # future new data

encoder <- onehot(test, add_NA_factors = TRUE)
test_onehot <- predict(encoder, test)
View(cbind(test, test_onehot))

test2_onehot <- predict(encoder, test2) # reuse encoder on new data
View(cbind(test2, test2_onehot))
all(colnames(test_onehot) == colnames(test2_onehot))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant