confusion2network

confusion2network is an R package that converts confusion matrix or classification predictions into confusion graph/network for performance investigation.

This package is still under active development and is subject to change, so documentation is lacking. But feel free to fork and send pull request. Use it with your own caution.


Installation

# install devtools if not
install.packages("devtools")
# install through github for now
devtools::install_github("qutang/confusion2network")

Highlight features

  • node size: the bigger, the more misclassified samples for this class
  • edge opacity and edge width

    • for self reference edges, the more transparent or thinner the better it performs
    • for other edges, the more transparent or thinner the less misclassification rate
  • node click: click to highlight nodes and its up to 2 degree connections, indicating which classes may be misclassified with it.

Example

Confusion matrix as a graph

confusion2network(sample_confusion_matrix, 
                  true_label_prefix = "TRUE_", 
                  pred_label_prefix = "PREDICT_", 
                  height = "400px", 
                  width = "60%")

Prediction dataframe as a graph

Sample prediction matrix

##   PID CLASS_ID PRED_CLASS_ID ACV_ID
## 1   1        0             2      0
## 2   1        0             2      0
## 3   1        0             2      0
## 4   1        0             3      0
## 5   1        0             2      0
## 6   1        0             1      0

Convert prediction matrix to a network

prediction2network(sample_prediction_dataframe, 
                   true_col = "CLASS_ID", 
                   pred_col = "PRED_CLASS_ID",
                   true_labels = c("Transition", "Sitting", "Upright", "Lying"), 
                   pred_labels = c("Sitting", "Upright", "Lying"), 
                   height = "400px", 
                   width = "60%")

Acknowledge

visNetwork and vis.js is the backend for the interactive network building. Refer to their API for your own customization.