Description Usage Arguments Details Value Author(s) See Also Examples
this function allows to obtain performance measures from Confusion Matrix, it returns a data frame containing performance measures from the confusion matrix given by the caret
package.
1 | getMetrics(y, yhat, classtype)
|
y |
expression. The class variable. |
yhat |
expression. The vector of predicted values. |
classtype |
character or numeric. The number of levels in |
getMetrics
works with target variables that have two, three, four, six or eight classes.
The function relies on the caret
package to obtain the confusion matrix from which performance measures are extracted. It can be run for several algorithms, and the results combined into one data frame for easier comparison (see section 'Examples').
Predictions have to be obtained beforehand and used as input for yhat
. The predict.train
function in caret
should be run without argument type
when obtaining the predictions.
Outputs an object with performance measures calculated from the confusion matrix given by the caret
package. A data frame is the resulting output with the first column giving the name of the performance measure, and the second column giving the corresponding value.
Zakaria Kehel, Bancy Ngatia, Khadija Aziz
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | if(interactive()){
# Obtain predictions from previous models
data(septoriaDurumWC)
split.data <- splitData(septoriaDurumWC, seed = 1234, y = "ST_S", p = 0.7)
data.train <- split.data$trainset
data.test <- split.data$testset
knn.mod <- tuneTrain(data = septoriaDurumWC,y = 'ST_S',method = 'knn',positive = 'R')
nnet.mod <- tuneTrain(data = septoriaDurumWC,y = 'ST_S',method = 'nnet',positive = 'R')
pred.knn <- predict(knn.mod$Model, newdata = data.test[ , -1])
pred.nnet <- predict(nnet.mod$Model, newdata = data.test[ , -1])
metrics.knn <- getMetrics(y = data.test$ST_S, yhat = pred.knn, classtype = 2)
metrics.nnet <- getMetrics(y = data.test$ST_S, yhat = pred.nnet, classtype = 2)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.