R caret LDA error when using resampling -
i running problem using lda through caret caregorical predictors. reason, enabling resampling throws error isn't informative. has seen before?
here reproducible toy example:
library(caret) library(mass) df <- data.frame(y = sample(as.factor(1:2), 200, replace = t), x1 = sample(as.factor(1:2), 200, replace = t), x2 = sample(as.factor(1:2), 200, replace = t)) # these 2 lines produce same results lda(df[, -1], df[, 1]) train(df[, -1], df[, 1], method = 'lda', trcontrol = traincontrol(method = 'none'))$finalmodel # gives error train(df[, -1], df[, 1], method = 'lda', trcontrol = traincontrol(method = 'cv'))$finalmodel error in train.default(df[, -1], df[, 1], method = "lda", trcontrol = traincontrol(method = "cv")) : stopping
this seems happen when using factor variables independent variables while not using formula interface. works:
train(y ~ x1 + x2, data = df, method = 'lda', trcontrol = traincontrol(method = 'cv'))$finalmodel alternatively, after converting factor variables binary dummy variables x/y-syntax works:
# convert independent variables dummy variables df$x1 <- as.numeric(df$x1 == "2") df$x2 <- as.numeric(df$x2 == "2") train(df[, -1], df[, 1], method = 'lda', trcontrol = traincontrol(method = 'cv'))$finalmodel note depending on method reported group means either around 0.5 or around 1.5, since first 2 methods in question apparently coerce factor levels 1 or 2 (numerical).
Comments
Post a Comment