【问题标题】:R: How do we print percentage accuracy for SVMR:我们如何打印 SVM 的百分比准确度
【发布时间】:2016-07-16 03:57:29
【问题描述】:

这是我的示例R 代码:

    train <- read.csv("Train.csv")
    test <- read.csv("Test+.csv")

   x <- model.matrix(age ~ . - 1,data=train)           

    classify=svm(as.factor(age)~ ., data=train,method="class")
    pred = predict(classify,test,type="class")

我如何从中打印百分比准确度?我想为我的评估显示所有性能指标,例如准确度、精确度、召回率等。

【问题讨论】:

  • 定义准确度——有多个有效的分类准确度指标。
  • 我认为它不适用于分类问题。结果要么在一个类别中,要么不在。

标签: r machine-learning svm libsvm confusion-matrix


【解决方案1】:

这里有几个选项,使用内置的iris 数据框进行说明:

library(e1071)

m1 <- svm(Species ~ ., data = iris)

使用table函数创建混淆矩阵:

table(predict(m1), iris$Species, dnn=c("Prediction", "Actual"))   
            Actual
Prediction   setosa versicolor virginica
setosa         50          0         0
versicolor      0         48         2
virginica       0          2        48

使用caret包生成混淆矩阵和其他模型诊断(也可以使用caret for the entire model development, tuning and validation process):

library(caret)

confusionMatrix(iris$Species, predict(m1))
Confusion Matrix and Statistics

            Reference
Prediction   setosa versicolor virginica
setosa         50          0         0
versicolor      0         48         2
virginica       0          2        48

Overall Statistics

Accuracy : 0.9733          
95% CI : (0.9331, 0.9927)
No Information Rate : 0.3333          
P-Value [Acc > NIR] : < 2.2e-16       

Kappa : 0.96            
Mcnemar's Test P-Value : NA              

Statistics by Class:

                     Class: setosa Class: versicolor Class: virginica
Sensitivity                 1.0000            0.9600           0.9600
Specificity                 1.0000            0.9800           0.9800
Pos Pred Value              1.0000            0.9600           0.9600
Neg Pred Value              1.0000            0.9800           0.9800
Prevalence                  0.3333            0.3333           0.3333
Detection Rate              0.3333            0.3200           0.3200
Detection Prevalence        0.3333            0.3333           0.3333
Balanced Accuracy           1.0000            0.9700           0.9700

【讨论】:

  • @Mahsolid“如何调整”与“如何打印百分比准确度”是完全不同的问题。
猜你喜欢
  • 2021-09-28
  • 2018-09-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-15
  • 1970-01-01
  • 2021-10-18
相关资源
最近更新 更多