pre_metrics | R Documentation |
Convenient function to calculate a confisuion matrix, recall and precision for a machine learning model
pre_metrics(predicted = ... , expected = ... , uncertain = NULL)
predicted |
Vector with predicted behaviours (output of the prediction from a trained model used on new data) |
expected |
Vector with expected behaviours which are already known (e.g. from observation) |
uncertain |
if the prediction process is designed to put all unceartain predictions in the same class, the class name can be specified here in "..." |
None of the provided column names should have a "-" in the name otherwise the function will not work.
Takes a vector of predicted behaviours and compares it to a vector of known behaviours. A confusion matrix is computed. The recall and precision are computed after Powers et al. 2011. In cases were unknown behaviours are considered it computes the proportion of unknown behaviours in contrast to the total number of behaviours recoreded. In cases where the model performes badly and one or more classes are not predicted, the function will only output the confusion matrix.
The output is a list:
confusion_matrix |
A confusion matrix from the predicted and expected behaviours of class "table" |
metrics |
Recall, precision and accuracy for every behaviour class in a matrix |
kappa |
Cohen's kappa value |
uncertain_predictions |
proportion of uncertain predictions in relation to to total number of redictions as a numeric value |
Wanja Rast
Powers, David Martin. "Evaluation: from precision, recall and F-measure to ROC, informedness, markedness and correlation." (2011).
predicted <- c(rep("A",7),"B","C","C",rep("B",8),"A","A",rep("C",9),"B") expected <- c(rep("A",10),rep("B",10),rep("C",10)) pre_metrics(predicted = predicted , expected = expected) In case the predictions contain unidentifiable behaviours: predicted <- c(rep("A",7),"B","C","other",rep("B",8),"A","other",rep("C",9),"B") expected <- c(rep("A",10),rep("B",10),rep("C",10)) pre_metrics(predicted = predicted , expected = expected , uncertain = "other")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.