Skip to content

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