【问题标题】:How to obtain F1, precision, recall and confusion matrix如何获得F1、精度、召回和混淆矩阵
【发布时间】:2020-07-20 18:08:58
【问题描述】:

我的项目的目标是预测一些文字描述的准确度。

我用 FASTTEXT 制作了向量。

TSV 输出:

 label lenght
1     0   1:43
2     0   1:10
3     0    1:8
4     0  1:110
5     1  1:105
6     0  1:446

然后我通过这个脚本使用库 e1071 处理 .tsv 文件:


library (e1071)

accuracy.model = read.table(file = 'file.tsv', sep = '\t', header = FALSE, col.names= c( "label", "lenght" ))

head(accuracy.model)

classifier = svm( formula = label ~ .,
                  data = accuracy.model,
                  type = 'C-classification',
                  kernel = 'radial',
                  cost = 32,
                  gamma = 8,
                  cross  = 10)

classifier

进行交叉验证(10 次)我能够检索到总体准确率。

我还想要 F1 分数、精度和召回值。

对于混淆矩阵,我查看了其他一些堆栈线程,发现必须使用插入符号库来完成,但我不知道该怎么做。

建议?

问候

【问题讨论】:

  • 请注意,我注意到您只有 1 个自变量,这对于使用 svm 来说真的很奇怪。您可能想检查这是否正确

标签: r svm


【解决方案1】:

假设我们适合这样的模型:

library(caret)
library(e1071)
data=iris
data$Species = ifelse(data$Species=="versicolor","v","o")

classifier = svm( formula = Species ~ .,
                  data = data,
                  type = 'C-classification',
                  kernel = 'radial',
                  cost = 32,
                  gamma = 8,
                  cross  = 10)

然后我们得到混淆矩阵:

mat = table(classifier$fitted,data$Species)

并应用插入符号功能:

confusionMatrix(mat)$byClass

         Sensitivity          Specificity       Pos Pred Value 
           1.0000000            1.0000000            1.0000000 
      Neg Pred Value            Precision               Recall 
           1.0000000            1.0000000            1.0000000 
                  F1           Prevalence       Detection Rate 
           1.0000000            0.6666667            0.6666667 
Detection Prevalence    Balanced Accuracy 
           0.6666667            1.0000000 

您可以在您的情况下应用它。

【讨论】:

    猜你喜欢
    • 2020-08-29
    • 2022-12-01
    • 2017-04-05
    • 1970-01-01
    • 1970-01-01
    • 2021-10-07
    • 2018-06-14
    • 1970-01-01
    相关资源
    最近更新 更多