【问题标题】:Calculate accuracy for image classification using SVM model使用 SVM 模型计算图像分类的准确度
【发布时间】:2017-04-30 14:13:14
【问题描述】:

我是 ML 和 R 的新手。我已经使用 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 生成类似以下屏幕截图的内容,

【问题讨论】:

    标签: r machine-learning svm confusion-matrix


    【解决方案1】:

    试试这个(带有 5 折交叉验证的 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, 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
    

    【讨论】:

      猜你喜欢
      • 2020-05-07
      • 2015-12-04
      • 1970-01-01
      • 2015-12-05
      • 2021-09-28
      • 2022-01-10
      • 2019-05-06
      • 2020-01-03
      • 2023-03-05
      相关资源
      最近更新 更多