binary_visualiseR {ConfusionTableR}R Documentation

Binary Visualiser - A Binary Confusion Matrix Visual

Description

a confusion matrix object for binary classification machine learning problems. Returns a plot to visualise the important statistics derived from a confusion matrix, see: https://machinelearningmastery.com/confusion-matrix-machine-learning/.

Usage

binary_visualiseR(
  train_labels,
  truth_labels,
  class_label1 = "Class Negative",
  class_label2 = "Class Positive",
  quadrant_col1 = "#3F97D0",
  quadrant_col2 = "#F7AD50",
  custom_title = "Confusion matrix",
  info_box_title = "Confusion matrix statistics",
  text_col = "black",
  round_dig = 2,
  cm_stat_size = 1.4,
  cm_stat_lbl_size = 1.5,
  ...
)

Arguments

train_labels

the classification labels from the training set

truth_labels

the testing set ground truth labels for comparison

class_label1

classification label 1 i.e. readmission into hospital

class_label2

classification label 2 i.e. not a readmission into hospital

quadrant_col1

colour of the first quadrant - specified as hexadecimal

quadrant_col2

colour of the second quadrant - specified as hexadecimal

custom_title

title of the confusion matrix plot

info_box_title

title of the confusion matrix statistics box

text_col

the colour of the text

round_dig

rounding options

cm_stat_size

the cex size of the statistics box label

cm_stat_lbl_size

the cex size of the label in the statistics box

...

function forwarding to the confusion matrix object to pass additional args, such as positive = "Class label"

Value

returns a visual of a Confusion Matrix output

Examples

library(dplyr)
library(ConfusionTableR)
library(caret)
library(tidyr)
library(mlbench)


# Load in the data
data("BreastCancer", package = "mlbench")
breast <- BreastCancer[complete.cases(BreastCancer), ] #Create a copy
breast <- breast[, -1]
breast <- breast[1:100,]
breast$Class <- factor(breast$Class) # Create as factor
for(i in 1:9) {
 breast[, i] <- as.numeric(as.character(breast[, i]))
}

#Perform train / test split on the data
train_split_idx <- caret::createDataPartition(breast$Class, p = 0.75, list = FALSE)
train <- breast[train_split_idx, ]
test <- breast[-train_split_idx, ]
rf_fit <- caret::train(Class ~ ., data=train, method="rf")
#Make predictions to expose class labels
preds <- predict(rf_fit, newdata=test, type="raw")
predicted <- cbind(data.frame(class_preds=preds), test)
# Create the visual
ConfusionTableR::binary_visualiseR(predicted$class_preds, predicted$Class)

[Package ConfusionTableR version 1.0.4 Index]