Description Usage Arguments Value See Also Examples
View source: R/fscoreSummary.R
Calculates information retrieval measures
(Precision, Recall, F1, F2) for evaluating a two-class classifier
output quality.
This function can be used in train()
function for
selecting the hyperparameter(s) of a classifier. This can be achieved by
specifying the argument metric
in train()
function call, and
summaryFunction = fscoreSummary
and classProbs = TRUE
in trainControl
.
See examples below.
1 | fscoreSummary(data, lev = NULL, model = NULL, ...)
|
data |
a data frame with columns |
lev |
a character vector of factors levels for the response. |
model |
a character string for the model name (as taken from the
|
... |
additional arguments to be passed to the low level functions. |
A vector containing the metrics.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | data = caret::twoClassSim(200)
describe(data)
mod1 = train(Class ~ . , data = data,
method = "rpart2",
tuneGrid = expand.grid(maxdepth = 1:10),
metric = "F1",
trControl = trainControl(method = "cv", number = 10,
classProbs = TRUE,
savePredictions = TRUE,
summaryFunction = fscoreSummary,
selectionFunction = "best") )
mod1
plot(mod1)
mod2 = train(Class ~ . , data = data,
method = "rpart2",
tuneGrid = expand.grid(maxdepth = 1:10),
metric = "F2",
trControl = trainControl(method = "cv", number = 10,
classProbs = TRUE,
summaryFunction = fscoreSummary,
selectionFunction = "best") )
mod2
plot(mod2)
mod3 = train(Class ~ . , data = data,
method = "rf",
tuneGrid = expand.grid(mtry = 1:5),
metric = "F1",
trControl = trainControl(method = "cv", number = 10,
classProbs = TRUE,
summaryFunction = fscoreSummary,
selectionFunction = "best") )
mod3
plot(mod3)
mod4 = train(Class ~ . , data = data,
method = "rf",
tuneGrid = expand.grid(mtry = 1:5),
metric = "F2",
trControl = trainControl(method = "cv", number = 10,
classProbs = TRUE,
summaryFunction = fscoreSummary,
selectionFunction = "best") )
mod4
plot(mod4)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.