[英]SVM Plot does not show any result in R
我使用了以下代碼:
library(e1071)
svm.model<-svm(default.payment.next.month~PAY_AMT6,data=creditdata,cost=5,gamma=1)
plot(svm.model,data=creditdata,fill=TRUE)
使用@parth 提供的可重現示例,您可以嘗試以下操作。
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)
在這里,我運行了一個分類模型,因此?svm
y
(即上述案例中的Class
)應該是一個factor
(您可以使用str(GermanCredit)
驗證這一點)。
建立模型后,您可以使用plot
繪制它。 ?plot.svm
表示如果您的模型中使用了兩個以上的自變量,則您需要提供formula
(通過固定 2 個維度,即上述情況下的Duration ~ Amount
)。 您可能還對slice
選項感興趣(有關更多詳細信息,請參閱?plot.svm
)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.