I'm trying to use the function predict.ksvm from library kernlab in R.
I have been reading the documentation at the following link:
https://www.rdocumentation.org/packages/kernlab/versions/0.9-27/topics/predict.ksvm
The function ksvm is working, so it's just the predict function that is currently not working.
The code:
library(kernlab)
mySvm<-ksvm(x=as.matrix(train[,-4703]),y=train[,4703],kernel="vanilladot")
predSvm<-predict.ksvm(mySvm,newdata=test[,-4703])
The error:
Error in predict.ksvm(mySvm, newdata = test[, -4703]) :
could not find function "predict.ksvm"
Try simply
It should work because
mySvmis an object of classksvmand an appropriate function method will be automatically chosen for it.When you write
it doesn't work because the
predictmethod for theksvmclass is somewhat hidden from you, pretends not to exist. If it were anS3function, you could writekernlab:::predict.ksvm, but in this case it is anS4function, so you needgetMethod("predict", "ksvm")as to see the function.