Find metrics by R

Asked

Viewed 59 times

0

I cannot find in R the same metrics that are presented by the graphical interface (see below). Of all the metrics, only the accuracy (CA) I was able to find. Is there any step by step or place where I can learn how to do this?

inserir a descrição da imagem aqui

  • 1

    Look if this helps http://www.sthda.com/english/articles/38-regression-model-validation/157-cross-validation-essentials-in-r/

  • 2

    There’s a package called Metrics that has all these metrics in very simple functions: https://CRAN.R-project.org/package=Metrics

1 answer

0

I did the manual process in solving the problem. I used Weka as a base to calculate the weights.

""" 
    v1 v2
    v3 v4

previsoes
       0    1
  0 1681   36
  1  112  171
"""
# Desmembrando a Matriz de Confusão
v1 = matriz_confusao[1,1]
v2 = matriz_confusao[1,2]
v3 = matriz_confusao[2,1]
v4 = matriz_confusao[2,2]

Acuracia_manual = ((v1+v4)/(v1+v4+v2+v3)) * 100

# Classe 0
Sensitivity_0 = v1/(v1 + v3)
Specificity_1 = v4/(v4 + v2)
Precisao_0 = v1/(v1 + v3)
Recall_0 = v1/(v1 + v2)
F1_0 = (2 * Precisao_0 * Recall_0)/(Precisao_0 + Recall_0)
Metrica_0 = data.frame(Precisao_0,Recall_0,F1_0)

# Classe 1
Sensitivity_1 = v4/(v4 + v2)
Specificity_0 = v1/(v1 + v3)
Precisao_1 = v4/(v4 + v2)
Recall_1 = v4/(v4 + v3)
F1_1 = (2 * Precisao_1 * Recall_1)/(Precisao_1 + Recall_1)
Metrica_1 = data.frame(Precisao_1,Recall_1,F1_1)

# Cálculo para achar a quantidade de elementos 0s e 1s (pesos - conceito do Weka)
arquivo = base$default
arquivo
Lable_0 = 0
Lable_1 = 0
for (d in arquivo) if (d == 0) Lable_0 = Lable_0+1 else Lable_1 = Lable_1+1

# Cálculo ponderado das médias
Sensitivity_avg = (Sensitivity_0 * Lable_0 + Sensitivity_1 * Lable_1)/(Lable_0 + Lable_1)
Specificity_avg = (Specificity_0 * Lable_0 + Specificity_1 * Lable_1)/(Lable_0 + Lable_1)
F1_avg = (F1_0 * Lable_0 + F1_1 * Lable_1)/(Lable_0 + Lable_1)
Precisao_avg = (Precisao_0 * Lable_0 + Precisao_1 * Lable_1)/(Lable_0 + Lable_1)
Recall_avg = (Recall_0 * Lable_0 + Recall_1 * Lable_1)/(Lable_0 + Lable_1)
Metrica_avg = data.frame(Acuracia_manual,F1_avg, Precisao_avg, Recall_avg)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.