嘗試此(SVM與5-倍交叉驗證),以獲得所需的輸出(RAN與隨機生成的數據)
tuned <- tune.svm(label~., data = train, gamma = 10^(-6:-1), cost = 10^(-1:1))
model <- svm(label~., data = train, kernel = 'radial', type = 'C-classification', gamma = 0.001, cost = 10, cross=5)
summary(model)
與輸出
Call:
svm(formula = label ~ ., data = train, kernel = "radial", type = "C-classification", gamma = 0.001, cost = 10, cross = 5)
Parameters:
SVM-Type: C-classification
SVM-Kernel: radial
cost: 10
gamma: 0.001
Number of Support Vectors: 70
(52 18)
Number of Classes: 2
Levels:
false true
5-fold cross-validation on training data:
Total Accuracy: 74.28571
Single Accuracies:
57.14286 85.71429 64.28571 92.85714 71.42857
,然後使用該模型用於預測上看不見的數據
prediction <- predict(model, newdata=test[,-1])
prediction
tab <- table(pred = prediction, true = test[,1])
print('contingency table')
tab
with output
"contingency table"
true
pred false true
false 21 9
true 0 0