-1

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)
Terru_theTerror
  • 4,918
  • 2
  • 20
  • 39
Ruser
  • 11
  • 1
  • 2
    Please provide reproducible data. Have a look at https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – MKR Feb 16 '18 at 05:55
  • can you post screenshot of your error or problem? And specification of what you want achieve. – Nihal Feb 16 '18 at 05:59
  • @MKR, Nihal : you can also use `library(caret);data("GermanCredit");library(e1071);svm.model <- svm(Amount ~ Duration, data = GermanCredit, cost = 5, gamma = 1);plot(svm.model, data = GermanCredit, fill = TRUE)` for a reproducible example with same issue. – parth Feb 16 '18 at 06:04
  • the dataset is huge. – Ruser Feb 16 '18 at 06:04
  • Nihal thanks for the response I tried this code .but still it doesnt work.can you please help on this – Ruser Feb 16 '18 at 06:07
  • i use the german credit card data from kaggle – Ruser Feb 16 '18 at 06:10
  • @Ruser, i posted code _for reproducible example_ as your `data=creditdata` was not not shared in question and your issue can be reproduced using the posted code – parth Feb 16 '18 at 06:18
  • Thanks.I used the same code which you have given.It does not plot anything and it doesnt throw any error also – Ruser Feb 16 '18 at 06:26
  • @parth can you please help on this – Ruser Feb 16 '18 at 07:17
  • 1
    @Ruser, the explanation [here](https://stackoverflow.com/a/25717154/6779509) might help you along with Prem's answer. Also, can you share the class of `default.payment.next.month`,`PAY_AMT6` columns in your data ? – parth Feb 16 '18 at 08:48

1 Answers1

1

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).

Prem
  • 11,775
  • 1
  • 19
  • 33