Reputation: 11
I've used the following code :
library(e1071)
svm.model<-svm(default.payment.next.month~PAY_AMT6,data=creditdata,cost=5,gamma=1)
plot(svm.model,data=creditdata,fill=TRUE)
Upvotes: -1
Views: 1525
Reputation: 13
I know this is quite old but still shows up near top of search results for me. I just had similar issue potentially (though hard to tell with lack of details in question).
I had my target as numeric and it would not plot anything nor give feedback as to why it wouldn't.
I simply converted to my target to factor prior to making the model and it worked.
df$target <- as.factor(df$target)
Upvotes: 0
Reputation: 11965
Using a reproducible example provided by @parth you can try something like below.
library(caret)
library(e1071)
#sample data
data("GermanCredit")
#SVM model
svm.model <- svm(Class ~ Duration + Amount + Age, data = GermanCredit)
#plot SVM model
plot(svm.model, data = GermanCredit, Duration ~ Amount)
Here I ran a classification model so y
(i.e. Class
in above case) in ?svm
should be a factor
(you can verify this using str(GermanCredit)
).
Once the model is built you can plot it using plot
. ?plot.svm
says that you need to provide formula
(by fixing 2 dimensions i.e. Duration ~ Amount
in above case) if more than two independent variables are used in your model. You may also be interested in slice
option (for more detail refer ?plot.svm
).
Upvotes: 1