I am trying to create a plot for weighted SVM model
The following commands
X <- subset(mydata, select=-STATUS)
Y <- subset(mydata, select=STATUS)
wts<-1/table(Y)
best_model= svm(mydata, Y, type="C-classification", kernel="linear", class.weights = wts)
summary(best_model)
####################################################################
install.packages("plot3D")
library(plot3D) # for 3D plot
x1plot = seq(min(mydata$PC1), max(mydata$PC1), length= 100)
x2plot = seq(min(mydata$PC2), max(mydata$PC2), length= 100)
m = mesh(x=x1plot, y=x2plot)
vals = matrix(0, nrow=nrow(m$x), ncol = ncol(m$x)) # place holder
for(i in 1: ncol(m$x))
{
this_X = cbind(m$x[,i], m$y[, i])
vals[,i] = predict(best_model, this_X)
}
just returns following error in RStudio:
Error in UseMethod("predict") : no applicable method for 'predict' applied to an object of class "svm"
I am using following data
Could you please give me some hint how to transform the best_model object? Or another way how to create a plot for multidimensional SVM for my data?
question from:
https://stackoverflow.com/questions/65836154/error-when-creating-svm-plot-in-r-error-in-usemethodpredict-no-applicable 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…