Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
631 views
in Technique[技术] by (71.8m points)

Error when creating SVM plot in R: Error in UseMethod("predict") : no applicable method for 'predict' applied to an object of class "svm"

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

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...