Como muitos modelos preditivos, o SVM produzirá pontuações de probabilidade e aplicará o limite à probabilidade de convertê-lo em rótulos positivos ou negativos.
Como @Sycorax mencionado no comentário, você pode ajustar o limite de corte para ajustar o trade-off entre falso positivo e falso negativo.
Aqui está um exemplo em R.
library(kernlab)
library(mlbench)
graphics.off()
set.seed(0)
d=mlbench.2dnormals(500)
plot(d)
# using 2nd order polynominal expansion
svp <- ksvm(d$x,d$classes,type="C-svc",kernel="polydot",
kpar=list(degree=2),C=10,prob.model=T)
plot(svp)
p=predict(svp,d$x, type="prob")[,1]
cut_off=0.5
caret::confusionMatrix(d$classes,ifelse(p<cut_off,2,1))
cut_off=0.8
caret::confusionMatrix(d$classes,ifelse(p<cut_off,2,1))
Observe que quando mudamos cut_off
, a matriz de confusão (falso positivo, falso negativo etc.) muda
> caret::confusionMatrix(d$classes,ifelse(p<cut_off,2,1))
Confusion Matrix and Statistics
Reference
Prediction 1 2
1 253 16
2 38 193
Accuracy : 0.892
95% CI : (0.8614, 0.9178)
No Information Rate : 0.582
P-Value [Acc > NIR] : < 2.2e-16
Kappa : 0.7813
Mcnemar's Test P-Value : 0.004267
Sensitivity : 0.8694
Specificity : 0.9234
Pos Pred Value : 0.9405
Neg Pred Value : 0.8355
Prevalence : 0.5820
Detection Rate : 0.5060
Detection Prevalence : 0.5380
Balanced Accuracy : 0.8964
'Positive' Class : 1
> cut_off=0.8
> caret::confusionMatrix(d$classes,ifelse(p<cut_off,2,1))
Confusion Matrix and Statistics
Reference
Prediction 1 2
1 223 46
2 10 221
Accuracy : 0.888
95% CI : (0.857, 0.9143)
No Information Rate : 0.534
P-Value [Acc > NIR] : < 2.2e-16
Kappa : 0.7772
Mcnemar's Test P-Value : 2.91e-06
Sensitivity : 0.9571
Specificity : 0.8277
Pos Pred Value : 0.8290
Neg Pred Value : 0.9567
Prevalence : 0.4660
Detection Rate : 0.4460
Detection Prevalence : 0.5380
Balanced Accuracy : 0.8924
'Positive' Class : 1