Am new to R, tried to create a SVM Model with Linear Kernel.
Here is the code:
library(e1071)
svm.narrow.margin <- svm(Diagnosis~.,
data = biomed,
type = "C-classification",
cost = 1.0,
kernel = "linear")
However it returns this error message:
Error in if (any(as.integer(y) != y)) stop("dependent variable has to be of factor or integer type for classification mode.") : missing value where TRUE/FALSE needed In addition: Warning message: In svm.default(x, y, scale = scale, ..., na.action = na.action) : NAs introduced by coercion
I ran the same set of codes on R Studio Cloud and it works fine which is confusing.
A possibility is because of latest R update. Are you using 4.0.0 in your local system?
This update changed the default behaviour of stringsAsFactors, so it may have an effect depending on how you are using it. Check output of default.stringsAsFactors() in both sessions.
So @Yarnabrina's suspicion is probably right. If you add stringsAsFactors = TRUE to the read.csv() call on your laptop your code should work fine (just as it does on RStudio Cloud).
You can set options(stringsAsFactors = TRUE) to make this the default for your entire session. But you should be cautious when using this setting as it reduces the reproducibility of your code.
I'd resort to this approach only if my code had many functions where this option needed to be specified. If it's just one or two read.csv() calls, it's far safer to just add the stringsAsFactors = TRUE to the function calls.