Arnand Arnand - 4 years ago 134
R Question

Train on Specificity

I use Caret to train my model (binary classification task). How can I make sure that train() doesn't train on the accuracy metric, but on Specificity (TN / (TN+FP)) metric?

what works on Accuracy:

control <- trainControl(method="cv", number=10)
metric <- "Accuracy"

set.seed(7)
fit.svm <- train(target_var ~., data=dataset, method="svmRadial", metric=metric, trControl=control)


It doesn't work to change:

metric = "Specificity"


Does anyone know how to train the model to optimise the Specificity?

KR,
Arnand

Answer Source

Try specifiyng the summaryFunction argument to twoClassSummary inside trainControl along with classProbs = TRUE , and metric = "Spec" inside train():

control <- trainControl(method="cv", 
                        number=10, 
                        summaryFunction = twoClassSummary,
                        classProbs = TRUE) 

fit.svm <- train(target_var ~., 
                 data=dataset,
                 method="svmRadial", 
                 metric="Spec", 
                 trControl=control)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download