2016-12-15 103 views
0

我是ML和R的新手。我已經使用SVM構建了圖像分類模型。以下是我用來建立此模型的代碼,使用SVM模型計算圖像分類的準確性

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) 

prediction <- predict(model, test[,-1]) 
prediction 

tab <- table(pred = prediction, true = test[,1]) 
tab 

是否有函數來計算模型的精度?

我需要知道如何生成像使用R中的下面的截圖, click here for the screenshot

回答

0

嘗試此(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