0
votes

I am building a model which have factor variables but numeric entries. I converted them to numeric. When I tried building the model with SVM radial kernel, I received some weird messages that I dont understand. Below is what I did.

Subset of data
class  ac_000       ad_000  ag_007
neg     2130706438  280     25896
neg     228         100     292936
pos     42328       856     51190
neg     24          24      0
neg     370         346     0
pos     1534        1388    794698

factorconvert <- function(f){as.numeric(levels(f))[f]} 
DF[, 2:4] <- lapply(DF[, 2:4], factorconvert) 

SVM
ctrl<-trainControl(method="repeatedcv"),
repeats=5,
summaryFunction=twoClassSummary,
classProbs=TRUE)

Train and Tune the SVM
svm.tune <- train(x=trainX, y= trainData$Class,method = "svmRadial",
tuneLength = 9, preProc =c("center","scale"),metric="ROC",trControl=ctrl)

Error in if (any(co)) { : missing value where TRUE/FALSE needed In
addition: Warning message: In FUN(newX[, i], ...) : NAs introduced by
coercion.

any(is.any(DF)).

I also removed all NAs in the data with na.omit(). I rechecked the data. No missing values were present. I need help.

1
Please include at least a subset of your data to make your problem reproducible. Without that, it is quite difficult to help you. Take a look to the help center. Thanks!lrnzcig
what is the size of actual data?abhiieor
1. Check the outcome of your factorconvert. It might not work correctly. It does't on the data you provided. 2. dput some of your original data. This set is too small to test with. If you do not want to use your data, try to replicate the error with GermanCredit data (included in the caret package) or some other data set.phiver

1 Answers

0
votes

This may happen if you directly want to convert string in the data-set into numerical form without factorize the column. I think you may want to check your data after converting using "factorconvert()" and check if first column contain any NA values. Let me know if this resolve your issue.