{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<p  style=\"z-index: 101;background: #fde073;text-align: center;line-height: 2.5;overflow: hidden;font-size:22px;\">Please <a href=\"#Cite\">cite us</a> if you use the software</p>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# PyCM Document"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Version : 4.2 <a class=\"tocSkip\"></a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "-----"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "tags": [
     "html_hide"
    ]
   },
   "source": [
    "## Table of contents"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "tags": [
     "html_hide"
    ]
   },
   "source": [
    "<ul>\n",
    "    <li><a href=\"#Overview\">Overview</a></li>\n",
    "    <li><a href=\"#Installation\">Installation</a></li>\n",
    "        <ol>\n",
    "            <li><a href=\"#PyPI\">PyPI</a></li>\n",
    "            <li><a href=\"#Source-code\">Source Code</a></li>\n",
    "            <li><a href=\"#MATLAB\">MATLAB</a></li>\n",
    "        </ol>\n",
    "    &nbsp;\n",
    "    <li><a href=\"#Usage\">Usage</a></li>\n",
    "        <ol>\n",
    "            <li><a href=\"#From-vector\">From Vector</a></li>\n",
    "            <li><a href=\"#Direct-CM\">Direct CM</a></li>\n",
    "            <li><a href=\"#Iterating-and-casting\">Iterating And Casting</a></li>\n",
    "            <li><a href=\"#Activation-threshold\">Activation Threshold</a></li>\n",
    "            <li><a href=\"#Load-from-file\">Load From File</a></li>\n",
    "            <li><a href=\"#Sample-weights\">Sample Weights</a></li>\n",
    "            <li><a href=\"#Transpose\">Transpose</a></li>\n",
    "            <li><a href=\"#Metrics-off\">Metrics Off</a></li>\n",
    "            <li><a href=\"#Relabel\">Relabel</a></li>\n",
    "            <li><a href=\"#Position\">Position</a></li>\n",
    "            <li><a href=\"#To-array\">To Array</a></li>\n",
    "            <li><a href=\"#Combine\">Combine</a></li>\n",
    "            <li><a href=\"#Plot\">Plot</a></li>\n",
    "            <li><a href=\"#Distance/Similarity\">Distance/Similarity</a></li>\n",
    "            <li><a href=\"#Parameter-recommender\">Parameter Recommender</a></li>\n",
    "            <li><a href=\"#Compare\">Compare</a></li>\n",
    "            <li><a href=\"#ROC-curve\">ROC Curve</a></li>\n",
    "            <li><a href=\"#Precision-Recall-curve\">Precision-Recall Curve</a></li>\n",
    "            <li><a href=\"#Multilabel-confusion-matrix\">Multilabel Confusion Matrix</a></li>\n",
    "            <li><a href=\"#Online-help\">Online Help</a></li>\n",
    "            <li><a href=\"#Acceptable-data-types\">Acceptable Data Types</a></li>\n",
    "        </ol>\n",
    "    &nbsp;\n",
    "    <li><a href=\"#Basic-parameters\">Basic Parameters</a></li>\n",
    "    <ol>\n",
    "        <li><a href=\"#TP-(True-positive)\">True Positive</a></li>\n",
    "        <li><a href=\"#TN-(True-negative)\">True Negative</a></li>\n",
    "        <li><a href=\"#FP-(False-positive)\">False Positive</a></li>\n",
    "        <li><a href=\"#FN-(False-negative)\">False Negative</a></li>\n",
    "        <li><a href=\"#P-(Condition-positive)\">Condition Positive</a></li>\n",
    "        <li><a href=\"#N-(Condition-negative)\">Condition Negative</a></li>\n",
    "        <li><a href=\"#TOP-(Test-outcome-positive)\">Test Outcome Positive</a></li>\n",
    "        <li><a href=\"#TON-(Test-outcome-negative)\">Test Outcome Negative</a></li>\n",
    "        <li><a href=\"#POP-(Population)\">Population</a></li>\n",
    "    </ol>\n",
    "    &nbsp;\n",
    "    <li><a href=\"#Class-statistics\">Class Statistics</a></li>\n",
    "    <ol>\n",
    "        <li><a href=\"#TPR-(True-positive-rate)\">True Positive Rate</a></li>\n",
    "        <li><a href=\"#TNR-(True-negative-rate)\">True Negative Rate</a></li>\n",
    "        <li><a href=\"#PPV-(Positive-predictive-value)\">Positive Predictive Value</a></li>\n",
    "        <li><a href=\"#NPV-(Negative-predictive-value)\">Negative Predictive Value</a></li>\n",
    "        <li><a href=\"#FNR-(False-negative-rate)\">False Negative Rate</a></li>\n",
    "        <li><a href=\"#FPR-(False-positive-rate)\">False Positive Rate</a></li>\n",
    "        <li><a href=\"#FDR-(False-discovery-rate)\">False Discovery Rate</a></li>\n",
    "        <li><a href=\"#FOR-(False-omission-rate)\">False Omission Rate</a></li>\n",
    "        <li><a href=\"#ACC-(Accuracy)\">Accuracy</a></li>\n",
    "        <li><a href=\"#ERR-(Error-rate)\">Error Rate</a></li>\n",
    "        <li><a href=\"#FBeta-Score\">FBeta Score</a></li>\n",
    "        <li><a href=\"#MCC-(Matthews-correlation-coefficient)\">Matthews Correlation Coefficient</a></li>\n",
    "        <li><a href=\"#BM-(Bookmaker-informedness)\">Informedness</a></li>\n",
    "        <li><a href=\"#MK-(Markedness)\">Markedness</a></li>\n",
    "        <li><a href=\"#PLR-(Positive-likelihood-ratio)\">Positive Likelihood Ratio</a></li>\n",
    "        <li><a href=\"#NLR-(Negative-likelihood-ratio)\">Negative Likelihood Ratio</a></li>\n",
    "        <li><a href=\"#DOR-(Diagnostic-odds-ratio)\">Diagnostic Odds Ratio</a></li>\n",
    "        <li><a href=\"#PRE-(Prevalence)\">Prevalence</a></li>\n",
    "        <li><a href=\"#G-(G-measure)\">G-Measure</a></li>\n",
    "        <li><a href=\"#RACC-(Random-accuracy)\">Random Accuracy</a></li>\n",
    "        <li><a href=\"#RACCU-(Random-accuracy-unbiased)\">Random Accuracy Unbiased</a></li>\n",
    "        <li><a href=\"#J-(Jaccard-index)\">Jaccard Index</a></li>\n",
    "        <li><a href=\"#IS-(Information-score)\">Information Score</a></li>\n",
    "        <li><a href=\"#CEN-(Confusion-entropy)\">Confusion Entropy</a></li>\n",
    "        <li><a href=\"#MCEN-(Modified-confusion-entropy)\">Modified Confusion Entropy</a></li>\n",
    "        <li><a href=\"#AUC-(Area-under-the-ROC-curve)\">Area Under The ROC Curve</a></li>\n",
    "        <li><a href=\"#dInd-(Distance-index)\">Distance Index</a></li>\n",
    "        <li><a href=\"#sInd-(Similarity-index)\">Similarity Index</a></li>\n",
    "        <li><a href=\"#DP-(Discriminant-power)\">Discriminant Power</a></li>\n",
    "        <li><a href=\"#Y-(Youden-index)\">Youden Index</a></li>\n",
    "        <li><a href=\"#PLRI-(Positive-likelihood-ratio-interpretation)\">Positive Likelihood Ratio Interpretation</a></li>\n",
    "        <li><a href=\"#NLRI-(Negative-likelihood-ratio-interpretation)\">Negative Likelihood Ratio Interpretation</a></li>\n",
    "        <li><a href=\"#DPI-(Discriminant-power-interpretation)\">Discriminant Power Interpretation</a></li>\n",
    "        <li><a href=\"#AUCI-(AUC-value-interpretation)\">AUC Value Interpretation</a></li>\n",
    "        <li><a href=\"#MCCI-(Matthews-correlation-coefficient-interpretation)\">Matthews Correlation Coefficient Interpretation</a></li>\n",
    "        <li><a href=\"#QI-(Yule's-Q-interpretation)\">Yule's Q Interpretation</a></li>\n",
    "        <li><a href=\"#GI-(Gini-index)\">Gini Index</a></li>\n",
    "        <li><a href=\"#LS-(Lift-score)\">Lift Score</a></li>\n",
    "        <li><a href=\"#AM-(Automatic/Manual)\">Automatic/Manual</a></li>\n",
    "        <li><a href=\"#BCD-(Bray-Curtis-dissimilarity)\">Bray-Curtis Dissimilarity</a></li>\n",
    "        <li><a href=\"#OP-(Optimized-precision)\">Optimized Precision</a></li>\n",
    "        <li><a href=\"#IBA-(Index-of-balanced-accuracy)\">Index of Balanced Accuracy</a></li>\n",
    "        <li><a href=\"#GM-(G-mean)\">G-Mean</a></li>\n",
    "        <li><a href=\"#Q-(Yule's-Q)\">Yule's Q</a></li>\n",
    "        <li><a href=\"#AGM-(Adjusted-G-mean)\">Adjusted G-Mean</a></li> \n",
    "        <li><a href=\"#AGF-(Adjusted-F-score)\">Adjusted F-Score</a></li>\n",
    "        <li><a href=\"#OC-(Overlap-coefficient)\">Overlap Coefficient</a></li>\n",
    "        <li><a href=\"#BB-(Braun-Blanquet-similarity)\">Braun-Blanquet Similarity</a></li>\n",
    "        <li><a href=\"#OOC-(Otsuka-Ochiai-coefficient)\">Otsuka Ochiai Coefficient</a></li>\n",
    "        <li><a href=\"#TI-(Tversky-index)\">Tversky Index</a></li> \n",
    "        <li><a href=\"#AUPR-(Area-under-the-PR-curve)\">Area Under The PR Curve</a></li> \n",
    "        <li><a href=\"#ICSI-(Individual-classification-success-index)\">Individual Classification Success Index</a></li> \n",
    "        <li><a href=\"#CI-(Confidence-interval)\">Confidence Interval</a></li> \n",
    "        <li><a href=\"#NB-(Net-benefit)\">Net Benefit</a></li>\n",
    "        <li><a href=\"#Average\">Average</a></li>\n",
    "        <li><a href=\"#Weighted-average\">Weighted Average</a></li>\n",
    "        <li><a href=\"#Sensitivity-index\">Sensitivity Index</a></li>\n",
    "        <li><a href=\"#HD-(Hamming-distance)\">Hamming Distance</a></li>\n",
    "    </ol>\n",
    "    &nbsp;\n",
    "    <li><a href=\"#Overall-statistics\">Overall Statistics</a></li>\n",
    "    <ol>\n",
    "        <li><a href=\"#Kappa\">Kappa</a></li>\n",
    "        <li><a href=\"#Kappa-unbiased\">Kappa Unbiased</a></li>\n",
    "        <li><a href=\"#Kappa-no-prevalence\">Kappa No Prevalence</a></li>\n",
    "        <li><a href=\"#Weighted-kappa\">Weighted Kappa</a></li>\n",
    "        <li><a href=\"#Kappa-standard-error\">Kappa Standard Error</a></li>\n",
    "        <li><a href=\"#Kappa-95%-CI\">Kappa 95% CI</a></li>\n",
    "        <li><a href=\"#Chi-squared\">Chi Squared</a></li>\n",
    "        <li><a href=\"#Chi-squared-DF\">Chi Squared DF</a></li>\n",
    "        <li><a href=\"#Phi-squared\">Phi Squared</a></li>\n",
    "        <li><a href=\"#Cramer's-V\">Cramer's V</a></li>\n",
    "        <li><a href=\"#Standard-error\">Standard Error</a></li>\n",
    "        <li><a href=\"#95%-CI\">95% CI</a></li>\n",
    "        <li><a href=\"#Bennett's-S\">Bennett's S</a></li>\n",
    "        <li><a href=\"#Scott's-Pi\">Scott's PI</a></li>\n",
    "        <li><a href=\"#Gwet's-AC1\">Gwet's AC1</a></li>\n",
    "        <li><a href=\"#Reference-entropy\">Reference Entropy</a></li>\n",
    "        <li><a href=\"#Response-entropy\">Response Entropy</a></li>\n",
    "        <li><a href=\"#Cross-entropy\">Cross Entropy</a></li>\n",
    "        <li><a href=\"#Joint-entropy\">Joint Entropy</a></li>\n",
    "        <li><a href=\"#Conditional-entropy\">Conditional Entropy</a></li>\n",
    "        <li><a href=\"#Kullback-Leibler-divergence\">Kullback-Leibler Divergence</a></li>\n",
    "        <li><a href=\"#Mutual-information\">Mutual Information</a></li>\n",
    "        <li><a href=\"#Goodman-&-Kruskal's-lambda-A\">Goodman-Kruskal's Lambda A</a></li>\n",
    "        <li><a href=\"#Goodman-&-Kruskal's-lambda-B\">Goodman-Kruskal's Lambda B</a></li>\n",
    "        <li><a href=\"#SOA1-(Landis-&-Koch's-benchmark)\">Landis-Koch's Benchmark</a></li>\n",
    "        <li><a href=\"#SOA2-(Fleiss'-benchmark)\">Fleiss' Benchmark</a></li>\n",
    "        <li><a href=\"#SOA3-(Altman's-benchmark)\">Altman's Benchmark</a></li>\n",
    "        <li><a href=\"#SOA4-(Cicchetti's-benchmark)\">Cicchetti's Benchmark</a></li>\n",
    "        <li><a href=\"#SOA5-(Cramer's-benchmark)\">Cramer's Benchmark</a></li>\n",
    "        <li><a href=\"#SOA6-(Matthews's-benchmark)\">Matthews's Benchmark</a></li>\n",
    "        <li><a href=\"#SOA7-(Goodman-&-Kruskal's-lambda-A-benchmark)\">Goodman-Kruskal's Lambda A Benchmark</a></li>\n",
    "        <li><a href=\"#SOA8-(Goodman-&-Kruskal's-lambda-B-benchmark)\">Goodman-Kruskal's Lambda B Benchmark</a></li>\n",
    "        <li><a href=\"#SOA9-(Krippendorff's-alpha-benchmark)\">Krippendorff's Alpha Benchmark</a></li>\n",
    "        <li><a href=\"#SOA10-(Pearson's-C-benchmark)\">Pearson's C Benchmark</a></li>\n",
    "        <li><a href=\"#Overall_ACC\">Overall Accuracy</a></li>\n",
    "        <li><a href=\"#Overall_RACC\">Overall Random Accuracy</a></li>\n",
    "        <li><a href=\"#Overall_RACCU\">Overall Random Accuracy Unbiased</a></li>\n",
    "        <li><a href=\"#PPV_Micro\">Positive Predictive Value Micro</a></li>\n",
    "        <li><a href=\"#NPV_Micro\">Negative Predictive Value Micro</a></li>\n",
    "        <li><a href=\"#TPR_Micro\">True Positive Rate Micro</a></li>\n",
    "        <li><a href=\"#TNR_Micro\">True Negative Rate Micro</a></li>\n",
    "        <li><a href=\"#FPR_Micro\">False Positive Rate Micro</a></li>\n",
    "        <li><a href=\"#FNR_Micro\">False Negative Rate Micro</a></li>\n",
    "        <li><a href=\"#F1_Micro\">F1 Score Micro</a></li>\n",
    "        <li><a href=\"#PPV_Macro\">Positive Predictive Value Macro</a></li>\n",
    "        <li><a href=\"#NPV_Macro\">Negative Predictive Value Macro</a></li>\n",
    "        <li><a href=\"#TPR_Macro\">True Positive Rate Macro</a></li>\n",
    "        <li><a href=\"#TNR_Macro\">True Negative Rate Macro</a></li>\n",
    "        <li><a href=\"#FPR_Macro\">False Positive Rate Macro</a></li>\n",
    "        <li><a href=\"#FNR_Macro\">False Negative Rate Macro</a></li>\n",
    "        <li><a href=\"#F1_Macro\">F1 Score Macro</a></li>\n",
    "        <li><a href=\"#ACC_Macro\">Accuracy Macro</a></li>\n",
    "        <li><a href=\"#Overall_J\">Overall Jaccard Index</a></li>\n",
    "        <li><a href=\"#Hamming-loss\">Hamming Loss</a></li>\n",
    "        <li><a href=\"#Zero-one-loss\">Zero-one Loss</a></li>\n",
    "        <li><a href=\"#NIR-(No-information-rate)\">No Information Rate</a></li>\n",
    "        <li><a href=\"#P-Value\">P Value</a></li>\n",
    "        <li><a href=\"#Overall_CEN\">Overall Confusion Entropy</a></li>\n",
    "        <li><a href=\"#Overall_MCEN\">Overall Modified Confusion Entropy</a></li>\n",
    "        <li><a href=\"#Overall_MCC\">Overall Matthews Correlation Coefficient</a></li>\n",
    "        <li><a href=\"#RR-(Global-performance-index)\">Global Performance Index</a></li>\n",
    "        <li><a href=\"#CBA-(Class-balance-accuracy)\">Class Balance Accuracy</a></li>\n",
    "        <li><a href=\"#AUNU\">AUNU</a></li>\n",
    "        <li><a href=\"#AUNP\">AUNP</a></li>\n",
    "        <li><a href=\"#RCI-(Relative-classifier-information)\">Relative Classifier Information</a></li>\n",
    "        <li><a href=\"#Pearson's-C\">Pearson's C</a></li>\n",
    "        <li><a href=\"#CSI-(Classification-success-index)\">Classification Success Index</a></li>\n",
    "        <li><a href=\"#ARI-(Adjusted-Rand-index)\">Adjusted Rand Index</a></li>\n",
    "        <li><a href=\"#Bangdiwala's-B\">Bangdiwala's B</a></li>\n",
    "        <li><a href=\"#Krippendorff's-alpha\">Krippendorff's Alpha</a></li>\n",
    "        <li><a href=\"#Weighted-alpha\">Weighted Alpha</a></li>\n",
    "        <li><a href=\"#Aickin's-alpha\">Aickin's Alpha</a></li>\n",
    "        <li><a href=\"#Brier-score\">Brier Score</a></li>\n",
    "        <li><a href=\"#Log-loss\">Log Loss</a></li>\n",
    "    </ol>\n",
    "    &nbsp;\n",
    "    <li><a href=\"#Print\">Print</a></li>\n",
    "    <ol>\n",
    "        <li><a href=\"#Full\">Full</a></li>\n",
    "        <li><a href=\"#Matrix\">Matrix</a></li>\n",
    "        <li><a href=\"#Normalized-matrix\">Normalized Matrix</a></li>\n",
    "        <li><a href=\"#Stat\">Stat</a></li>\n",
    "        <li><a href=\"#Compare-report\">Compare Report</a></li>\n",
    "    </ol>\n",
    "    &nbsp;\n",
    "    <li><a href=\"#Save\">Save</a></li>\n",
    "    <ol>\n",
    "        <li><a href=\"#.pycm-file\">pycm</a></li>\n",
    "        <li><a href=\"#HTML\">HTML</a></li>\n",
    "        <li><a href=\"#CSV\">CSV</a></li>\n",
    "        <li><a href=\"#OBJ\">object</a></li>\n",
    "        <li><a href=\"#comp\">comp</a></li>\n",
    "    </ol>\n",
    "    &nbsp;\n",
    "    <li><a href=\"#Input-errors\">Input Errors</a></li>\n",
    "    <li><a href=\"#Examples\">Examples</a></li>\n",
    "    <li><a href=\"#Cite\">Cite</a></li>\n",
    "    <li><a href=\"#References\">References</a></li>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Overview"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<p style=\"text-align:justify;\">\n",
    "PyCM is a multi-class confusion matrix library written in Python that supports both input data vectors and direct matrix, and a proper tool for post-classification model evaluation that supports most classes and overall statistics parameters.\t\n",
    "PyCM is the swiss-army knife of confusion matrices, targeted mainly at data scientists that need a broad array of metrics for predictive models and accurate evaluation of a large variety of classifiers.\n",
    "</p>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div style=\"text-align:center;\">\n",
    "    <img src=\"../Otherfiles/block_diagram.jpg\" onerror='this.src=\"../images/block_diagram.jpg\"' width=\"700\">\n",
    "</div>\n",
    "<center><p style=\"text-align:center;\">Fig1. ConfusionMatrix Block Diagram</p></center>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Installation\t"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "⚠️  PyCM 3.9 is the last version to support **Python 3.5**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "⚠️  PyCM 2.4 is the last version to support **Python 2.7** & **Python 3.4**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "⚠️  Plotting capability requires **Matplotlib (>= 3.0.0)** or **Seaborn (>= 0.9.1)**   "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### PyPI\n",
    "\n",
    "\n",
    "- Check [Python Packaging User Guide](https://packaging.python.org/installing/)     \n",
    "- Run `pip install pycm==4.2`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Source code\n",
    "- Download [Version 4.2](https://github.com/sepandhaghighi/pycm/archive/v4.2.zip) or [Latest Source](https://github.com/sepandhaghighi/pycm/archive/dev.zip)\n",
    "- Run `pip install .`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Conda\n",
    "\n",
    "- Check [Conda Managing Package](https://conda.io/docs/user-guide/tasks/manage-pkgs.html#installing-packages-from-anaconda-org)\n",
    "- `conda install -c sepandhaghighi pycm`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### MATLAB"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Download and install [MATLAB](https://www.mathworks.com/products/matlab.html) (>=8.5, 64/32 bit)\n",
    "- Download and install [Python3.x](https://www.python.org/downloads/) (>=3.6, 64/32 bit) \n",
    "\t- Select `Add to PATH` option\n",
    "\t- Select `Install pip` option\n",
    "- Run `pip install pycm` or `pip3 install pycm`\n",
    "- Configure Python interpreter\n",
    "```\n",
    ">> pyversion PYTHON_EXECUTABLE_FULL_PATH\n",
    "```\n",
    "- Visit [MATLAB Examples](https://github.com/sepandhaghighi/pycm/tree/master/MATLAB)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Usage"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Environment check"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Checking that the notebook is running on Google Colab or not."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n",
    "try:\n",
    "  import google.colab\n",
    "  !{sys.executable} -m pip -q -q install pycm\n",
    "except:\n",
    "  pass"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### From vector"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pycm import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "y_actu = [2, 0, 2, 2, 0, 1, 1, 2, 2, 0, 1, 2]\n",
    "y_pred = [0, 0, 2, 1, 0, 2, 1, 0, 2, 0, 2, 2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "cm = ConfusionMatrix(y_actu, y_pred,digit=5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li> <span style=\"color:red;\">Notice </span> :  <code>digit</code> (the number of digits to the right of the decimal point in a number) is new in <span style=\"color:red;\">version 0.6</span> (default value : 5)</li>\n",
    "    <li>Only for print and save</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pycm.ConfusionMatrix(classes: [0, 1, 2])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[2, 0, 2, 2, 0, 1, 1, 2, 2, 0, 1, 2]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.actual_vector"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 0, 2, 1, 0, 2, 1, 0, 2, 0, 2, 2]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.predict_vector"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 1, 2]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.classes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'ACC': {0: 0.8333333333333334, 1: 0.75, 2: 0.5833333333333334},\n",
       " 'AGF': {0: 0.9135962935560564, 1: 0.5399492471560389, 2: 0.5515973485146916},\n",
       " 'AGM': {0: 0.837285964012303, 1: 0.6919986974962765, 2: 0.6071224016819726},\n",
       " 'AM': {0: 2, 1: -1, 2: -1},\n",
       " 'AUC': {0: 0.8888888888888888, 1: 0.611111111111111, 2: 0.5833333333333333},\n",
       " 'AUCI': {0: 'Very Good', 1: 'Fair', 2: 'Poor'},\n",
       " 'AUPR': {0: 0.8, 1: 0.41666666666666663, 2: 0.55},\n",
       " 'BB': {0: 0.6, 1: 0.3333333333333333, 2: 0.5},\n",
       " 'BCD': {0: 0.08333333333333333,\n",
       "  1: 0.041666666666666664,\n",
       "  2: 0.041666666666666664},\n",
       " 'BM': {0: 0.7777777777777777, 1: 0.2222222222222221, 2: 0.16666666666666652},\n",
       " 'CEN': {0: 0.25, 1: 0.49657842846620864, 2: 0.6044162769630221},\n",
       " 'DOR': {0: 'None', 1: 3.999999999999998, 2: 1.9999999999999998},\n",
       " 'DP': {0: 'None', 1: 0.331933069996499, 2: 0.16596653499824957},\n",
       " 'DPI': {0: 'None', 1: 'Poor', 2: 'Poor'},\n",
       " 'ERR': {0: 0.16666666666666663, 1: 0.25, 2: 0.41666666666666663},\n",
       " 'F0.5': {0: 0.6521739130434783,\n",
       "  1: 0.45454545454545453,\n",
       "  2: 0.5769230769230769},\n",
       " 'F1': {0: 0.75, 1: 0.4, 2: 0.5454545454545454},\n",
       " 'F2': {0: 0.8823529411764706, 1: 0.35714285714285715, 2: 0.5172413793103449},\n",
       " 'FDR': {0: 0.4, 1: 0.5, 2: 0.4},\n",
       " 'FN': {0: 0, 1: 2, 2: 3},\n",
       " 'FNR': {0: 0.0, 1: 0.6666666666666667, 2: 0.5},\n",
       " 'FOR': {0: 0.0, 1: 0.19999999999999996, 2: 0.4285714285714286},\n",
       " 'FP': {0: 2, 1: 1, 2: 2},\n",
       " 'FPR': {0: 0.2222222222222222,\n",
       "  1: 0.11111111111111116,\n",
       "  2: 0.33333333333333337},\n",
       " 'G': {0: 0.7745966692414834, 1: 0.408248290463863, 2: 0.5477225575051661},\n",
       " 'GI': {0: 0.7777777777777777, 1: 0.2222222222222221, 2: 0.16666666666666652},\n",
       " 'GM': {0: 0.8819171036881969, 1: 0.5443310539518174, 2: 0.5773502691896257},\n",
       " 'HD': {0: 2, 1: 3, 2: 5},\n",
       " 'IBA': {0: 0.9506172839506174, 1: 0.1316872427983539, 2: 0.2777777777777778},\n",
       " 'ICSI': {0: 0.6000000000000001,\n",
       "  1: -0.16666666666666674,\n",
       "  2: 0.10000000000000009},\n",
       " 'IS': {0: 1.263034405833794, 1: 1.0, 2: 0.2630344058337938},\n",
       " 'J': {0: 0.6, 1: 0.25, 2: 0.375},\n",
       " 'LS': {0: 2.4, 1: 2.0, 2: 1.2},\n",
       " 'MCC': {0: 0.6831300510639732, 1: 0.25819888974716115, 2: 0.1690308509457033},\n",
       " 'MCCI': {0: 'Moderate', 1: 'Negligible', 2: 'Negligible'},\n",
       " 'MCEN': {0: 0.2643856189774724, 1: 0.5, 2: 0.6875},\n",
       " 'MK': {0: 0.6000000000000001, 1: 0.30000000000000004, 2: 0.17142857142857126},\n",
       " 'N': {0: 9, 1: 9, 2: 6},\n",
       " 'NLR': {0: 0.0, 1: 0.7500000000000001, 2: 0.75},\n",
       " 'NLRI': {0: 'Good', 1: 'Negligible', 2: 'Negligible'},\n",
       " 'NPV': {0: 1.0, 1: 0.8, 2: 0.5714285714285714},\n",
       " 'OC': {0: 1.0, 1: 0.5, 2: 0.6},\n",
       " 'OOC': {0: 0.7745966692414834, 1: 0.4082482904638631, 2: 0.5477225575051661},\n",
       " 'OP': {0: 0.7083333333333334, 1: 0.2954545454545454, 2: 0.4404761904761905},\n",
       " 'P': {0: 3, 1: 3, 2: 6},\n",
       " 'PLR': {0: 4.5, 1: 2.9999999999999987, 2: 1.4999999999999998},\n",
       " 'PLRI': {0: 'Poor', 1: 'Poor', 2: 'Poor'},\n",
       " 'POP': {0: 12, 1: 12, 2: 12},\n",
       " 'PPV': {0: 0.6, 1: 0.5, 2: 0.6},\n",
       " 'PRE': {0: 0.25, 1: 0.25, 2: 0.5},\n",
       " 'Q': {0: 'None', 1: 0.6, 2: 0.3333333333333333},\n",
       " 'QI': {0: 'None', 1: 'Moderate', 2: 'Weak'},\n",
       " 'RACC': {0: 0.10416666666666667,\n",
       "  1: 0.041666666666666664,\n",
       "  2: 0.20833333333333334},\n",
       " 'RACCU': {0: 0.1111111111111111,\n",
       "  1: 0.04340277777777778,\n",
       "  2: 0.21006944444444442},\n",
       " 'TN': {0: 7, 1: 8, 2: 4},\n",
       " 'TNR': {0: 0.7777777777777778, 1: 0.8888888888888888, 2: 0.6666666666666666},\n",
       " 'TON': {0: 7, 1: 10, 2: 7},\n",
       " 'TOP': {0: 5, 1: 2, 2: 5},\n",
       " 'TP': {0: 3, 1: 1, 2: 3},\n",
       " 'TPR': {0: 1.0, 1: 0.3333333333333333, 2: 0.5},\n",
       " 'Y': {0: 0.7777777777777777, 1: 0.2222222222222221, 2: 0.16666666666666652},\n",
       " 'dInd': {0: 0.2222222222222222, 1: 0.6758625033664689, 2: 0.6009252125773316},\n",
       " 'sInd': {0: 0.8428651597363228, 1: 0.5220930407198541, 2: 0.5750817072006014}}"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.class_stat"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  <code>cm.statistic_result</code> prev versions (0.2 >)</li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'95% CI': (0.30438856248221097, 0.8622781041844558),\n",
       " 'ACC Macro': 0.7222222222222223,\n",
       " 'ARI': 0.09206349206349207,\n",
       " 'AUNP': 0.6666666666666666,\n",
       " 'AUNU': 0.6944444444444443,\n",
       " 'Bangdiwala B': 0.37254901960784315,\n",
       " 'Bennett S': 0.37500000000000006,\n",
       " 'CBA': 0.4777777777777778,\n",
       " 'CSI': 0.1777777777777778,\n",
       " 'Chi-Squared': 6.6,\n",
       " 'Chi-Squared DF': 4,\n",
       " 'Conditional Entropy': 0.9591479170272448,\n",
       " 'Cramer V': 0.5244044240850757,\n",
       " 'Cross Entropy': 1.5935164295556343,\n",
       " 'F1 Macro': 0.5651515151515151,\n",
       " 'F1 Micro': 0.5833333333333334,\n",
       " 'FNR Macro': 0.38888888888888895,\n",
       " 'FNR Micro': 0.41666666666666663,\n",
       " 'FPR Macro': 0.22222222222222232,\n",
       " 'FPR Micro': 0.20833333333333337,\n",
       " 'Gwet AC1': 0.3893129770992367,\n",
       " 'Hamming Loss': 0.41666666666666663,\n",
       " 'Joint Entropy': 2.4591479170272446,\n",
       " 'KL Divergence': 0.09351642955563438,\n",
       " 'Kappa': 0.35483870967741943,\n",
       " 'Kappa 95% CI': (-0.07707577422109269, 0.7867531935759315),\n",
       " 'Kappa No Prevalence': 0.16666666666666674,\n",
       " 'Kappa Standard Error': 0.2203645326012817,\n",
       " 'Kappa Unbiased': 0.34426229508196726,\n",
       " 'Krippendorff Alpha': 0.3715846994535519,\n",
       " 'Lambda A': 0.16666666666666666,\n",
       " 'Lambda B': 0.42857142857142855,\n",
       " 'Mutual Information': 0.5242078379544426,\n",
       " 'NIR': 0.5,\n",
       " 'NPV Macro': 0.7904761904761904,\n",
       " 'NPV Micro': 0.7916666666666666,\n",
       " 'Overall ACC': 0.5833333333333334,\n",
       " 'Overall CEN': 0.4638112995385119,\n",
       " 'Overall J': (1.225, 0.4083333333333334),\n",
       " 'Overall MCC': 0.36666666666666664,\n",
       " 'Overall MCEN': 0.5189369467580801,\n",
       " 'Overall RACC': 0.3541666666666667,\n",
       " 'Overall RACCU': 0.3645833333333333,\n",
       " 'P-Value': 0.38720703125,\n",
       " 'PPV Macro': 0.5666666666666668,\n",
       " 'PPV Micro': 0.5833333333333334,\n",
       " 'Pearson C': 0.5956833971812705,\n",
       " 'Phi-Squared': 0.5499999999999999,\n",
       " 'RCI': 0.3494718919696284,\n",
       " 'RR': 4.0,\n",
       " 'Reference Entropy': 1.5,\n",
       " 'Response Entropy': 1.4833557549816874,\n",
       " 'SOA1(Landis & Koch)': 'Fair',\n",
       " 'SOA10(Pearson C)': 'Strong',\n",
       " 'SOA2(Fleiss)': 'Poor',\n",
       " 'SOA3(Altman)': 'Fair',\n",
       " 'SOA4(Cicchetti)': 'Poor',\n",
       " 'SOA5(Cramer)': 'Relatively Strong',\n",
       " 'SOA6(Matthews)': 'Weak',\n",
       " 'SOA7(Lambda A)': 'Very Weak',\n",
       " 'SOA8(Lambda B)': 'Moderate',\n",
       " 'SOA9(Krippendorff Alpha)': 'Low',\n",
       " 'Scott PI': 0.34426229508196726,\n",
       " 'Standard Error': 0.14231876063832777,\n",
       " 'TNR Macro': 0.7777777777777777,\n",
       " 'TNR Micro': 0.7916666666666666,\n",
       " 'TPR Macro': 0.611111111111111,\n",
       " 'TPR Micro': 0.5833333333333334,\n",
       " 'Zero-one Loss': 5}"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.overall_stat"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.3</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  <code>_</code> removed from overall statistics names in <span style=\"color:red;\">version 1.6</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{0: {0: 3, 1: 0, 2: 0}, 1: {0: 0, 1: 1, 2: 2}, 2: {0: 2, 1: 1, 2: 3}}"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{0: {0: 3, 1: 0, 2: 0}, 1: {0: 0, 1: 1, 2: 2}, 2: {0: 2, 1: 1, 2: 3}}"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.matrix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{0: {0: 1.0, 1: 0.0, 2: 0.0},\n",
       " 1: {0: 0.0, 1: 0.33333, 2: 0.66667},\n",
       " 2: {0: 0.33333, 1: 0.16667, 2: 0.5}}"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.normalized_matrix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{0: {0: 1.0, 1: 0.0, 2: 0.0},\n",
       " 1: {0: 0.0, 1: 0.33333, 2: 0.66667},\n",
       " 2: {0: 0.33333, 1: 0.16667, 2: 0.5}}"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.normalized_table"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> : <code>matrix</code>, <code>normalized_matrix</code> & <code>normalized_table</code> added in <span style=\"color:red;\">version 1.5</span> (changed from print style)</li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "y_actu = numpy.array([2, 0, 2, 2, 0, 1, 1, 2, 2, 0, 1, 2])\n",
    "y_pred = numpy.array([0, 0, 2, 1, 0, 2, 1, 0, 2, 0, 2, 2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "cm = ConfusionMatrix(y_actu, y_pred,digit=5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pycm.ConfusionMatrix(classes: [0, 1, 2])"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> : <code>numpy.array</code> support in <span style=\"color:red;\">versions > 0.7</span></li>\n",
    "</ul>  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "cm = ConfusionMatrix(y_actu, y_pred, classes=[1, 0, 2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Predict 1       0       2       \n",
      "Actual\n",
      "1       1       0       2       \n",
      "\n",
      "0       0       3       0       \n",
      "\n",
      "2       1       2       3       \n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "cm.print_matrix()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "cm = ConfusionMatrix(y_actu, y_pred, classes=[0, 1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Predict 0       1       \n",
      "Actual\n",
      "0       3       0       \n",
      "\n",
      "1       0       1       \n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "cm.print_matrix()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\Sepkjaer\\AppData\\Local\\Programs\\Python\\Python35-32\\lib\\site-packages\\pycm-4.2-py3.5.egg\\pycm\\utils.py:399: RuntimeWarning: Specified classes are not a subset of the classes in the actual and predicted vectors.\n"
     ]
    }
   ],
   "source": [
    "cm = ConfusionMatrix(y_actu, y_pred, classes=[1, 0, 4])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Predict 1       0       4       \n",
      "Actual\n",
      "1       1       0       0       \n",
      "\n",
      "0       0       3       0       \n",
      "\n",
      "4       0       0       0       \n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "cm.print_matrix()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> : <code>classes</code> added in <span style=\"color:red;\">version 3.2</span></li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1 in cm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "10 in cm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm[1][1]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> : <code>__getitem__</code> and <code>__contains__</code> methods added in <span style=\"color:red;\">version 3.8</span></li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Direct CM"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "cm2 = ConfusionMatrix(matrix={0: {0: 3, 1: 0, 2: 0}, 1: {0: 0, 1: 1, 2: 2}, 2: {0: 2, 1: 1, 2: 3}}, digit=5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pycm.ConfusionMatrix(classes: [0, 1, 2])"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "cm2.actual_vector"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "cm2.predict_vector"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 1, 2]"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm2.classes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'ACC': {0: 0.8333333333333334, 1: 0.75, 2: 0.5833333333333334},\n",
       " 'AGF': {0: 0.9135962935560564, 1: 0.5399492471560389, 2: 0.5515973485146916},\n",
       " 'AGM': {0: 0.837285964012303, 1: 0.6919986974962765, 2: 0.6071224016819726},\n",
       " 'AM': {0: 2, 1: -1, 2: -1},\n",
       " 'AUC': {0: 0.8888888888888888, 1: 0.611111111111111, 2: 0.5833333333333333},\n",
       " 'AUCI': {0: 'Very Good', 1: 'Fair', 2: 'Poor'},\n",
       " 'AUPR': {0: 0.8, 1: 0.41666666666666663, 2: 0.55},\n",
       " 'BB': {0: 0.6, 1: 0.3333333333333333, 2: 0.5},\n",
       " 'BCD': {0: 0.08333333333333333,\n",
       "  1: 0.041666666666666664,\n",
       "  2: 0.041666666666666664},\n",
       " 'BM': {0: 0.7777777777777777, 1: 0.2222222222222221, 2: 0.16666666666666652},\n",
       " 'CEN': {0: 0.25, 1: 0.49657842846620864, 2: 0.6044162769630221},\n",
       " 'DOR': {0: 'None', 1: 3.999999999999998, 2: 1.9999999999999998},\n",
       " 'DP': {0: 'None', 1: 0.331933069996499, 2: 0.16596653499824957},\n",
       " 'DPI': {0: 'None', 1: 'Poor', 2: 'Poor'},\n",
       " 'ERR': {0: 0.16666666666666663, 1: 0.25, 2: 0.41666666666666663},\n",
       " 'F0.5': {0: 0.6521739130434783,\n",
       "  1: 0.45454545454545453,\n",
       "  2: 0.5769230769230769},\n",
       " 'F1': {0: 0.75, 1: 0.4, 2: 0.5454545454545454},\n",
       " 'F2': {0: 0.8823529411764706, 1: 0.35714285714285715, 2: 0.5172413793103449},\n",
       " 'FDR': {0: 0.4, 1: 0.5, 2: 0.4},\n",
       " 'FN': {0: 0, 1: 2, 2: 3},\n",
       " 'FNR': {0: 0.0, 1: 0.6666666666666667, 2: 0.5},\n",
       " 'FOR': {0: 0.0, 1: 0.19999999999999996, 2: 0.4285714285714286},\n",
       " 'FP': {0: 2, 1: 1, 2: 2},\n",
       " 'FPR': {0: 0.2222222222222222,\n",
       "  1: 0.11111111111111116,\n",
       "  2: 0.33333333333333337},\n",
       " 'G': {0: 0.7745966692414834, 1: 0.408248290463863, 2: 0.5477225575051661},\n",
       " 'GI': {0: 0.7777777777777777, 1: 0.2222222222222221, 2: 0.16666666666666652},\n",
       " 'GM': {0: 0.8819171036881969, 1: 0.5443310539518174, 2: 0.5773502691896257},\n",
       " 'HD': {0: 2, 1: 3, 2: 5},\n",
       " 'IBA': {0: 0.9506172839506174, 1: 0.1316872427983539, 2: 0.2777777777777778},\n",
       " 'ICSI': {0: 0.6000000000000001,\n",
       "  1: -0.16666666666666674,\n",
       "  2: 0.10000000000000009},\n",
       " 'IS': {0: 1.263034405833794, 1: 1.0, 2: 0.2630344058337938},\n",
       " 'J': {0: 0.6, 1: 0.25, 2: 0.375},\n",
       " 'LS': {0: 2.4, 1: 2.0, 2: 1.2},\n",
       " 'MCC': {0: 0.6831300510639732, 1: 0.25819888974716115, 2: 0.1690308509457033},\n",
       " 'MCCI': {0: 'Moderate', 1: 'Negligible', 2: 'Negligible'},\n",
       " 'MCEN': {0: 0.2643856189774724, 1: 0.5, 2: 0.6875},\n",
       " 'MK': {0: 0.6000000000000001, 1: 0.30000000000000004, 2: 0.17142857142857126},\n",
       " 'N': {0: 9, 1: 9, 2: 6},\n",
       " 'NLR': {0: 0.0, 1: 0.7500000000000001, 2: 0.75},\n",
       " 'NLRI': {0: 'Good', 1: 'Negligible', 2: 'Negligible'},\n",
       " 'NPV': {0: 1.0, 1: 0.8, 2: 0.5714285714285714},\n",
       " 'OC': {0: 1.0, 1: 0.5, 2: 0.6},\n",
       " 'OOC': {0: 0.7745966692414834, 1: 0.4082482904638631, 2: 0.5477225575051661},\n",
       " 'OP': {0: 0.7083333333333334, 1: 0.2954545454545454, 2: 0.4404761904761905},\n",
       " 'P': {0: 3, 1: 3, 2: 6},\n",
       " 'PLR': {0: 4.5, 1: 2.9999999999999987, 2: 1.4999999999999998},\n",
       " 'PLRI': {0: 'Poor', 1: 'Poor', 2: 'Poor'},\n",
       " 'POP': {0: 12, 1: 12, 2: 12},\n",
       " 'PPV': {0: 0.6, 1: 0.5, 2: 0.6},\n",
       " 'PRE': {0: 0.25, 1: 0.25, 2: 0.5},\n",
       " 'Q': {0: 'None', 1: 0.6, 2: 0.3333333333333333},\n",
       " 'QI': {0: 'None', 1: 'Moderate', 2: 'Weak'},\n",
       " 'RACC': {0: 0.10416666666666667,\n",
       "  1: 0.041666666666666664,\n",
       "  2: 0.20833333333333334},\n",
       " 'RACCU': {0: 0.1111111111111111,\n",
       "  1: 0.04340277777777778,\n",
       "  2: 0.21006944444444442},\n",
       " 'TN': {0: 7, 1: 8, 2: 4},\n",
       " 'TNR': {0: 0.7777777777777778, 1: 0.8888888888888888, 2: 0.6666666666666666},\n",
       " 'TON': {0: 7, 1: 10, 2: 7},\n",
       " 'TOP': {0: 5, 1: 2, 2: 5},\n",
       " 'TP': {0: 3, 1: 1, 2: 3},\n",
       " 'TPR': {0: 1.0, 1: 0.3333333333333333, 2: 0.5},\n",
       " 'Y': {0: 0.7777777777777777, 1: 0.2222222222222221, 2: 0.16666666666666652},\n",
       " 'dInd': {0: 0.2222222222222222, 1: 0.6758625033664689, 2: 0.6009252125773316},\n",
       " 'sInd': {0: 0.8428651597363228, 1: 0.5220930407198541, 2: 0.5750817072006014}}"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm2.class_stat"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'95% CI': (0.30438856248221097, 0.8622781041844558),\n",
       " 'ACC Macro': 0.7222222222222223,\n",
       " 'ARI': 0.09206349206349207,\n",
       " 'AUNP': 0.6666666666666666,\n",
       " 'AUNU': 0.6944444444444443,\n",
       " 'Bangdiwala B': 0.37254901960784315,\n",
       " 'Bennett S': 0.37500000000000006,\n",
       " 'CBA': 0.4777777777777778,\n",
       " 'CSI': 0.1777777777777778,\n",
       " 'Chi-Squared': 6.6,\n",
       " 'Chi-Squared DF': 4,\n",
       " 'Conditional Entropy': 0.9591479170272448,\n",
       " 'Cramer V': 0.5244044240850757,\n",
       " 'Cross Entropy': 1.5935164295556343,\n",
       " 'F1 Macro': 0.5651515151515151,\n",
       " 'F1 Micro': 0.5833333333333334,\n",
       " 'FNR Macro': 0.38888888888888895,\n",
       " 'FNR Micro': 0.41666666666666663,\n",
       " 'FPR Macro': 0.22222222222222232,\n",
       " 'FPR Micro': 0.20833333333333337,\n",
       " 'Gwet AC1': 0.3893129770992367,\n",
       " 'Hamming Loss': 0.41666666666666663,\n",
       " 'Joint Entropy': 2.4591479170272446,\n",
       " 'KL Divergence': 0.09351642955563438,\n",
       " 'Kappa': 0.35483870967741943,\n",
       " 'Kappa 95% CI': (-0.07707577422109269, 0.7867531935759315),\n",
       " 'Kappa No Prevalence': 0.16666666666666674,\n",
       " 'Kappa Standard Error': 0.2203645326012817,\n",
       " 'Kappa Unbiased': 0.34426229508196726,\n",
       " 'Krippendorff Alpha': 0.3715846994535519,\n",
       " 'Lambda A': 0.16666666666666666,\n",
       " 'Lambda B': 0.42857142857142855,\n",
       " 'Mutual Information': 0.5242078379544426,\n",
       " 'NIR': 0.5,\n",
       " 'NPV Macro': 0.7904761904761904,\n",
       " 'NPV Micro': 0.7916666666666666,\n",
       " 'Overall ACC': 0.5833333333333334,\n",
       " 'Overall CEN': 0.4638112995385119,\n",
       " 'Overall J': (1.225, 0.4083333333333334),\n",
       " 'Overall MCC': 0.36666666666666664,\n",
       " 'Overall MCEN': 0.5189369467580801,\n",
       " 'Overall RACC': 0.3541666666666667,\n",
       " 'Overall RACCU': 0.3645833333333333,\n",
       " 'P-Value': 0.38720703125,\n",
       " 'PPV Macro': 0.5666666666666668,\n",
       " 'PPV Micro': 0.5833333333333334,\n",
       " 'Pearson C': 0.5956833971812705,\n",
       " 'Phi-Squared': 0.5499999999999999,\n",
       " 'RCI': 0.3494718919696284,\n",
       " 'RR': 4.0,\n",
       " 'Reference Entropy': 1.5,\n",
       " 'Response Entropy': 1.4833557549816874,\n",
       " 'SOA1(Landis & Koch)': 'Fair',\n",
       " 'SOA10(Pearson C)': 'Strong',\n",
       " 'SOA2(Fleiss)': 'Poor',\n",
       " 'SOA3(Altman)': 'Fair',\n",
       " 'SOA4(Cicchetti)': 'Poor',\n",
       " 'SOA5(Cramer)': 'Relatively Strong',\n",
       " 'SOA6(Matthews)': 'Weak',\n",
       " 'SOA7(Lambda A)': 'Very Weak',\n",
       " 'SOA8(Lambda B)': 'Moderate',\n",
       " 'SOA9(Krippendorff Alpha)': 'Low',\n",
       " 'Scott PI': 0.34426229508196726,\n",
       " 'Standard Error': 0.14231876063832777,\n",
       " 'TNR Macro': 0.7777777777777777,\n",
       " 'TNR Micro': 0.7916666666666666,\n",
       " 'TPR Macro': 0.611111111111111,\n",
       " 'TPR Micro': 0.5833333333333334,\n",
       " 'Zero-one Loss': 5}"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm2.overall_stat"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.8.1</span> </li>\n",
    "    <li>In direct matrix mode <code>actual_vector</code> and <code>predict_vector</code> are empty</li>\n",
    "</ul> "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "array = [[1, 2, 3], [4, 6, 1], [1, 2, 3]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "cm = ConfusionMatrix(matrix=array)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pycm.ConfusionMatrix(classes: [0, 1, 2])"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 1, 2]"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.classes"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  confusion matrices input in array format is new in <span style=\"color:red;\">version 3.6</span> </li>\n",
    "</ul> "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{0: {0: 1, 1: 2, 2: 3}, 1: {0: 4, 1: 6, 2: 1}, 2: {0: 1, 1: 2, 2: 3}}"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{0: {0: 1, 1: 2, 2: 3}, 1: {0: 4, 1: 6, 2: 1}, 2: {0: 1, 1: 2, 2: 3}}"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.matrix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{0: {0: 0.16667, 1: 0.33333, 2: 0.5},\n",
       " 1: {0: 0.36364, 1: 0.54545, 2: 0.09091},\n",
       " 2: {0: 0.16667, 1: 0.33333, 2: 0.5}}"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.normalized_matrix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{0: {0: 0.16667, 1: 0.33333, 2: 0.5},\n",
       " 1: {0: 0.36364, 1: 0.54545, 2: 0.09091},\n",
       " 2: {0: 0.16667, 1: 0.33333, 2: 0.5}}"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.normalized_table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Predict 0       1       2       \n",
      "Actual\n",
      "0       1       2       3       \n",
      "\n",
      "1       4       6       1       \n",
      "\n",
      "2       1       2       3       \n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "cm.print_matrix()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [],
   "source": [
    "array = numpy.array([[1, 2, 3], [4, 6, 1], [1, 2, 3]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [],
   "source": [
    "cm = ConfusionMatrix(matrix=array)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pycm.ConfusionMatrix(classes: [0, 1, 2])"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [],
   "source": [
    "cm = ConfusionMatrix(matrix=array, classes=[\"L1\", \"L2\", \"L3\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pycm.ConfusionMatrix(classes: ['L1', 'L2', 'L3'])"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Iterating and casting"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "From `version 3.5`, `ConfusionMatrix` is an **iterator** object."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "L2 {'L2': 6, 'L3': 1, 'L1': 4}\n",
      "L3 {'L2': 2, 'L3': 3, 'L1': 1}\n",
      "L1 {'L2': 2, 'L3': 3, 'L1': 1}\n"
     ]
    }
   ],
   "source": [
    "for row, col in cm:\n",
    "    print(row, col)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('L2', {'L1': 4, 'L2': 6, 'L3': 1})"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm_iter = iter(cm)\n",
    "next(cm_iter)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': {'L1': 1, 'L2': 2, 'L3': 3},\n",
       " 'L2': {'L1': 4, 'L2': 6, 'L3': 1},\n",
       " 'L3': {'L1': 1, 'L2': 2, 'L3': 3}}"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm_dict = dict(cm)\n",
    "cm_dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('L2', {'L1': 4, 'L2': 6, 'L3': 1}),\n",
       " ('L3', {'L1': 1, 'L2': 2, 'L3': 3}),\n",
       " ('L1', {'L1': 1, 'L2': 2, 'L3': 3})]"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm_list = list(cm)\n",
    "cm_list"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 3.5</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Activation threshold"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`threshold` is added in `version 0.9` for real value prediction.\t\t\t\n",
    "\t\t\t\t\t\t\n",
    "For more information visit <a href=\"#Example-3-(Activation-threshold)\">Example 3</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.9</span> </li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Load from file"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`file` is added in `version 0.9.5` in order to load saved confusion matrix with `.obj` format generated by `save_obj` method.\n",
    "\n",
    "For more information visit <a href=\"#Example-4-(File)\">Example 4</a>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.9.5</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Sample weights"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`sample_weight` is added in `version 1.2`\n",
    "\n",
    "For more information visit <a href=\"#Example-5-(Sample-weights)\">Example 5</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 1.2</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Transpose"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`transpose` is added in `version 1.2` in order to transpose input matrix (only in `Direct CM` mode)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [],
   "source": [
    "cm = ConfusionMatrix(matrix={0: {0: 3, 1: 0, 2: 0}, 1: {0: 0, 1: 1, 2: 2}, 2: {0: 2, 1: 1, 2: 3}}, digit=5, transpose=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Predict 0       1       2       \n",
      "Actual\n",
      "0       3       0       2       \n",
      "\n",
      "1       0       1       1       \n",
      "\n",
      "2       0       2       3       \n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "cm.print_matrix()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 1.2</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Metrics off"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`metrics_off` is added in `version 3.9` in order to bypass metrics calculation."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [],
   "source": [
    "cm3 = ConfusionMatrix(y_actu, y_pred, metrics_off=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'ACC': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'AGF': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'AGM': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'AM': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'AUC': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'AUCI': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'AUPR': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'BB': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'BCD': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'BM': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'CEN': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'DOR': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'DP': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'DPI': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'ERR': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'F0.5': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'F1': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'F2': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'FDR': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'FN': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'FNR': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'FOR': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'FP': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'FPR': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'G': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'GI': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'GM': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'HD': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'IBA': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'ICSI': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'IS': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'J': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'LS': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'MCC': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'MCCI': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'MCEN': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'MK': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'N': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'NLR': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'NLRI': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'NPV': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'OC': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'OOC': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'OP': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'P': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'PLR': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'PLRI': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'POP': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'PPV': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'PRE': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'Q': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'QI': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'RACC': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'RACCU': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'TN': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'TNR': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'TON': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'TOP': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'TP': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'TPR': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'Y': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'dInd': {0: 'None', 1: 'None', 2: 'None'},\n",
       " 'sInd': {0: 'None', 1: 'None', 2: 'None'}}"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm3.class_stat"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'95% CI': 'None',\n",
       " 'ACC Macro': 'None',\n",
       " 'ARI': 'None',\n",
       " 'AUNP': 'None',\n",
       " 'AUNU': 'None',\n",
       " 'Bangdiwala B': 'None',\n",
       " 'Bennett S': 'None',\n",
       " 'CBA': 'None',\n",
       " 'CSI': 'None',\n",
       " 'Chi-Squared': 'None',\n",
       " 'Chi-Squared DF': 'None',\n",
       " 'Conditional Entropy': 'None',\n",
       " 'Cramer V': 'None',\n",
       " 'Cross Entropy': 'None',\n",
       " 'F1 Macro': 'None',\n",
       " 'F1 Micro': 'None',\n",
       " 'FNR Macro': 'None',\n",
       " 'FNR Micro': 'None',\n",
       " 'FPR Macro': 'None',\n",
       " 'FPR Micro': 'None',\n",
       " 'Gwet AC1': 'None',\n",
       " 'Hamming Loss': 'None',\n",
       " 'Joint Entropy': 'None',\n",
       " 'KL Divergence': 'None',\n",
       " 'Kappa': 'None',\n",
       " 'Kappa 95% CI': 'None',\n",
       " 'Kappa No Prevalence': 'None',\n",
       " 'Kappa Standard Error': 'None',\n",
       " 'Kappa Unbiased': 'None',\n",
       " 'Krippendorff Alpha': 'None',\n",
       " 'Lambda A': 'None',\n",
       " 'Lambda B': 'None',\n",
       " 'Mutual Information': 'None',\n",
       " 'NIR': 'None',\n",
       " 'NPV Macro': 'None',\n",
       " 'NPV Micro': 'None',\n",
       " 'Overall ACC': 'None',\n",
       " 'Overall CEN': 'None',\n",
       " 'Overall J': 'None',\n",
       " 'Overall MCC': 'None',\n",
       " 'Overall MCEN': 'None',\n",
       " 'Overall RACC': 'None',\n",
       " 'Overall RACCU': 'None',\n",
       " 'P-Value': 'None',\n",
       " 'PPV Macro': 'None',\n",
       " 'PPV Micro': 'None',\n",
       " 'Pearson C': 'None',\n",
       " 'Phi-Squared': 'None',\n",
       " 'RCI': 'None',\n",
       " 'RR': 'None',\n",
       " 'Reference Entropy': 'None',\n",
       " 'Response Entropy': 'None',\n",
       " 'SOA1(Landis & Koch)': 'None',\n",
       " 'SOA10(Pearson C)': 'None',\n",
       " 'SOA2(Fleiss)': 'None',\n",
       " 'SOA3(Altman)': 'None',\n",
       " 'SOA4(Cicchetti)': 'None',\n",
       " 'SOA5(Cramer)': 'None',\n",
       " 'SOA6(Matthews)': 'None',\n",
       " 'SOA7(Lambda A)': 'None',\n",
       " 'SOA8(Lambda B)': 'None',\n",
       " 'SOA9(Krippendorff Alpha)': 'None',\n",
       " 'Scott PI': 'None',\n",
       " 'Standard Error': 'None',\n",
       " 'TNR Macro': 'None',\n",
       " 'TNR Micro': 'None',\n",
       " 'TPR Macro': 'None',\n",
       " 'TPR Micro': 'None',\n",
       " 'Zero-one Loss': 'None'}"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm3.overall_stat"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 3.9</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Relabel"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`relabel` method is added in `version 1.5` in order to change ConfusionMatrix class names."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [],
   "source": [
    "cm.relabel(mapping={0:\"L1\",1:\"L2\",2:\"L3\"}, sort=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pycm.ConfusionMatrix(classes: ['L1', 'L2', 'L3'])"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Parameters "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. `mapping` : mapping dictionary (type : `dict`)\n",
    "2. `sort` : flag for sorting new classes (type : `bool`, default : `False`)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 1.5</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> : <code>sort</code> added in <span style=\"color:red;\">version 3.9</span></li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Position"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`position` method is added in `version 2.8` in order to find the indexes of observations in `predict_vector` which made TP, TN, FP, FN."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{0: {'FN': [], 'FP': [0, 7], 'TN': [2, 3, 5, 6, 8, 10, 11], 'TP': [1, 4, 9]},\n",
       " 1: {'FN': [5, 10], 'FP': [3], 'TN': [0, 1, 2, 4, 7, 8, 9, 11], 'TP': [6]},\n",
       " 2: {'FN': [0, 3, 7], 'FP': [5, 10], 'TN': [1, 4, 6, 9], 'TP': [2, 8, 11]}}"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm3 = ConfusionMatrix(y_actu, y_pred, digit=5)\n",
    "cm3.position()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 2.8</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  only works in vector mode </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### To array"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`to_array` method is added in `version 2.9` in order to returns the confusion matrix in the form of a NumPy array. This can be helpful to apply different operations over the confusion matrix for different purposes such as aggregation, normalization, and combination."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[3, 0, 2],\n",
       "       [0, 1, 1],\n",
       "       [0, 2, 3]])"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.to_array()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.6, 0. , 0.4],\n",
       "       [0. , 0.5, 0.5],\n",
       "       [0. , 0.4, 0.6]])"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.to_array(normalized=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.6, 0.4],\n",
       "       [0. , 1. ]])"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.to_array(normalized=True, one_vs_all=True, class_name=\"L1\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Parameters "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. `normalized` : a flag for getting normalized confusion matrix (type : `bool`, default : `False`)\n",
    "2. `one_vs_all` : one-vs-all mode flag (type : `bool`, default : `False`)\n",
    "3. `class_name` : target class name for one-vs-all mode (type : `any valid type`, default : `None`)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Output"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`Confusion Matrix in NumPy array format`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 2.9</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Combine"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`combine` method is added in `version 3.0` in order to merge two confusion matrices. This option will be useful in mini-batch learning."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Predict 0       1       2       \n",
      "Actual\n",
      "0       6       0       0       \n",
      "\n",
      "1       0       2       4       \n",
      "\n",
      "2       4       2       6       \n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "cm_combined = cm2.combine(cm3)\n",
    "cm_combined.print_matrix()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Parameters "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. `other` : the other matrix that is going to be combined (type : `ConfusionMatrix`)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Output"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "New `ConfusionMatrix`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 3.0</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Plot"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`plot` method is added in `version 3.0` in order to plot a confusion matrix using Matplotlib or Seaborn."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Keyring is skipped due to an exception: invalid syntax (core.py, line 48)\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Keyring is skipped due to an exception: invalid syntax (core.py, line 48)\n"
     ]
    }
   ],
   "source": [
    "import sys\n",
    "!{sys.executable}  -m pip -q -q install matplotlib;\n",
    "!{sys.executable}  -m pip -q -q install seaborn;\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x41e71b0>"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 9512 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "cm.plot()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x1227c1d0>"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 14816 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "cm.plot(cmap=plt.cm.Greens, number_label=True, normalized=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x122b45d0>"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 11500 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "cm.plot(plot_lib=\"seaborn\", number_label=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x1b8fb4d0>"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 9540 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "cm.plot(cmap=plt.cm.Blues, number_label=True, one_vs_all=True, class_name=\"L1\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x1b8fb730>"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 16508 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "cm.plot(cmap=plt.cm.Reds, number_label=True, normalized=True, one_vs_all=True, class_name=\"L3\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Parameters "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. `normalized` :normalized flag for matrix (type : `bool`, default : `False`)\n",
    "2. `one_vs_all` : one-vs-all mode flag (type : `bool`, default : `False`)\n",
    "3. `class_name` : target class name for one-vs-all mode (type : `any valid type`, default : `None`)\n",
    "4. `title` : plot title (type : `str`, default : `Confusion Matrix`)\n",
    "5. `number_label` : number label flag (type : `bool`, default : `False`)\n",
    "6. `cmap` : color map (type : `matplotlib.colors.ListedColormap`, default : `None`)\n",
    "7. `plot_lib` : plotting library (type : `str`, default : `matplotlib`)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Output"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Plot axes"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 3.0</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Distance/Similarity"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- [Jupyter Notebook](https://nbviewer.jupyter.org/github/sepandhaghighi/pycm/blob/master/Document/Distance.ipynb)\n",
    "- [HTML](http://www.pycm.io/doc/Distance.html)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 3.8</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Parameter recommender"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This option has been added in `version 1.9` to recommend the most related parameters considering the characteristics of the input dataset. The suggested parameters are selected according to some characteristics of the input such as being balance/imbalance and binary/multi-class. All suggestions can be categorized into three main groups: imbalanced dataset, binary classification for a balanced dataset, and multi-class classification for a balanced dataset. The recommendation lists have been gathered according to the respective paper of each parameter and the capabilities which had been claimed by the paper."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div style=\"text-align:center;\">\n",
    "    <img src=\"../Otherfiles/recommendation_block_diagram.jpg\" onerror='this.src=\"../images/recommendation_block_diagram.jpg\"' width=\"400\">\n",
    "</div>\n",
    "<center><p style=\"text-align:center;\">Fig2. Parameter Recommender Block Diagram</p></center>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For determining if the dataset is imbalanced, we use the following strategy:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$R=\\frac{Max(P)}{Min(P)}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$State=\\begin{cases}Balance & R\\leq 3\\\\Imbalance & R > 3\\end{cases}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.imbalance"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.binary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['ERR',\n",
       " 'TPR Micro',\n",
       " 'TPR Macro',\n",
       " 'F1 Macro',\n",
       " 'PPV Macro',\n",
       " 'NPV Macro',\n",
       " 'ACC',\n",
       " 'Overall ACC',\n",
       " 'MCC',\n",
       " 'MCCI',\n",
       " 'Overall MCC',\n",
       " 'SOA6(Matthews)',\n",
       " 'BCD',\n",
       " 'Hamming Loss',\n",
       " 'Zero-one Loss']"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.recommended_list"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`is_imbalanced` parameter has been added in `version 3.3`, so the user can indicate whether the concerned dataset is imbalanced or not. As long as the user does not provide any information in this regard, the automatic detection algorithm will be used."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm4 = ConfusionMatrix(y_actu, y_pred, is_imbalanced=True)\n",
    "cm4.imbalance"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm4 = ConfusionMatrix(y_actu, y_pred, is_imbalanced=False)\n",
    "cm4.imbalance"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  also available in HTML report </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> : The recommender system assumes that the input is the result of classification over the whole data rather than just a part of it. If the confusion matrix is the result of test data classification, the recommendation is not valid. </li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  <code>is_imbalanced</code> , new in <span style=\"color:red;\">version 3.3 </span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Compare"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In `version 2.0`, a method for comparing several confusion matrices is introduced. This option is a combination of several overall and class-based benchmarks. Each of the benchmarks evaluates the performance of the classification algorithm from good to poor and give them a numeric score. The score of good and poor performances are 1 and 0, respectively.\n",
    "\n",
    "After that, two scores are calculated for each confusion matrices, overall and class-based. The overall score is the average of the score of seven overall benchmarks which are Landis & Koch, Cramer, Matthews, Goodman-Kruskal's Lambda A, Goodman-Kruskal's Lambda B, Krippendorff's Alpha, and Pearson's C. In the same manner, the class-based score is the average of the score of six class-based benchmarks which are Positive Likelihood Ratio Interpretation, Negative Likelihood Ratio Interpretation, Discriminant Power Interpretation, AUC value Interpretation, Matthews Correlation Coefficient Interpretation and Yule's Q Interpretation. It should be noticed that if one of the benchmarks returns none for one of the classes, that benchmarks will be eliminated in total averaging. If the user sets weights for the classes, the averaging over the value of class-based benchmark scores will transform to a weighted average.\n",
    "\n",
    "If the user sets the value of `by_class` boolean input `True`, the best confusion matrix is the one with the maximum class-based score. Otherwise, if a confusion matrix obtains the maximum of both overall and class-based scores, that will be reported as the best confusion matrix, but in any other case, the compared object doesn’t select the best confusion matrix."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div style=\"text-align:center;\">\n",
    "    <img src=\"../Otherfiles/compare_block_diagram.jpg\" onerror='this.src=\"../images/compare_block_diagram.jpg\"' width=\"500\">\n",
    "</div>\n",
    "<center><p style=\"text-align:center;\">Fig3. Compare Block Diagram</p></center>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This is how the overall and class-based scores are determined for each confusion matrix. Note that here $|Set|$ shows the cardinality of the set and the cardinality of each benchmark is equal to the maximum possible score for that benchmark."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$S_{Overall}=\\sum_{i=1}^{|B_O|}\\frac{W_{OB}(i)}{\\sum W_{OB}}\\times\\frac{R_O(i)}{|B_O(i)|}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$S_{Class}=\\sum_{i=1}^{|B_C|}\\sum_{j=1}^{|C|}\\frac{W_{CB}(i)}{\\sum W_{CB}}\\times\\frac{W_C(j)}{\\sum W_{C}}\\times\\frac{R_C(i,j)}{|B_C(i)|}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$0\\leq S_{Overall},S_{Class}\\leq1$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- $B_C$ : Class benchmarks\n",
    "- $B_O$ : Overall benchmarks\n",
    "- $C$ : Classes\n",
    "- $W_{CB}$ : Class benchmark weights\n",
    "- $W_{OB}$ : Overall benchmark weights\n",
    "- $W_{C}$ : Class weights\n",
    "- $R_C$ : Class benchmark result\n",
    "- $R_O$ : Overall benchmark result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [],
   "source": [
    "cm2 = ConfusionMatrix(matrix={0: {0:2, 1:50, 2:6}, 1:{0:5, 1:50, 2:3}, 2:{0:1, 1:7, 2:50}})\n",
    "cm3 = ConfusionMatrix(matrix={0: {0:50, 1:2, 2:6}, 1:{0:50, 1:5, 2:3}, 2:{0:1, 1:55, 2:2}})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [],
   "source": [
    "cp = Compare({\"cm2\":cm2, \"cm3\":cm3})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Best : cm2\n",
      "\n",
      "Rank  Name   Class-Score       Overall-Score\n",
      "1     cm2    0.50278           0.58095\n",
      "2     cm3    0.33611           0.52857\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print(cp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'cm2': {'class': 0.50278, 'overall': 0.58095},\n",
       " 'cm3': {'class': 0.33611, 'overall': 0.52857}}"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cp.scores"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['cm2', 'cm3']"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cp.sorted"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pycm.ConfusionMatrix(classes: [0, 1, 2])"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cp.best"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'cm2'"
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cp.best_name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [],
   "source": [
    "cp2 = Compare({\"cm2\":cm2, \"cm3\":cm3}, by_class=True, class_weight={0:5, 1:1, 2:1})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Best : cm3\n",
      "\n",
      "Rank  Name   Class-Score       Overall-Score\n",
      "1     cm3    0.45357           0.52857\n",
      "2     cm2    0.34881           0.58095\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print(cp2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [],
   "source": [
    "cp3 = Compare({\"cm2\":cm2, \"cm3\":cm3}, class_benchmark_weight={\"PLRI\":0, \"NLRI\":0, \"DPI\":0, \"AUCI\":1, \"MCCI\":0, \"QI\":0})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Best : cm2\n",
      "\n",
      "Rank  Name   Class-Score       Overall-Score\n",
      "1     cm2    0.46667           0.58095\n",
      "2     cm3    0.33333           0.52857\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print(cp3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [],
   "source": [
    "cp4 = Compare(\n",
    "    {\"cm2\":cm2, \"cm3\":cm3},\n",
    "    overall_benchmark_weight={\"SOA1\":1, \"SOA2\":0, \"SOA3\":0, \"SOA4\":0, \"SOA5\":0, \"SOA6\":1, \"SOA7\":0, \"SOA8\":0, \"SOA9\":0, \"SOA10\":0})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Best : cm2\n",
      "\n",
      "Rank  Name   Class-Score       Overall-Score\n",
      "1     cm2    0.50278           0.45\n",
      "2     cm3    0.33611           0.18333\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print(cp4)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Overall and class benchmark lists are available in `CLASS_BENCHMARK_LIST` and `OVERALL_BENCHMARK_LIST`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['AUCI', 'DPI', 'MCCI', 'NLRI', 'PLRI', 'QI']\n",
      "['SOA1', 'SOA10', 'SOA2', 'SOA3', 'SOA4', 'SOA5', 'SOA6', 'SOA7', 'SOA8', 'SOA9']\n"
     ]
    }
   ],
   "source": [
    "from pycm import CLASS_BENCHMARK_LIST, OVERALL_BENCHMARK_LIST\n",
    "print(CLASS_BENCHMARK_LIST)\n",
    "print(OVERALL_BENCHMARK_LIST)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  <code>overall_benchmark_weight</code> and <code>class_benchmark_weight</code>, new in <span style=\"color:red;\">version 3.3 </span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  From <span style=\"color:red;\">version 3.8</span>, Goodman-Kruskal's Lambda A, Goodman-Kruskal's Lambda B, Krippendorff's Alpha, and Pearson's C benchmarks are considered in the overall score and default weights of the overall benchmarks are modified accordingly. </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### ROC curve"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`ROCCurve`, added in `version 3.7`, is devised to compute the Receiver Operating Characteristic (ROC) or simply ROC curve. In ROC curves, the Y axis represents the True Positive Rate, and the X axis represents the False Positive Rate. Thus, the ideal point is located at the top left of the curve, and a larger area under the curve represents better performance. ROC curve is a graphical representation of binary classifiers' performance. In PyCM, `ROCCurve` binarizes the output based on the \"One vs. Rest\" strategy to provide an extension of ROC for multi-class classifiers. By getting the actual labels vector and the target probability estimates of the positive classes, this method is able to compute and plot TPR-FPR pairs for different discrimination thresholds and compute the area under the ROC curve. \n",
    "The thresholds for which the TPR-FPR pairs are calculated can be either specified by users (by setting `thresholds` input) or calculated automatically. Furthermore, sample weights can be adjusted via `sample_weight` as an input; otherwise, they are assumed to be 1. `ROCCurve` has two methods named `area()` and `plot()`. `area()` provides the user with the value of area under curve, which can be calculated using either `trapezoidal` (default method) or `midpoint` numerical integral technique. `plot()` is also provided to plot the given curve."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.75"
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from pycm import ROCCurve\n",
    "crv = ROCCurve(\n",
    "    actual_vector=numpy.array([1, 1, 2, 2]),\n",
    "    probs=numpy.array([[0.1, 0.9], [0.4, 0.6], [0.35, 0.65], [0.8, 0.2]]),\n",
    "    classes=[2, 1])\n",
    "crv.thresholds\n",
    "auc_trp = crv.area()\n",
    "auc_trp[1]\n",
    "auc_trp[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x1b96d6b0>"
      ]
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 12952 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "crv.plot(area=True, classes=[2])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 3.7</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Precision-Recall curve"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`PRCurve`, added in `version 3.7`, is devised to compute the Precision-Recall curve in which the Y axis represents the Precision, and the X axis represents the Recall of a classifier. Thus, the ideal point is located at the top right of the curve, and a larger area under the curve represents better performance. Precision-Recall curve is a graphical representation of binary classifiers' performance. In PyCM, `PRCurve` binarizes the output based on the \"One vs. Rest\" strategy to provide an extension of this curve for multi-class classifiers. By getting the actual labels vector and the target probability estimates of the positive classes, this method is able to compute and plot Precision-Recall pairs for different discrimination thresholds and compute the area under the curve. \n",
    "The thresholds for which the Precision-Recall pairs are calculated can be either specified by users (by setting `thresholds` input) or calculated automatically. Furthermore, sample weights can be adjusted via `sample_weight` as an input; otherwise, they are assumed to be 1. `PRCurve` has two methods named `area()` and `plot()`. `area()` provides the user with the value of area under curve, which can be calculated using either `trapezoidal` (default method) or `midpoint` numerical integral technique. `plot()` is also provided to plot the given curve."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\Sepkjaer\\AppData\\Local\\Programs\\Python\\Python35-32\\lib\\site-packages\\pycm-4.2-py3.5.egg\\pycm\\curve.py:382: RuntimeWarning: The curve contains non-numerical value(s).\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "0.29166666666666663"
      ]
     },
     "execution_count": 93,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from pycm import PRCurve\n",
    "crv = PRCurve(\n",
    "    actual_vector=numpy.array([1, 1, 2, 2]),\n",
    "    probs=numpy.array([[0.1, 0.9], [0.4, 0.6], [0.35, 0.65], [0.8, 0.2]]),\n",
    "    classes=[2, 1])\n",
    "crv.thresholds\n",
    "auc_trp = crv.area()\n",
    "auc_trp[1]\n",
    "auc_trp[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x1b9a5e50>"
      ]
     },
     "execution_count": 94,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 14056 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "crv.plot(area=True, classes=[2])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 3.7</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Multilabel confusion matrix"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "From `version 4.0`, `MultiLabelCM` has been added to calculate class-wise or sample-wise multilabel confusion matrices. In class-wise mode, confusion matrices are calculated for each class, and in sample-wise mode, they are generated per sample. All generated confusion matrices are binarized with a one-vs-rest transformation."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1, 0, 1], [0, 1, 0]]\n",
      "[[1, 0, 0], [0, 1, 1]]\n",
      "Predict 0       1       \n",
      "Actual\n",
      "0       1       0       \n",
      "\n",
      "1       0       1       \n",
      "\n",
      "\n",
      "Predict 0       1       \n",
      "Actual\n",
      "0       1       0       \n",
      "\n",
      "1       1       1       \n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "mlcm = MultiLabelCM(actual_vector=[{\"cat\", \"bird\"}, {\"dog\"}], \n",
    "                    predict_vector=[{\"cat\"}, {\"dog\", \"bird\"}], \n",
    "                    classes=[\"cat\", \"dog\", \"bird\"])\n",
    "print(mlcm.actual_vector_multihot)\n",
    "print(mlcm.predict_vector_multihot)\n",
    "mlcm.get_cm_by_class(\"cat\").print_matrix()\n",
    "mlcm.get_cm_by_sample(0).print_matrix()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 4.0</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Online help"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`online_help` function is added in `version 1.1` in order to open each statistics definition in web browser."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "```python\n",
    "\n",
    ">>> from pycm import online_help\n",
    ">>> online_help(\"J\")\n",
    ">>> online_help(\"J\", alt_link=True)\n",
    ">>> online_help(\"SOA1(Landis & Koch)\")\n",
    ">>> online_help(2)\n",
    "\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* List of items are available by calling `online_help()` (without argument)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* If PyCM website is not available, set `alt_link = True`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Please choose one parameter : \n",
      "\n",
      "Example : online_help(\"J\") or online_help(2)\n",
      "\n",
      "1-95% CI\n",
      "2-ACC\n",
      "3-ACC Macro\n",
      "4-AGF\n",
      "5-AGM\n",
      "6-AM\n",
      "7-ARI\n",
      "8-AUC\n",
      "9-AUCI\n",
      "10-AUNP\n",
      "11-AUNU\n",
      "12-AUPR\n",
      "13-BB\n",
      "14-BCD\n",
      "15-BM\n",
      "16-Bangdiwala B\n",
      "17-Bennett S\n",
      "18-CBA\n",
      "19-CEN\n",
      "20-CSI\n",
      "21-Chi-Squared\n",
      "22-Chi-Squared DF\n",
      "23-Conditional Entropy\n",
      "24-Cramer V\n",
      "25-Cross Entropy\n",
      "26-DOR\n",
      "27-DP\n",
      "28-DPI\n",
      "29-ERR\n",
      "30-F0.5\n",
      "31-F1\n",
      "32-F1 Macro\n",
      "33-F1 Micro\n",
      "34-F2\n",
      "35-FDR\n",
      "36-FN\n",
      "37-FNR\n",
      "38-FNR Macro\n",
      "39-FNR Micro\n",
      "40-FOR\n",
      "41-FP\n",
      "42-FPR\n",
      "43-FPR Macro\n",
      "44-FPR Micro\n",
      "45-G\n",
      "46-GI\n",
      "47-GM\n",
      "48-Gwet AC1\n",
      "49-HD\n",
      "50-Hamming Loss\n",
      "51-IBA\n",
      "52-ICSI\n",
      "53-IS\n",
      "54-J\n",
      "55-Joint Entropy\n",
      "56-KL Divergence\n",
      "57-Kappa\n",
      "58-Kappa 95% CI\n",
      "59-Kappa No Prevalence\n",
      "60-Kappa Standard Error\n",
      "61-Kappa Unbiased\n",
      "62-Krippendorff Alpha\n",
      "63-LS\n",
      "64-Lambda A\n",
      "65-Lambda B\n",
      "66-MCC\n",
      "67-MCCI\n",
      "68-MCEN\n",
      "69-MK\n",
      "70-Mutual Information\n",
      "71-N\n",
      "72-NIR\n",
      "73-NLR\n",
      "74-NLRI\n",
      "75-NPV\n",
      "76-NPV Macro\n",
      "77-NPV Micro\n",
      "78-OC\n",
      "79-OOC\n",
      "80-OP\n",
      "81-Overall ACC\n",
      "82-Overall CEN\n",
      "83-Overall J\n",
      "84-Overall MCC\n",
      "85-Overall MCEN\n",
      "86-Overall RACC\n",
      "87-Overall RACCU\n",
      "88-P\n",
      "89-P-Value\n",
      "90-PLR\n",
      "91-PLRI\n",
      "92-POP\n",
      "93-PPV\n",
      "94-PPV Macro\n",
      "95-PPV Micro\n",
      "96-PRE\n",
      "97-Pearson C\n",
      "98-Phi-Squared\n",
      "99-Q\n",
      "100-QI\n",
      "101-RACC\n",
      "102-RACCU\n",
      "103-RCI\n",
      "104-RR\n",
      "105-Reference Entropy\n",
      "106-Response Entropy\n",
      "107-SOA1(Landis & Koch)\n",
      "108-SOA2(Fleiss)\n",
      "109-SOA3(Altman)\n",
      "110-SOA4(Cicchetti)\n",
      "111-SOA5(Cramer)\n",
      "112-SOA6(Matthews)\n",
      "113-SOA7(Lambda A)\n",
      "114-SOA8(Lambda B)\n",
      "115-SOA9(Krippendorff Alpha)\n",
      "116-SOA10(Pearson C)\n",
      "117-Scott PI\n",
      "118-Standard Error\n",
      "119-TN\n",
      "120-TNR\n",
      "121-TNR Macro\n",
      "122-TNR Micro\n",
      "123-TON\n",
      "124-TOP\n",
      "125-TP\n",
      "126-TPR\n",
      "127-TPR Macro\n",
      "128-TPR Micro\n",
      "129-Y\n",
      "130-Zero-one Loss\n",
      "131-dInd\n",
      "132-sInd\n"
     ]
    }
   ],
   "source": [
    "online_help()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Parameters "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. `param` : input parameter (type : `int or str`, default : `None`)\n",
    "2. `alt_link` : alternative link for document flag (type : `bool`, default : `False`)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  <code>alt_link</code> , new in <span style=\"color:red;\">version 2.4 </span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Acceptable data types\t"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<strong>ConfusionMatrix</strong>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. `actual_vector` : python `list` or numpy `array` of any stringable objects\n",
    "2. `predict_vector` : python `list` or numpy `array` of any stringable objects\n",
    "3. `matrix` : `dict`\n",
    "4. `digit`: `int`\n",
    "5. `threshold` : `FunctionType (function or lambda)`\n",
    "6. `file` : `File object`\n",
    "7. `sample_weight` : python `list` or numpy `array` of numbers\n",
    "8. `transpose` : `bool`\n",
    "9. `classes` : python `list`\n",
    "10. `is_imbalanced` : `bool`\n",
    "11. `metrics_off` : `bool`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* run `help(ConfusionMatrix)` for more information"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  <code>metrics_off</code>, new in <span style=\"color:red;\">version 3.9 </span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<strong>Compare</strong>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. `cm_dict` : python `dict` of `ConfusionMatrix` object (`str` : `ConfusionMatrix`)\n",
    "2. `by_class` : `bool`\n",
    "3. `class_weight` : python `dict` of class weights (`class_name` : `float`)\n",
    "4. `class_benchmark_weight`: python `dict` of class benchmark weights (`class_benchmark_name` : `float`) \n",
    "5. `overall_benchmark_weight`: python `dict` of overall benchmark weights (`overall_benchmark_name` : `float`) \n",
    "6. `digit`: `int`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* run `help(Compare)` for more information"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  <code>weight</code> renamed to <code>class_weight</code> in <span style=\"color:red;\">version 3.3</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  <code>overall_benchmark_weight</code> and <code>class_benchmark_weight</code>, new in <span style=\"color:red;\">version 3.3 </span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<strong>ROCCurve</strong>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. `actual_vector` : python `list` or numpy `array` of any stringable objects\n",
    "2. `probs` : python `list` or numpy `array`\n",
    "3. `classes` : python `list`\n",
    "4. `thresholds`: python `list` or numpy `array` \n",
    "5. `sample_weight`: python `list` or numpy `array`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* run `help(ROCCurve)` for more information"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<strong>PRCurve</strong>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. `actual_vector` : python `list` or numpy `array` of any stringable objects\n",
    "2. `probs` : python `list` or numpy `array`\n",
    "3. `classes` : python `list`\n",
    "4. `thresholds`: python `list` or numpy `array` \n",
    "5. `sample_weight`: python `list` or numpy `array`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* run `help(PRCurve)` for more information"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<strong>MultiLabelCM</strong>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. `actual_vector` : python `list` or numpy array of `sets`\n",
    "2. `predict_vector` : python `list` or numpy array of `sets`\n",
    "3. `sample_weight`: python `list` or numpy `array`\n",
    "4. `classes` : python `list`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* run `help(MultiLabelCM)` for more information"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Basic parameters"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### TP (True positive)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "A true positive test result is one that detects the condition when the\n",
    "condition is present (correctly identified) [[3]](#ref3)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 3, 'L2': 1, 'L3': 3}"
      ]
     },
     "execution_count": 97,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.TP"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### TN (True negative)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "A true negative test result is one that does not detect the condition when\n",
    "the condition is absent (correctly rejected) [[3]](#ref3)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 7, 'L2': 8, 'L3': 4}"
      ]
     },
     "execution_count": 98,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.TN"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### FP (False positive)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "A false positive test result is one that detects the condition when the\n",
    "condition is absent (incorrectly identified) [[3]](#ref3)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0, 'L2': 2, 'L3': 3}"
      ]
     },
     "execution_count": 99,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.FP"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### FN (False negative)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "A false negative test result is one that does not detect the condition when\n",
    "the condition is present (incorrectly rejected) [[3]](#ref3)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 2, 'L2': 1, 'L3': 2}"
      ]
     },
     "execution_count": 100,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.FN"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### P (Condition positive)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Number of positive samples.\n",
    "Also known as support (the number of occurrences of each class in y_true) [[3]](#ref3)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$P=TP+FN$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 5, 'L2': 2, 'L3': 5}"
      ]
     },
     "execution_count": 101,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.P"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### N (Condition negative)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Number of negative samples [[3]](#ref3)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$N=TN+FP$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 7, 'L2': 10, 'L3': 7}"
      ]
     },
     "execution_count": 102,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.N"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### TOP (Test outcome positive)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Number of positive outcomes [[3]](#ref3)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$TOP=TP+FP$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 3, 'L2': 3, 'L3': 6}"
      ]
     },
     "execution_count": 103,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.TOP"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### TON (Test outcome negative)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Number of negative outcomes [[3]](#ref3)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$TON=TN+FN$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 9, 'L2': 9, 'L3': 6}"
      ]
     },
     "execution_count": 104,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.TON"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### POP (Population)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Total sample size [[3]](#ref3)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$POP=TP+TN+FN+FP$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 12, 'L2': 12, 'L3': 12}"
      ]
     },
     "execution_count": 105,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.POP"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* <a href=\"https://en.wikipedia.org/wiki/Confusion_matrix\">Wikipedia page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Class statistics"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### TPR (True positive rate)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Sensitivity (also called the true positive rate, the recall, or probability of detection in some fields) measures the proportion of positives that are correctly identified as such (e.g. the percentage of sick people who are correctly identified as having the condition) [[3]](#ref3).\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/Sensitivity_and_specificity\">Wikipedia page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$TPR=\\frac{TP}{P}=\\frac{TP}{TP+FN}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0.6, 'L2': 0.5, 'L3': 0.6}"
      ]
     },
     "execution_count": 106,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.TPR"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### TNR (True negative rate)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Specificity (also called the true negative rate) measures the proportion of negatives that are correctly identified as such (e.g. the percentage of healthy people who are correctly identified as not having the condition) [[3]](#ref3).\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/Sensitivity_and_specificity\">Wikipedia page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$TNR=\\frac{TN}{N}=\\frac{TN}{TN+FP}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 1.0, 'L2': 0.8, 'L3': 0.5714285714285714}"
      ]
     },
     "execution_count": 107,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.TNR"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### PPV (Positive predictive value)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Positive predictive value (PPV) is the proportion of positives that correspond to\n",
    "the presence of the condition [[3]](#ref3).\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/Positive_and_negative_predictive_values\">Wikipedia page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$PPV=\\frac{TP}{TP+FP}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 1.0, 'L2': 0.3333333333333333, 'L3': 0.5}"
      ]
     },
     "execution_count": 108,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.PPV"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### NPV (Negative predictive value)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Negative predictive value (NPV) is the proportion of negatives that correspond to\n",
    "the absence of the condition [[3]](#ref3).\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/Positive_and_negative_predictive_values\">Wikipedia page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$NPV=\\frac{TN}{TN+FN}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0.7777777777777778, 'L2': 0.8888888888888888, 'L3': 0.6666666666666666}"
      ]
     },
     "execution_count": 109,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.NPV"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### FNR (False negative rate)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The false negative rate is the proportion of positives which yield negative test outcomes with the test, i.e., the conditional probability of a negative test result given that the condition being looked for is present [[3]](#ref3).\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/False_positives_and_false_negatives#False_positive_and_false_negative_rates\">Wikipedia page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$FNR=\\frac{FN}{P}=\\frac{FN}{FN+TP}=1-TPR$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0.4, 'L2': 0.5, 'L3': 0.4}"
      ]
     },
     "execution_count": 110,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.FNR"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### FPR (False positive rate)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The false positive rate is the proportion of all negatives that still yield positive test outcomes, i.e., the conditional probability of a positive test result given an event that was not present [[3]](#ref3).\n",
    "\n",
    "The false positive rate is equal to the significance level. The specificity of the test is equal to $ 1 $ minus the false positive rate.\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/False_positives_and_false_negatives#False_positive_and_false_negative_rates\">Wikipedia page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$FPR=\\frac{FP}{N}=\\frac{FP}{FP+TN}=1-TNR$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0.0, 'L2': 0.19999999999999996, 'L3': 0.4285714285714286}"
      ]
     },
     "execution_count": 111,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.FPR"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### FDR (False discovery rate)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The false discovery rate (FDR) is a method of conceptualizing the rate of type I errors in null hypothesis testing when conducting multiple comparisons. FDR-controlling procedures are designed to control the expected proportion of \"discoveries\" (rejected null hypotheses) that are false (incorrect rejections) [[3]](#ref3).\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/False_discovery_rate\">Wikipedia page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$FDR=\\frac{FP}{FP+TP}=1-PPV$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0.0, 'L2': 0.6666666666666667, 'L3': 0.5}"
      ]
     },
     "execution_count": 112,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.FDR"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### FOR (False omission rate)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "False omission rate (FOR) is a statistical method used in multiple hypothesis testing to correct for multiple comparisons and it is the complement of the negative predictive value. It measures the proportion of false negatives which are incorrectly rejected [[3]](#ref3).\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/Positive_and_negative_predictive_values\">Wikipedia page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$FOR=\\frac{FN}{FN+TN}=1-NPV$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0.2222222222222222,\n",
       " 'L2': 0.11111111111111116,\n",
       " 'L3': 0.33333333333333337}"
      ]
     },
     "execution_count": 113,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.FOR"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### ACC (Accuracy)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The accuracy is the number of correct predictions from all predictions made [[3]](#ref3).\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/Accuracy_and_precision\">Wikipedia page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$ACC=\\frac{TP+TN}{P+N}=\\frac{TP+TN}{TP+TN+FP+FN}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0.8333333333333334, 'L2': 0.75, 'L3': 0.5833333333333334}"
      ]
     },
     "execution_count": 114,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.ACC"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### ERR (Error rate)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The error rate is the number of incorrect predictions from all predictions made [[3]](#ref3)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$ERR=\\frac{FP+FN}{P+N}=\\frac{FP+FN}{TP+TN+FP+FN}=1-ACC$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0.16666666666666663, 'L2': 0.25, 'L3': 0.41666666666666663}"
      ]
     },
     "execution_count": 115,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.ERR"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.4</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### FBeta-Score"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In statistical analysis of classification, the F1 score (also F-score or F-measure) is a measure of a test's accuracy. It considers both the precision $ p $ and the recall $ r $ of the test to compute the score.\n",
    "The F1 score is the harmonic average of the precision and recall, where F1 score reaches its best value at $ 1 $ (perfect precision and recall) and worst at $ 0 $ [[3]](#ref3).\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/F1_score\">Wikipedia page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$F_{\\beta}=(1+\\beta^2)\\times \\frac{PPV\\times TPR}{(\\beta^2 \\times PPV)+TPR}=\\frac{(1+\\beta^2) \\times TP}{(1+\\beta^2)\\times TP+FP+\\beta^2 \\times FN}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0.75, 'L2': 0.4, 'L3': 0.5454545454545454}"
      ]
     },
     "execution_count": 116,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.F1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0.8823529411764706, 'L2': 0.35714285714285715, 'L3': 0.5172413793103449}"
      ]
     },
     "execution_count": 117,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.F05"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 118,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0.6521739130434783, 'L2': 0.45454545454545453, 'L3': 0.5769230769230769}"
      ]
     },
     "execution_count": 118,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.F2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0.6144578313253012, 'L2': 0.4857142857142857, 'L3': 0.5930232558139535}"
      ]
     },
     "execution_count": 119,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.F_beta(beta=4)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Parameters "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. `beta` : beta parameter (type : `float`)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Output"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`{class1: FBeta-Score1, class2: FBeta-Score2, ...}`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.4</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### MCC (Matthews correlation coefficient)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The Matthews correlation coefficient is used in machine learning as a measure of the quality of binary (two-class) classifications, introduced by biochemist Brian W. Matthews in 1975. It takes into account true and false positives and negatives and is generally regarded as a balanced measure that can be used even if the classes are of very different sizes. The MCC is, in essence, a correlation coefficient between the observed and predicted binary classifications; it returns a value between  $ −1 $ and  $ +1 $. A coefficient of $ +1 $ represents a perfect prediction, $ 0 $ no better than random prediction and $ −1 $ indicates total disagreement between prediction and observation [[27]](#ref27).\n",
    "\n",
    "<a href=\"#MCCI-(Matthews-correlation-coefficient-interpretation)\">Interpretation</a>\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/Matthews_correlation_coefficient\">Wikipedia page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$MCC=\\frac{TP \\times TN-FP \\times FN}{\\sqrt{(TP+FP)\\times (TP+FN)\\times (TN+FP)\\times (TN+FN)}}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 120,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0.6831300510639732, 'L2': 0.25819888974716115, 'L3': 0.1690308509457033}"
      ]
     },
     "execution_count": 120,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.MCC"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### BM (Bookmaker informedness)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The informedness of a prediction method as captured by a contingency matrix is defined as the probability that the prediction method will make a correct decision as opposed to guessing and is calculated using the bookmaker algorithm [[2]](#ref2).\n",
    "\n",
    "Equals to <a href=\"#Y-(Youden-index)\">Youden Index</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$BM=TPR+TNR-1$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0.6000000000000001,\n",
       " 'L2': 0.30000000000000004,\n",
       " 'L3': 0.17142857142857126}"
      ]
     },
     "execution_count": 121,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.BM"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### MK (Markedness)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In statistics and psychology, the social science concept of markedness is quantified as a measure of how much one variable is marked as a predictor or possible cause of another and is also known as $ \\triangle P $ in simple two-choice cases [[2]](#ref2)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$MK=PPV+NPV-1$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0.7777777777777777, 'L2': 0.2222222222222221, 'L3': 0.16666666666666652}"
      ]
     },
     "execution_count": 122,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.MK"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### PLR (Positive likelihood ratio)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Likelihood ratios are used for assessing the value of performing a diagnostic test. They use the sensitivity and specificity of the test to determine whether a test result usefully changes the probability that a condition (such as a disease state) exists. The first description of the use of likelihood ratios for decision rules was made at a symposium on information theory in 1954 [[28]](#ref28).\n",
    "\n",
    "<a href=\"#PLRI-(Positive-likelihood-ratio-interpretation)\">Interpretation</a>\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/Likelihood_ratios_in_diagnostic_testing\">Wikipedia page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$LR_+=PLR=\\frac{TPR}{FPR}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 'None', 'L2': 2.5000000000000004, 'L3': 1.4}"
      ]
     },
     "execution_count": 123,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.PLR"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  <code>LR+</code> renamed to <code>PLR</code> in <span style=\"color:red;\">version 1.5</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### NLR (Negative likelihood ratio)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Likelihood ratios are used for assessing the value of performing a diagnostic test. They use the sensitivity and specificity of the test to determine whether a test result usefully changes the probability that a condition (such as a disease state) exists. The first description of the use of likelihood ratios for decision rules was made at a symposium on information theory in 1954 [[28]](#ref28).\n",
    "\n",
    "<a href=\"#NLRI-(Negative-likelihood-ratio-interpretation)\">Interpretation</a>\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/Likelihood_ratios_in_diagnostic_testing\">Wikipedia page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$LR_-=NLR=\\frac{FNR}{TNR}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 124,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0.4, 'L2': 0.625, 'L3': 0.7000000000000001}"
      ]
     },
     "execution_count": 124,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.NLR"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  <code>LR-</code> renamed to <code>NLR</code> in <span style=\"color:red;\">version 1.5</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### DOR (Diagnostic odds ratio)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The diagnostic odds ratio is a measure of the effectiveness of a diagnostic test. It is defined as the ratio of the odds of the test being positive if the subject has a disease relative to the odds of the test being positive if the subject does not have the disease [[28]](#ref28).\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/Diagnostic_odds_ratio\">Wikipedia page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$DOR=\\frac{LR_+}{LR_-}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 'None', 'L2': 4.000000000000001, 'L3': 1.9999999999999998}"
      ]
     },
     "execution_count": 125,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.DOR"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### PRE (Prevalence)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Prevalence is a statistical concept referring to the number of cases of a disease that are present in a particular population at a given time (Reference Likelihood) [[14]](#ref14).\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/Prevalence\">Wikipedia page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$Prevalence=\\frac{P}{POP}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 126,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0.4166666666666667, 'L2': 0.16666666666666666, 'L3': 0.4166666666666667}"
      ]
     },
     "execution_count": 126,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.PRE"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### G (G-measure)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The geometric mean of precision and sensitivity, also known as Fowlkes–Mallows index [[3]](#ref3).\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/Fowlkes%E2%80%93Mallows_index\">Wikipedia page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$G=\\sqrt{PPV\\times TPR}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 127,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0.7745966692414834, 'L2': 0.408248290463863, 'L3': 0.5477225575051661}"
      ]
     },
     "execution_count": 127,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.G"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### RACC (Random accuracy)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The expected accuracy from a strategy of randomly guessing categories according to reference and response distributions [[24]](#ref24)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$RACC=\\frac{TOP \\times P}{POP^2}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 128,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0.10416666666666667,\n",
       " 'L2': 0.041666666666666664,\n",
       " 'L3': 0.20833333333333334}"
      ]
     },
     "execution_count": 128,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.RACC"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.3</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### RACCU (Random accuracy unbiased)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The expected accuracy from a strategy of randomly guessing categories according to the average of the reference and response distributions [[25]](#ref25)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$RACCU=(\\frac{TOP+P}{2 \\times POP})^2$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 129,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0.1111111111111111,\n",
       " 'L2': 0.04340277777777778,\n",
       " 'L3': 0.21006944444444442}"
      ]
     },
     "execution_count": 129,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.RACCU"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.8.1</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### J (Jaccard index)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The Jaccard index, also known as Intersection over Union and the Jaccard similarity coefficient (originally coined coefficient de communauté by Paul Jaccard), is a statistic used for comparing the similarity and diversity of sample sets [[29]](#ref29).\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/Jaccard_index\">Wikipedia page</a>\n",
    "\n",
    "Some articles also named it as the F* (An Interpretable Transformation of the F-measure) [[77]](#ref77)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$J=\\frac{TP}{TOP+P-TP}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 130,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0.6, 'L2': 0.25, 'L3': 0.375}"
      ]
     },
     "execution_count": 130,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.J"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.9</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### IS (Information score)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The amount of information needed to correctly classify an example into\n",
    "class C, whose prior probability is $ p(C) $, is defined as $ -\\log_2(p(C)) $ [[18]](#ref18) [[39]](#ref39)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$IS=-log_2(\\frac{TP+FN}{POP})+log_2(\\frac{TP}{TP+FP})$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 131,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 1.2630344058337937, 'L2': 0.9999999999999998, 'L3': 0.26303440583379367}"
      ]
     },
     "execution_count": 131,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.IS"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 1.3</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### CEN (Confusion entropy)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "CEN based upon the concept of entropy for evaluating classifier performances. By exploiting the misclassification information of confusion matrices, the measure evaluates the confusion level of the class distribution of\n",
    "misclassified samples. Both theoretical analysis and statistical results show that the proposed measure is more discriminating than accuracy and RCI while it remains relatively consistent with the two measures. Moreover, it is more capable of measuring how the samples of different classes have been separated from each\n",
    "other. Hence the proposed measure is more precise than the two measures and can substitute for them to evaluate classifiers in classification applications [[17]](#ref17)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$P_{i,j}^{j}=\\frac{Matrix(i,j)}{\\sum_{k=1}^{|C|}\\Big(Matrix(j,k)+Matrix(k,j)\\Big)}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$P_{i,j}^{i}=\\frac{Matrix(i,j)}{\\sum_{k=1}^{|C|}\\Big(Matrix(i,k)+Matrix(k,i)\\Big)}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$CEN_j=-\\sum_{k=1,k\\neq j}^{|C|}\\Bigg(P_{j,k}^jlog_{2(|C|-1)}\\Big(P_{j,k}^j\\Big)+P_{k,j}^jlog_{2(|C|-1)}\\Big(P_{k,j}^j\\Big)\\Bigg)$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 132,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0.25, 'L2': 0.49657842846620864, 'L3': 0.6044162769630221}"
      ]
     },
     "execution_count": 132,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.CEN"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  $ |C| $ is the number of classes </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 1.3</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### MCEN (Modified confusion entropy)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Modified version of CEN [[19]](#ref19)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$P_{i,j}^{j}=\\frac{Matrix(i,j)}{\\sum_{k=1}^{|C|}\\Big(Matrix(j,k)+Matrix(k,j)\\Big)-Matrix(j,j)}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$P_{i,j}^{i}=\\frac{Matrix(i,j)}{\\sum_{k=1}^{|C|}\\Big(Matrix(i,k)+Matrix(k,i)\\Big)-Matrix(i,i)}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$MCEN_j=-\\sum_{k=1,k\\neq j}^{|C|}\\Bigg(P_{j,k}^jlog_{2(|C|-1)}\\Big(P_{j,k}^j\\Big)+P_{k,j}^jlog_{2(|C|-1)}\\Big(P_{k,j}^j\\Big)\\Bigg)$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 133,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0.2643856189774724, 'L2': 0.5, 'L3': 0.6875}"
      ]
     },
     "execution_count": 133,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.MCEN"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 1.3</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### AUC (Area under the ROC curve)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The area under the curve (often referred to as simply the AUC) is equal to the probability that a classifier will rank a randomly chosen positive instance higher than a randomly chosen negative one (assuming 'positive' ranks higher than 'negative').\n",
    "Thus, AUC corresponds to the arithmetic mean of sensitivity and specificity values of each class [[23]](#ref23).\n",
    "\n",
    "<a href=\"#AUCI-(AUC-value-interpretation)\">Interpretation</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$AUC=\\frac{TNR+TPR}{2}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 134,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0.8, 'L2': 0.65, 'L3': 0.5857142857142856}"
      ]
     },
     "execution_count": 134,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.AUC"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 1.4</span> </li>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  this is an approximate calculation of AUC </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### dInd (Distance index)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Euclidean distance of a ROC point from the top left corner of the ROC space, which can take values between 0 (perfect classification) and $ \\sqrt{2} $  [[23]](#ref23)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$dInd=\\sqrt{(1-TNR)^2+(1-TPR)^2}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 135,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0.4, 'L2': 0.5385164807134504, 'L3': 0.5862367008195198}"
      ]
     },
     "execution_count": 135,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.dInd"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 1.4</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### sInd (Similarity index)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "sInd is comprised between $ 0 $ (no correct classifications) and $ 1 $ (perfect classification) [[23]](#ref23)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$sInd = 1 - \\sqrt{\\frac{(1-TNR)^2+(1-TPR)^2}{2}}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 136,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0.717157287525381, 'L2': 0.6192113447068046, 'L3': 0.5854680534700882}"
      ]
     },
     "execution_count": 136,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.sInd"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 1.4</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### DP (Discriminant power) "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Discriminant power (DP) is a measure that summarizes sensitivity and specificity.\n",
    "The DP has been used mainly in feature selection over imbalanced data [[33]](#ref33).\n",
    "\n",
    "<a href=\"#DPI-(Discriminant-power-interpretation)\">Interpretation</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$X=\\frac{TPR}{1-TPR}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$Y=\\frac{TNR}{1-TNR}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$DP=\\frac{\\sqrt{3}}{\\pi}(log_{10}X+log_{10}Y)$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 137,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 'None', 'L2': 0.33193306999649924, 'L3': 0.1659665349982495}"
      ]
     },
     "execution_count": 137,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.DP"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 1.5</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Y (Youden index)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Youden’s index evaluates the algorithm’s ability to avoid failure; it’s derived from sensitivity and\n",
    "specificity and denotes a linear correspondence balanced accuracy.\n",
    "As Youden’s index is a linear transformation of the mean sensitivity and specificity, its values are difficult to\n",
    "interpret, we retain that a higher value of Y indicates better ability to avoid failure. \n",
    "Youden’s index has been conventionally used to evaluate tests diagnostic, improve the efficiency of\n",
    "Telemedical prevention [[33]](#ref33) [[34]](#ref34).\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/Youden%27s_J_statistic\">Wikipedia page</a>\n",
    "\n",
    "Equals to <a href=\"#BM-(Bookmaker-informedness)\">Bookmaker Informedness</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$Y=BM=TPR+TNR-1$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 138,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0.6000000000000001,\n",
       " 'L2': 0.30000000000000004,\n",
       " 'L3': 0.17142857142857126}"
      ]
     },
     "execution_count": 138,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.Y"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 1.5</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### PLRI (Positive likelihood ratio interpretation)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For more information visit [[33]](#ref33)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<table>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">PLR</td>\n",
    "           <td style=\"text-align:center\">Model contribution</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\"> 1 ></td>\n",
    "           <td style=\"text-align:center;background-color:red;\">Negligible</td>\n",
    "       </tr>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">1 - 5</td>\n",
    "           <td style=\"text-align:center;background-color:orange;\">Poor</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\">5 - 10</td>\n",
    "           <td style=\"text-align:center;background-color:yellow;\">Fair</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\"> > 10 </td>\n",
    "           <td style=\"text-align:center;background-color:green;\">Good</td>\n",
    "       </tr>\n",
    "    \n",
    "    \n",
    "</table>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 139,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 'None', 'L2': 'Poor', 'L3': 'Poor'}"
      ]
     },
     "execution_count": 139,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.PLRI"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 1.5</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### NLRI (Negative likelihood ratio interpretation)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For more information visit [[48]](#ref48)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<table>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">NLR</td>\n",
    "           <td style=\"text-align:center\">Model contribution</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\"> 0.5 - 1</td>\n",
    "           <td style=\"text-align:center;background-color:red;\">Negligible</td>\n",
    "       </tr>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">0.2 - 0.5</td>\n",
    "           <td style=\"text-align:center;background-color:orange;\">Poor</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\">0.1 - 0.2</td>\n",
    "           <td style=\"text-align:center;background-color:yellow;\">Fair</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\"> 0.1 >  </td>\n",
    "           <td style=\"text-align:center;background-color:green;\">Good</td>\n",
    "       </tr>\n",
    "    \n",
    "    \n",
    "</table>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 140,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 'Poor', 'L2': 'Negligible', 'L3': 'Negligible'}"
      ]
     },
     "execution_count": 140,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.NLRI"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 2.2</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### DPI (Discriminant power interpretation)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For more information visit [[33]](#ref33)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<table>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">DP</td>\n",
    "           <td style=\"text-align:center\">Model contribution</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\"> 1 > </td>\n",
    "           <td style=\"text-align:center;background-color:red;\">Poor</td>\n",
    "       </tr>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">1 - 2</td>\n",
    "           <td style=\"text-align:center;background-color:orange;\">Limited</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\">2 - 3</td>\n",
    "           <td style=\"text-align:center;background-color:yellow;\">Fair</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\"> > 3 </td>\n",
    "           <td style=\"text-align:center;background-color:green;\">Good</td>\n",
    "       </tr>\n",
    "    \n",
    "    \n",
    "</table>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 141,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 'None', 'L2': 'Poor', 'L3': 'Poor'}"
      ]
     },
     "execution_count": 141,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.DPI"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 1.5</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### AUCI (AUC value interpretation)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For more information visit [[33]](#ref33)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<table>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">AUC</td>\n",
    "           <td style=\"text-align:center\">Model performance</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\">0.5 - 0.6</td>\n",
    "           <td style=\"text-align:center;background-color:red;\">Poor</td>\n",
    "       </tr>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">0.6 - 0.7</td>\n",
    "           <td style=\"text-align:center;background-color:orange;\">Fair</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\">0.7 - 0.8</td>\n",
    "           <td style=\"text-align:center;background-color:yellowgreen;\">Good</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\"> 0.8 - 0.9</td>\n",
    "           <td style=\"text-align:center;background-color:lawngreen;\">Very Good</td>\n",
    "       </tr>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">0.9 - 1.0</td>\n",
    "           <td style=\"text-align:center;background-color:green;\">Excellent</td>\n",
    "       </tr>\n",
    "    \n",
    "</table>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 142,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 'Very Good', 'L2': 'Fair', 'L3': 'Poor'}"
      ]
     },
     "execution_count": 142,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.AUCI"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 1.6</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### MCCI (Matthews correlation coefficient interpretation)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "MCC is a confusion matrix method of calculating the Pearson product-moment correlation coefficient (not to be confused with Pearson's C). Therefore, it has the same interpretation [[2]](#ref2).\n",
    "\n",
    "For more information visit [[49]](#ref49)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<table>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">MCC</td>\n",
    "           <td style=\"text-align:center\">Interpretation</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\">0.3 ></td>\n",
    "           <td style=\"text-align:center;background-color:Red;\">Negligible</td>\n",
    "       </tr>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">0.3 - 0.5</td>\n",
    "           <td style=\"text-align:center;background-color:orange;\">Weak</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\">0.5 - 0.7</td>\n",
    "           <td style=\"text-align:center;background-color:yellow;\">Moderate</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\"> 0.7 - 0.9</td>\n",
    "           <td style=\"text-align:center;background-color:lawngreen;\">Strong</td>\n",
    "       </tr>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">0.9 - 1.0</td>\n",
    "           <td style=\"text-align:center;background-color:green;\">Very Strong</td>\n",
    "       </tr>\n",
    "    \n",
    "</table>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 143,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 'Moderate', 'L2': 'Negligible', 'L3': 'Negligible'}"
      ]
     },
     "execution_count": 143,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.MCCI"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 2.2</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  only positive values are considered</li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### QI (Yule's Q interpretation)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For more information visit [[67]](#ref67)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<table>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">Q</td>\n",
    "           <td style=\"text-align:center\">Interpretation</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\"> 0.25 > </td>\n",
    "           <td style=\"text-align:center;background-color:red;\">Negligible</td>\n",
    "       </tr>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">0.25 - 0.5</td>\n",
    "           <td style=\"text-align:center;background-color:orange;\">Weak</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\">0.5 - 0.75</td>\n",
    "           <td style=\"text-align:center;background-color:yellow;\">Moderate</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\"> > 0.75 </td>\n",
    "           <td style=\"text-align:center;background-color:green;\">Strong</td>\n",
    "       </tr>\n",
    "    \n",
    "    \n",
    "</table>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 144,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 'None', 'L2': 'Moderate', 'L3': 'Weak'}"
      ]
     },
     "execution_count": 144,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.QI"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 2.6</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### GI (Gini index)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "A chance-standardized variant of the AUC is given by Gini coefficient, taking values between $ 0 $ (no difference\n",
    "between the score distributions of the two classes) and $ 1 $ (complete separation between the two distributions).\n",
    "Gini coefficient is widespread use metric in imbalanced data learning [[33]](#ref33). \n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/Gini_coefficient\">Wikipedia page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$GI=2\\times AUC-1$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 145,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0.6000000000000001,\n",
       " 'L2': 0.30000000000000004,\n",
       " 'L3': 0.17142857142857126}"
      ]
     },
     "execution_count": 145,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.GI"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 1.7</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### LS (Lift score)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In the context of classification, lift compares model predictions to randomly generated predictions. Lift is often used in marketing research combined with gain and lift charts as a visual aid [[35]](#ref35) [[36]](#ref36)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$LS=\\frac{PPV}{PRE}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 146,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 2.4, 'L2': 2.0, 'L3': 1.2}"
      ]
     },
     "execution_count": 146,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.LS"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 1.8</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### AM (Automatic/Manual)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difference between automatic and manual classification i.e., the difference between positive outcomes and of positive samples."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$AM=TOP-P=(TP+FP)-(TP+FN)$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 147,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': -2, 'L2': 1, 'L3': 1}"
      ]
     },
     "execution_count": 147,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.AM"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 1.9</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### BCD (Bray-Curtis dissimilarity)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In ecology and biology, the Bray–Curtis dissimilarity, named after J. Roger Bray and John T. Curtis, is a statistic used to quantify the compositional dissimilarity between two different sites, based on counts at each site [[37]](#ref37).\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/Bray%E2%80%93Curtis_dissimilarity\">Wikipedia page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$BCD=\\frac{|AM|}{\\sum_{i=1}^{|C|}\\Big(TOP_i+P_i\\Big)}=\\frac{|AM|}{2\\times POP}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 148,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0.08333333333333333,\n",
       " 'L2': 0.041666666666666664,\n",
       " 'L3': 0.041666666666666664}"
      ]
     },
     "execution_count": 148,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.BCD"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 1.9</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### OP (Optimized precision)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Optimized precision is a type of hybrid threshold metric and has been proposed as a\n",
    "discriminator for building an optimized heuristic classifier. This metric is a combination of\n",
    "accuracy, sensitivity and specificity metrics. The sensitivity and specificity metrics were used for \n",
    "stabilizing and optimizing the accuracy performance when dealing with an imbalanced class of two-class problems [[40]](#ref40) [[42]](#ref42)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$OP = ACC - \\frac{|TNR-TPR|}{|TNR+TPR|}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 149,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0.5833333333333334, 'L2': 0.5192307692307692, 'L3': 0.5589430894308943}"
      ]
     },
     "execution_count": 149,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.OP"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 2.0</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### IBA (Index of balanced accuracy)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The method combines an unbiased index of its overall accuracy and a measure about\n",
    "how dominant is the class with the highest individual accuracy rate [[41]](#ref41) [[42]](#ref42)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$IBA_{\\alpha}=(1+\\alpha \\times(TPR-TNR))\\times TNR \\times TPR$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 150,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0.36, 'L2': 0.27999999999999997, 'L3': 0.35265306122448975}"
      ]
     },
     "execution_count": 150,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.IBA"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 151,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0.48, 'L2': 0.34, 'L3': 0.3477551020408163}"
      ]
     },
     "execution_count": 151,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.IBA_alpha(0.5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 152,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0.576, 'L2': 0.388, 'L3': 0.34383673469387754}"
      ]
     },
     "execution_count": 152,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.IBA_alpha(0.1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Parameters "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. `alpha` : alpha parameter (type : `float`)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Output"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`{class1: IBA1, class2: IBA2, ...}`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 2.0</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### GM (G-mean)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Geometric mean of specificity and sensitivity [[3]](#ref3) [[41]](#ref41) [[42]](#ref42)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$GM=\\sqrt{TPR \\times TNR}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 153,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0.7745966692414834, 'L2': 0.6324555320336759, 'L3': 0.5855400437691198}"
      ]
     },
     "execution_count": 153,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.GM"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 2.0</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Q (Yule's Q)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In statistics, Yule's Q, also known as the coefficient of colligation, is a measure of association between two binary variables [[45]](#ref45).\n",
    "\n",
    "<a href=\"#QI-(Yule's-Q-interpretation)\">Interpretation</a>\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/Coefficient_of_colligation\">Wikipedia page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$OR = \\frac{TP\\times TN}{FP\\times FN}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$Q = \\frac{OR-1}{OR+1}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 154,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 'None', 'L2': 0.6, 'L3': 0.3333333333333333}"
      ]
     },
     "execution_count": 154,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.Q"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 2.1</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### AGM (Adjusted G-mean)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "An adjusted version of the geometric mean of specificity and sensitivity [[46]](#ref46)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$N_n=\\frac{N}{POP}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$AGM=\\frac{GM+TNR\\times N_n}{1+N_n};TPR>0$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$AGM=0;TPR=0$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 155,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0.8576400016262, 'L2': 0.708612108382005, 'L3': 0.5803410802752335}"
      ]
     },
     "execution_count": 155,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.AGM"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 2.1</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### AGF (Adjusted F-score)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The F-measures used only three of the four elements of the confusion matrix and hence two classifiers with different TNR values may have the same F-score. Therefore, the AGF metric is introduced to use all elements of the confusion matrix and provide more weights to samples which are correctly classified in the minority class [[50]](#ref50)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$AGF=\\sqrt{F_2 \\times InvF_{0.5}}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$F_{2}=5\\times \\frac{PPV\\times TPR}{(4 \\times PPV)+TPR}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$InvF_{0.5}=(1+0.5^2)\\times \\frac{NPV\\times TNR}{(0.5^2 \\times NPV)+TNR}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 156,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0.7285871475307653, 'L2': 0.6286946134619315, 'L3': 0.610088876086563}"
      ]
     },
     "execution_count": 156,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.AGF"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 2.3</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### OC (Overlap coefficient)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The overlap coefficient, or Szymkiewicz–Simpson coefficient, is a similarity measure that measures the overlap between two finite sets. It is defined as the size of the intersection divided by the smaller of the size of the two sets [[52]](#ref52).\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/Overlap_coefficient\">Wikipedia page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$OC=\\frac{TP}{min(TOP,P)}=max(PPV,TPR)$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 157,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 1.0, 'L2': 0.5, 'L3': 0.6}"
      ]
     },
     "execution_count": 157,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.OC"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 2.3</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### BB (Braun-Blanquet similarity)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The Braun-Blanquet coefficient is a similarity measure that is mostly used in botany. It is defined as the size of the intersection divided by the larger of the size of the two sets [[82]](#ref82) [[83]](#ref83)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$BB=\\frac{TP}{max(TOP,P)}=min(PPV,TPR)$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 158,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0.6, 'L2': 0.3333333333333333, 'L3': 0.5}"
      ]
     },
     "execution_count": 158,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.BB"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 3.6</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### OOC (Otsuka-Ochiai coefficient)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In biology, there is a similarity index, known as the Otsuka-Ochiai coefficient named after Yanosuke Otsuka and Akira Ochiai, also known as the Ochiai-Barkman or Ochiai coefficient. If sets are represented as bit vectors, the Otsuka-Ochiai coefficient can be seen to be the same as the cosine similarity [[53]](#ref53).\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/Yanosuke_Otsuka\">Wikipedia page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$OOC=\\frac{TP}{\\sqrt{TOP\\times P}}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 159,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0.7745966692414834, 'L2': 0.4082482904638631, 'L3': 0.5477225575051661}"
      ]
     },
     "execution_count": 159,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.OOC"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 2.3</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### TI (Tversky index)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The Tversky index, named after Amos Tversky, is an asymmetric similarity measure on sets that compares a variant to a prototype. The Tversky index can be seen as a generalization of Dice's coefficient and Tanimoto coefficient [[54]](#ref54).\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/Tversky_index\">Wikipedia page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$TI(\\alpha,\\beta)=\\frac{TP}{TP+\\alpha FN+\\beta FP}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 160,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0.42857142857142855, 'L2': 0.1111111111111111, 'L3': 0.1875}"
      ]
     },
     "execution_count": 160,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.TI(2,3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Parameters "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. `alpha` : alpha coefficient (type : `float`)\n",
    "2. `beta` : beta coefficient (type : `float`)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Output"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`{class1: TI1, class2: TI2, ...}`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 2.4</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### AUPR (Area under the PR curve)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "A PR curve is plotting precision against recall. The precision recall area under curve (AUPR) is just the area under the PR curve. The higher it is, the better the model is [[55]](#ref55) [[56]](#ref56).\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$AUPR=\\frac{TPR+PPV}{2}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 161,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0.8, 'L2': 0.41666666666666663, 'L3': 0.55}"
      ]
     },
     "execution_count": 161,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.AUPR"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 2.4</span> </li>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  this is an approximate calculation of AUPR </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### ICSI (Individual classification success index)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The Individual Classification Success Index (ICSI), is a\n",
    "class-specific symmetric measure defined for classification\n",
    "assessment purpose. ICSI is hence $ 1 $ minus the sum of type I and type II errors.\n",
    "It ranges from $ -1 $ (both errors are maximal, i.e. $ 1 $) to $ 1 $ (both\n",
    "errors are minimal, i.e. $ 0 $), but the value $ 0 $ does not have any\n",
    "clear meaning. The measure is symmetric, and linearly related\n",
    "to the arithmetic mean of TPR and PPV [[58]](#ref58)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$ICSI=PPV+TPR-1$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 162,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0.6000000000000001,\n",
       " 'L2': -0.16666666666666674,\n",
       " 'L3': 0.10000000000000009}"
      ]
     },
     "execution_count": 162,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.ICSI"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 2.5</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### CI (Confidence interval)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In statistics, a confidence interval (CI) is a type of interval estimate (of a population parameter) that is computed from the observed data. The confidence level is the frequency (i.e., the proportion) of possible confidence intervals that contain the true value of their corresponding parameter. In other words, if confidence intervals are constructed using a given confidence level in an infinite number of independent experiments, the proportion of those intervals that contain the true value of the parameter will match the confidence level [[31]](#ref31).\n",
    "\n",
    "Supported statistics : `ACC`,`AUC`,`PRE`,`Overall ACC`,`Kappa`,`TPR`,`TNR`,`PPV`,`NPV`,`PLR`,`NLR`\n",
    "\n",
    "Supported alpha values (two-sided) : 0.001, 0.002, 0.01, 0.02, 0.05, 0.1, 0.2\n",
    "\n",
    "Supported alpha values (one-sided) : 0.0005, 0.001, 0.005, 0.01, 0.05, 0.1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Confidence intervals for `TPR`,`TNR`,`PPV`,`NPV`,`ACC`,`PRE` and `Overall ACC` are calculated using the normal approximation to the binomial distribution [[59]](#ref59), Wilson score [[62]](#ref62) and Agresti-Coull method [[63]](#ref63): \n",
    "\n",
    "#### Normal approximation\n",
    "\n",
    "$$SE=\\sqrt{\\frac{\\hat{p}(1-\\hat{p})}{n}}$$\n",
    "\n",
    "$$CI=\\hat{p}\\pm z\\times SE$$\n",
    "\n",
    "$$n=\\begin{cases}P & \\hat{p} == TPR/FNR\\\\N & \\hat{p} == TNR/FPR\\\\TOP & \\hat{p} == PPV\\\\TON & \\hat{p} ==NPV \\\\POP& \\hat{p} == ACC/ACC_{Overall}\\end{cases}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Wilson score\n",
    "\n",
    "$$CI=\\frac{\\hat{p}+\\frac{z^2}{2n}}{1+\\frac{z^2}{n}}\\pm\\frac{z}{1+\\frac{z^2}{n}}\\sqrt{\\frac{\\hat{p}(1-\\hat{p})}{n}+\\frac{z^2}{4n^2}}$$\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Agresti-Coull\n",
    "\n",
    "$$\\hat{p}=\\frac{x}{n}$$\n",
    "\n",
    "$$\\tilde{p}=\\frac{x+\\frac{z^2}{2}}{n+z^2}$$\n",
    "\n",
    "$$CI =\\tilde{p}\\pm\\sqrt{\\frac{\\tilde{p}(1-\\tilde{p})}{n+z^2}}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Confidence interval for `Kappa` are calculated using Fleiss formula [[24]](#ref24) [[38]](#ref38) :\n",
    "\n",
    "$$SE_{Kappa}=\\sqrt{\\frac{ACC_{Overall}\\times (1-RACC_{Overall})}{(1-RACC_{Overall})^2}}$$\n",
    "\n",
    "$$CI_{Kappa}=Kappa\\pm z\\times SE_{Kappa}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Confidence intervals for `NLR` and `PLR` are calculated using the log method [[60]](#ref60) :\n",
    "\n",
    "$$SE_{LR}=\\sqrt{\\frac{1}{a}-\\frac{1}{b}+\\frac{1}{c}-\\frac{1}{d}}$$\n",
    "\n",
    "$$CI_{LR}=e^{ln(LR)\\pm z\\times SE_{LR}}$$\n",
    "\n",
    "$$PLR:\\begin{cases}a=TP\\\\b=P\\\\c=FP\\\\d=N\\end{cases}$$\n",
    "\n",
    "$$NLR:\\begin{cases}a=FN\\\\b=P\\\\c=TN\\\\d=N\\end{cases}$$\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Confidence interval for `AUC` is calculated using Hanley and McNeil formula [[61]](#ref61) :\n",
    "\n",
    "$$SE_{AUC}=\\sqrt{\\frac{q_0+(N-1)q_1+(P-1)q_2}{N\\times P}}$$\n",
    "\n",
    "$$q_0=AUC(1-AUC)$$\n",
    "\n",
    "$$q_1=\\frac{AUC}{2-AUC}-AUC^2$$\n",
    "\n",
    "$$q_2=\\frac{2AUC^2}{1+AUC}-AUC^2$$\n",
    "\n",
    "$$CI_{AUC}=AUC\\pm z\\times SE_{AUC}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 163,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': [0.21908902300206645, (0.17058551491594975, 1.0294144850840503)],\n",
       " 'L2': [0.3535533905932738, (-0.19296464556281656, 1.1929646455628165)],\n",
       " 'L3': [0.21908902300206645, (0.17058551491594975, 1.0294144850840503)]}"
      ]
     },
     "execution_count": 163,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.CI(\"TPR\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 164,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': [0.21908902300206645, (-0.2769850810763853, 1.0769850810763852)],\n",
       " 'L2': [0.3535533905932738, (-0.5924799769332159, 1.5924799769332159)],\n",
       " 'L3': [0.21908902300206645, (-0.2769850810763853, 1.0769850810763852)]}"
      ]
     },
     "execution_count": 164,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.CI(\"FNR\", alpha=0.001, one_sided=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 165,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': [0.14231876063832774, (0.19325746190524654, 0.6804926643446272)],\n",
       " 'L2': [0.10758287072798381, (0.04696414761482223, 0.44803635738467273)],\n",
       " 'L3': [0.14231876063832774, (0.19325746190524654, 0.6804926643446272)]}"
      ]
     },
     "execution_count": 165,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.CI(\"PRE\", alpha=0.05, binom_method=\"wilson\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 166,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0.14231876063832777, (0.2805568916340536, 0.8343177950165198)]"
      ]
     },
     "execution_count": 166,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.CI(\"Overall ACC\", alpha=0.02, binom_method=\"agresti-coull\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 167,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0.14231876063832777, (0.30438856248221097, 0.8622781041844558)]"
      ]
     },
     "execution_count": 167,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.CI(\"Overall ACC\", alpha=0.05)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Parameters "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. `param` : input parameter (type : `str`)\n",
    "2. `alpha` : type I error (type : `float`, default : `0.05`)\n",
    "3. `one_sided` : one-sided mode flag (type : `bool`, default : `False`)\n",
    "4. `binom_method` : binomial confidence intervals method (type : `str`, default : `normal-approx`)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Output"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. Two-sided : `{class1: [SE1, (Lower CI, Upper CI)], ...}`\n",
    "2. One-sided : `{class1: [SE1, (Lower one-sided CI, Upper one-sided CI)], ...}`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  For more information visit <a href=\"#Example-8-(Confidence-interval)\">Example 8</a></li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 2.5</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### NB (Net benefit)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "NB is a weighted sum of true positive\n",
    "classifications with compensation for false positive classifications by giving\n",
    "these a weight $ w $ [[64]](#ref64) [[65]](#ref65)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$NB=\\frac{TP-w\\times FP}{POP}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Vickers and Elkin (2006) suggested considering a range of thresholds and\n",
    "calculating the NB across these thresholds. The results can be plotted in a\n",
    "decision curve [[66]](#ref66)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$p_t=threshold$$\n",
    "$$w=\\frac{p_t}{1-p_t}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 168,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 0.25, 'L2': 0.0735, 'L3': 0.23525}"
      ]
     },
     "execution_count": 168,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.NB(w=0.059)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Parameters "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. `w` : weight"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Output"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`{class1: NB1, class2: NB2, ...}`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 2.6</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "###  Average"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here \"average\" refers to the arithmetic mean, the sum of the numbers divided by how many numbers are being averaged.\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/Average\">Wikipedia page</a>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 169,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.6111111111111112"
      ]
     },
     "execution_count": 169,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.average(\"PPV\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 170,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.5651515151515151"
      ]
     },
     "execution_count": 170,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.average(\"F1\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 171,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3.0000000000000004"
      ]
     },
     "execution_count": 171,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.average(\"DOR\", none_omit=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Parameters "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. `param` : input parameter (type : `str`)\n",
    "2. `none_omit` : none items omitting flag (type : `bool`, default : `False`)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Output"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`Average`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 2.7</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "###  Weighted average"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The weighted average is similar to an ordinary average, except that instead of each of the data points contributing equally to the final average, some data points contribute more than others.\n",
    "\n",
    "Default weight is **condition positive** (number of positive samples).\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/Weighted_arithmetic_mean\">Wikipedia page</a>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 172,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.6805555555555555"
      ]
     },
     "execution_count": 172,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.weighted_average(\"PPV\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 173,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.606439393939394"
      ]
     },
     "execution_count": 173,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.weighted_average(\"F1\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 174,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.5714285714285716"
      ]
     },
     "execution_count": 174,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.weighted_average(\"DOR\", none_omit=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 175,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.7152097902097901"
      ]
     },
     "execution_count": 175,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.weighted_average(\"F1\", weight={\"L1\": 23, \"L2\": 2, \"L3\": 1})"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Parameters "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. `param` : input parameter (type : `str`)\n",
    "2. `weight` : explicitly passes weights (type : `dict`, default : `None`)\n",
    "3. `none_omit` : none items omitting flag (type : `bool`, default : `False`)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Output"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`Weighted average`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 2.7</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Sensitivity index"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The sensitivity index or d′ is a statistic used in signal detection theory. It provides the separation between the means of the signal and the noise distributions, compared against the standard deviation of the signal or noise distribution.\n",
    "d′ can be estimated from the observed hit rate and false-alarm rate, as follows [[76]](#ref76):"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$d^{\\prime}=Z(TPR) - Z(FPR)$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Function Z(p), p ∈ [0,1], is the inverse of the cumulative distribution function of the Gaussian distribution.\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/Sensitivity_index\">Wikipedia page</a>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 176,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 'None', 'L2': 0.8416212335729143, 'L3': 0.4333594729285047}"
      ]
     },
     "execution_count": 176,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.sensitivity_index()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Output"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`{class1: SI1, class2: SI2, ...}`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 3.1</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### HD (Hamming distance)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In information theory, the Hamming distance between two strings of equal length is the number of positions at which the corresponding symbols are different. In other words, it measures the minimum number of substitutions required to change one string into the other, or the minimum number of errors that could have transformed one string into the other. In a more general context, the Hamming distance is one of several string metrics for measuring the edit distance between two sequences. It is named after the American mathematician Richard Hamming [[80]](#ref80) [[81]](#ref81).\n",
    "\n",
    "A major application is in coding theory, more specifically to block codes, in which the equal-length strings are vectors over a finite field."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"https://en.wikipedia.org/wiki/Hamming_distance\">Wikipedia page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$HD = FN + FP$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 177,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': 2, 'L2': 3, 'L3': 5}"
      ]
     },
     "execution_count": 177,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.HD"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 3.6</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Overall statistics"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Kappa"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Kappa is a statistic that measures inter-rater agreement for qualitative (categorical) items. It is generally thought to be a more robust measure than simple percent agreement calculation, as kappa takes into account the possibility of the agreement occurring by chance [[24]](#ref24).\n",
    "\n",
    "<a href=\"#SOA1-(Landis-&-Koch's-benchmark)\">Benchmark1</a>\n",
    "<a href=\"#SOA2-(Fleiss'-benchmark)\">Benchmark2</a>\n",
    "<a href=\"#SOA3-(Altman's-benchmark)\">Benchmark3</a>\n",
    "<a href=\"#SOA4-(Cicchetti's-benchmark)\">Benchmark4</a>\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/Cohen%27s_kappa\">Wikipedia page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$Kappa=\\frac{ACC_{Overall}-RACC_{Overall}}{1-RACC_{Overall}}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 178,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.35483870967741943"
      ]
     },
     "execution_count": 178,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.Kappa"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.3</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Kappa unbiased"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The unbiased kappa value is defined in terms of total accuracy and a slightly different computation of expected likelihood that averages the reference and response probabilities [[25]](#ref25).\n",
    "\n",
    "Equals to [Scott's Pi](#Scott's-Pi)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$Kappa_{Unbiased}=\\frac{ACC_{Overall}-RACCU_{Overall}}{1-RACCU_{Overall}}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 179,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.34426229508196726"
      ]
     },
     "execution_count": 179,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.KappaUnbiased"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.8.1</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Kappa no prevalence"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Prevalence-adjusted and bias-adjusted kappa (PABAK) [[14]](#ref14)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$Kappa_{NoPrevalence}=2 \\times ACC_{Overall}-1$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 180,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.16666666666666674"
      ]
     },
     "execution_count": 180,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.KappaNoPrevalence"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.8.1</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Weighted kappa"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The weighted kappa allows disagreements to be weighted differently and is especially useful when codes are ordered. Three matrices are involved, the matrix of observed scores, the matrix of expected scores based on chance agreement, and the weight matrix [[70]](#ref70) [[71]](#ref71)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$v_{ij}=1-\\frac{w_{ij}}{max(w)}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$P_e=\\sum_{i,j=1}^{|C|}\\frac{TOP_i \\times P_j}{POP^2}\\times v_{ij}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$P_a=\\sum_{i,j=1}^{|C|}\\frac{Matrix(i,j)}{POP}\\times v_{ij}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$Kappa_{Weighted}=\\frac{P_a-P_e}{1-P_e}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 181,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.39130434782608675"
      ]
     },
     "execution_count": 181,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.weighted_kappa(\n",
    "    weight={\n",
    "        \"L1\": {\"L1\": 0, \"L2\": 1, \"L3\": 2},\n",
    "        \"L2\": {\"L1\": 1, \"L2\": 0, \"L3\": 1},\n",
    "        \"L3\": {\"L1\": 2, \"L2\": 1, \"L3\": 0}})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 182,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\Sepkjaer\\AppData\\Local\\Programs\\Python\\Python35-32\\lib\\site-packages\\pycm-4.2-py3.5.egg\\pycm\\cm.py:850: RuntimeWarning: Invalid weight format; the result is for unweighted kappa.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "0.35483870967741943"
      ]
     },
     "execution_count": 182,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.weighted_kappa()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Parameters "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. `weight` : weight matrix (type : `dict`, default : `None`)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Output"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`Weighted kappa`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 2.7</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Kappa standard error"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The standard error(s) of the Kappa coefficient was obtained by Fleiss (1969) [[24]](#ref24) [[38]](#ref38)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$SE_{Kappa}=\\sqrt{\\frac{ACC_{Overall}\\times (1-RACC_{Overall})}{(1-RACC_{Overall})^2}}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 183,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.2203645326012817"
      ]
     },
     "execution_count": 183,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.Kappa_SE"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.7</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Kappa 95% CI"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Kappa 95% Confidence Interval [[24]](#ref24) [[38]](#ref38)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$CI_{Kappa}=Kappa \\pm 1.96\\times SE_{Kappa}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 184,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(-0.07707577422109269, 0.7867531935759315)"
      ]
     },
     "execution_count": 184,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.Kappa_CI"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.7</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Chi-squared"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Pearson's chi-squared test is a statistical test applied to sets of categorical data to evaluate how likely it is that any observed difference between the sets arose by chance. It is suitable for unpaired data from large samples [[10]](#ref10).\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/Chi-squared_test\">Wikipedia page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\\chi^2=\\sum_{i=1}^{|C|}\\sum_{j=1}^{|C|}\\frac{\\Big(Matrix(i,j)-E(i,j)\\Big)^2}{E(i,j)}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$E(i,j)=\\frac{TOP_j\\times P_i}{POP}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 185,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6.6000000000000005"
      ]
     },
     "execution_count": 185,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.Chi_Squared"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.7</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Chi-squared DF"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Number of degrees of freedom of this confusion matrix for the chi-squared statistic [[10]](#ref10)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$DF=(|C|-1)^2$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 186,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 186,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.DF"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.7</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Phi-squared"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In statistics, the phi coefficient (or mean square contingency coefficient) is a measure of association for two binary variables. Introduced by Karl Pearson, this measure is similar to the Pearson correlation coefficient in its interpretation. In fact, a Pearson correlation coefficient estimated for two binary variables will return the phi coefficient [[10]](#ref10).\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/Phi_coefficient\">Wikipedia page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\\phi^2=\\frac{\\chi^2}{POP}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 187,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.55"
      ]
     },
     "execution_count": 187,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.Phi_Squared"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.7</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Cramer's V"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In statistics, Cramér's V (sometimes referred to as Cramér's phi) is a measure of association between two nominal variables, giving a value between $ 0 $ and $ +1 $ (inclusive). It is based on Pearson's chi-squared statistic and was published by Harald Cramér in 1946 [[26]](#ref26).\n",
    "\n",
    "<a href=\"#SOA5-(Cramer's-benchmark)\">Benchmark</a>\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/Cram%C3%A9r%27s_V\">Wikipedia page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$V=\\sqrt{\\frac{\\phi^2}{|C|-1}}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 188,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.5244044240850758"
      ]
     },
     "execution_count": 188,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.V"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.7</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Standard error"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The standard error (SE) of a statistic (usually an estimate of a parameter) is the standard deviation of its sampling distribution or an estimate of that standard deviation [[31]](#ref31).\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/Standard_error\">Wikipedia page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$SE_{ACC}=\\sqrt{\\frac{ACC\\times (1-ACC)}{POP}}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 189,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.14231876063832777"
      ]
     },
     "execution_count": 189,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.SE"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.7</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 95% CI"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In statistics, a confidence interval (CI) is a type of interval estimate (of a population parameter) that is computed from the observed data. The confidence level is the frequency (i.e., the proportion) of possible confidence intervals that contain the true value of their corresponding parameter. In other words, if confidence intervals are constructed using a given confidence level in an infinite number of independent experiments, the proportion of those intervals that contain the true value of the parameter will match the confidence level [[31]](#ref31).\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/Confidence_interval\">Wikipedia page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$CI=ACC \\pm 1.96\\times SE_{ACC}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 190,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0.30438856248221097, 0.8622781041844558)"
      ]
     },
     "execution_count": 190,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.CI95"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.7</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  <code>CI</code> renamed to <code>CI95</code> in <span style=\"color:red;\">version 2.5</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Bennett's S"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Bennett, Alpert & Goldstein’s S is a statistical measure of inter-rater agreement. It was created by Bennett et al. in 1954.\n",
    "Bennett et al. suggested adjusting inter-rater reliability to accommodate the percentage of rater agreement that might be expected by chance was a better measure than a simple agreement between raters [[8]](#ref8).\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/Bennett,_Alpert,_and_Goldstein%E2%80%99s_S\">Wikipedia Page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$p_c=\\frac{1}{|C|}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$S=\\frac{ACC_{Overall}-p_c}{1-p_c}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 191,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.37500000000000006"
      ]
     },
     "execution_count": 191,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.S"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.5</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Scott's Pi"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Scott's pi (named after William A. Scott) is a statistic for measuring inter-rater reliability for nominal data in communication studies. Textual entities are annotated with categories by different annotators, and various measures are used to assess the extent of agreement between the annotators, one of which is Scott's pi. Since automatically annotating text is a popular problem in natural language processing, and the goal is to get the computer program that is being developed to agree with the humans in the annotations it creates, assessing the extent to which humans agree with each other is important for establishing a reasonable upper limit on computer performance [[7]](#ref7).\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/Scott%27s_Pi\">Wikipedia page</a>\n",
    "\n",
    "\n",
    "Equals to [Kappa Unbiased](#Kappa-unbiased)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$p_c=\\sum_{i=1}^{|C|}(\\frac{TOP_i + P_i}{2\\times POP})^2$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\\pi=\\frac{ACC_{Overall}-p_c}{1-p_c}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 192,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.34426229508196726"
      ]
     },
     "execution_count": 192,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.PI"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.5</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Gwet's AC1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "AC1 was originally introduced by Gwet in 2001 (Gwet, 2001). The interpretation of AC1 is similar to generalized kappa (Fleiss, 1971), which is used to assess inter-rater reliability when there are multiple raters. Gwet (2002) demonstrated that AC1 can overcome the limitations that kappa is sensitive to trait prevalence and rater's classification probabilities (i.e., marginal probabilities), whereas AC1 provides more robust measure of inter-rater reliability [[6]](#ref6)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\\pi_i=\\frac{TOP_i + P_i}{2\\times POP}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$p_c=\\frac{1}{|C|-1}\\sum_{i=1}^{|C|}\\Big(\\pi_i\\times (1-\\pi_i)\\Big)$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$AC_1=\\frac{ACC_{Overall}-p_c}{1-p_c}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 193,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.3893129770992367"
      ]
     },
     "execution_count": 193,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.AC1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.5</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Reference entropy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The entropy of the decision problem itself as defined by the counts for the reference. The entropy of a distribution is the average negative log probability of outcomes [[30]](#ref30)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$Likelihood_{Reference}=\\frac{P_i}{POP}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$Entropy_{Reference}=-\\sum_{i=1}^{|C|}Likelihood_{Reference}(i)\\times\\log_{2}{Likelihood_{Reference}(i)}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$0\\times\\log_{2}{0}\\equiv0$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 194,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.4833557549816874"
      ]
     },
     "execution_count": 194,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.ReferenceEntropy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.8.1</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Response entropy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The entropy of the response distribution. The entropy of a distribution is the average negative log probability of outcomes [[30]](#ref30)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$Likelihood_{Response}=\\frac{TOP_i}{POP}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$Entropy_{Response}=-\\sum_{i=1}^{|C|}Likelihood_{Response}(i)\\times\\log_{2}{Likelihood_{Response}(i)}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$0\\times\\log_{2}{0}\\equiv0$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 195,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.5"
      ]
     },
     "execution_count": 195,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.ResponseEntropy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.8.1</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Cross entropy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The cross-entropy of the response distribution against the reference distribution. The cross-entropy is defined by the negative log probabilities of the response distribution weighted by the reference distribution [[30]](#ref30).\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/Cross_entropy\">Wikipedia page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$Likelihood_{Reference}=\\frac{P_i}{POP}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$Likelihood_{Response}=\\frac{TOP_i}{POP}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$Entropy_{Cross}=-\\sum_{i=1}^{|C|}Likelihood_{Reference}(i)\\times\\log_{2}{Likelihood_{Response}(i)}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$0\\times\\log_{2}{0}\\equiv0$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 196,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.5833333333333335"
      ]
     },
     "execution_count": 196,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.CrossEntropy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.8.1</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Joint entropy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The entropy of the joint reference and response distribution as defined by the underlying matrix [[30]](#ref30)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$P^{'}(i,j)=\\frac{Matrix(i,j)}{POP}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$Entropy_{Joint}=-\\sum_{i=1}^{|C|}\\sum_{j=1}^{|C|}P^{'}(i,j)\\times\\log_{2}{P^{'}(i,j)}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$0\\times\\log_{2}{0}\\equiv0$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 197,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.4591479170272446"
      ]
     },
     "execution_count": 197,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.JointEntropy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.8.1</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Conditional entropy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The entropy of the distribution of categories in the response given that the reference category was as specified [[30]](#ref30).\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/Conditional_entropy\">Wikipedia page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$P^{'}(j|i)=\\frac{Matrix(j,i)}{P_i}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$Entropy_{Conditional}=\\sum_{i=1}^{|C|}\\Bigg(Likelihood_{Reference}(i)\\times\\Big(-\\sum_{j=1}^{|C|}P^{'}(j|i)\\times\\log_{2}{P^{'}(j|i)}\\Big)\\Bigg)$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$0\\times\\log_{2}{0}\\equiv0$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 198,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.9757921620455572"
      ]
     },
     "execution_count": 198,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.ConditionalEntropy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.8.1</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Kullback-Leibler divergence"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In mathematical statistics, the Kullback–Leibler divergence (also called relative entropy) is a measure of how one probability distribution diverges from a second, expected probability distribution  [[11]](#ref11) [[30]](#ref30).\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/Kullback%E2%80%93Leibler_divergence\">Wikipedia Page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$Likelihood_{Response}=\\frac{TOP_i}{POP}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$Likelihood_{Reference}=\\frac{P_i}{POP}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$Divergence=-\\sum_{i=1}^{|C|}Likelihood_{Reference}\\times\\log_{2}{\\frac{Likelihood_{Reference}}{Likelihood_{Response}}}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 199,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.09997757835164581"
      ]
     },
     "execution_count": 199,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.KL"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.8.1</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Mutual information"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Mutual information is defined as Kullback-Leibler divergence, between the product of the individual distributions and the joint distribution.\n",
    "Mutual information is symmetric. We could also subtract the conditional entropy of the reference given the response from the reference entropy to get the same result [[11]](#ref11) [[30]](#ref30).\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/Mutual_information\">Wikipedia Page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$P^{'}(i,j)=\\frac{Matrix(i,j)}{POP}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$Likelihood_{Reference}=\\frac{P_i}{POP}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$Likelihood_{Response}=\\frac{TOP_i}{POP}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$MI=-\\sum_{i=1}^{|C|}\\sum_{j=1}^{|C|}P^{'}(i,j)\\times\\log_{2}\\Big({\\frac{P^{'}(i,j)}{Likelihood_{Reference}(i)\\times Likelihood_{Response}(i) }\\Big)}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$MI=Entropy_{Response}-Entropy_{Conditional}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 200,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.5242078379544428"
      ]
     },
     "execution_count": 200,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.MutualInformation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.8.1</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Goodman & Kruskal's lambda A"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In probability theory and statistics, Goodman & Kruskal's lambda  is a measure of proportional reduction in error in cross tabulation analysis [[12]](#ref12).\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/Goodman_and_Kruskal%27s_lambda\">Wikipedia page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\\lambda_A=\\frac{\\sum_{j=1}^{|C|}Max\\Big(Matrix(-,j)\\Big)-Max(P)}{POP-Max(P)}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 201,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.42857142857142855"
      ]
     },
     "execution_count": 201,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.LambdaA"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.8.1</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Goodman & Kruskal's lambda B"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In probability theory and statistics, Goodman & Kruskal's lambda  is a measure of proportional reduction in error in cross tabulation analysis [[13]](#ref13).\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/Goodman_and_Kruskal%27s_lambda\">Wikipedia Page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\\lambda_B=\\frac{\\sum_{i=1}^{|C|}Max\\Big(Matrix(i,-)\\Big)-Max(TOP)}{POP-Max(TOP)}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 202,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.16666666666666666"
      ]
     },
     "execution_count": 202,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.LambdaB"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.8.1</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### SOA1 (Landis & Koch's benchmark)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For more information visit [[1]](#ref1)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<table>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">Kappa</td>\n",
    "           <td style=\"text-align:center\">Strength of Agreement</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\"> 0 ></td>\n",
    "           <td style=\"text-align:center;background-color:red;\">Poor</td>\n",
    "       </tr>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">0 - 0.2</td>\n",
    "           <td style=\"text-align:center;background-color:orangered;\">Slight</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\">0.2 – 0.4</td>\n",
    "           <td style=\"text-align:center;background-color:orange;\">Fair</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\">0.4 – 0.6</td>\n",
    "           <td style=\"text-align:center;background-color:yellow;\">Moderate</td>\n",
    "       </tr>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">0.6 – 0.8</td>\n",
    "           <td style=\"text-align:center;background-color:lawngreen;\">Substantial</td>\n",
    "       </tr>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">0.8 – 1.0</td>\n",
    "           <td style=\"text-align:center;background-color:green;\">Almost perfect</td>\n",
    "       </tr>\n",
    "    \n",
    "    \n",
    "</table>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 203,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Fair'"
      ]
     },
     "execution_count": 203,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.SOA1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.3</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### SOA2 (Fleiss' benchmark)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For more information visit [[4]](#ref4)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<table>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">Kappa</td>\n",
    "           <td style=\"text-align:center\">Strength of Agreement</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\"> 0.40 ></td>\n",
    "           <td style=\"text-align:center;background-color:red;\">Poor</td>\n",
    "       </tr>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">0.40 - 0.75</td>\n",
    "           <td style=\"text-align:center;background-color:lawngreen;\">Intermediate to Good</td>\n",
    "       </tr>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">More than 0.75</td>\n",
    "           <td style=\"text-align:center;background-color:green;\">Excellent</td>\n",
    "       </tr>\n",
    "    \n",
    "    \n",
    "</table>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 204,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Poor'"
      ]
     },
     "execution_count": 204,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.SOA2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.4</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### SOA3 (Altman's benchmark)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For more information visit [[5]](#ref5)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<table>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">Kappa</td>\n",
    "           <td style=\"text-align:center\">Strength of Agreement</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\"> 0.2 ></td>\n",
    "           <td style=\"text-align:center;background-color:red;\">Poor</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\">0.2 – 0.4</td>\n",
    "           <td style=\"text-align:center;background-color:orange;\">Fair</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\">0.4 – 0.6</td>\n",
    "           <td style=\"text-align:center;background-color:yellow;\">Moderate</td>\n",
    "       </tr>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">0.6 – 0.8</td>\n",
    "           <td style=\"text-align:center;background-color:lawngreen;\">Good</td>\n",
    "       </tr>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">0.8 – 1.0</td>\n",
    "           <td style=\"text-align:center;background-color:green;\">Very Good</td>\n",
    "       </tr>\n",
    "    \n",
    "    \n",
    "</table>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 205,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Fair'"
      ]
     },
     "execution_count": 205,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.SOA3"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.4</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### SOA4 (Cicchetti's benchmark)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For more information visit [[9]](#ref9)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<table>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">Kappa</td>\n",
    "           <td style=\"text-align:center\">Strength of Agreement</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\"> 0.40 ></td>\n",
    "           <td style=\"text-align:center;background-color:red;\">Poor</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\">0.40 – 0.59</td>\n",
    "           <td style=\"text-align:center;background-color:orange;\">Fair</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\">0.59 – 0.74</td>\n",
    "           <td style=\"text-align:center;background-color:lawngreen;\">Good</td>\n",
    "       </tr>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">0.74 – 1.00</td>\n",
    "           <td style=\"text-align:center;background-color:green;\">Excellent</td>\n",
    "       </tr>\n",
    "    \n",
    "    \n",
    "</table>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 206,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Poor'"
      ]
     },
     "execution_count": 206,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.SOA4"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.7</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### SOA5 (Cramer's benchmark)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For more information visit [[47]](#ref47)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<table>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">Cramer's V</td>\n",
    "           <td style=\"text-align:center\">Strength of Association</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\"> 0.1 ></td>\n",
    "           <td style=\"text-align:center;background-color:red;\">Negligible</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\">0.1 – 0.2</td>\n",
    "           <td style=\"text-align:center;background-color:orange;\">Weak</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\">0.2 – 0.4</td>\n",
    "           <td style=\"text-align:center;background-color:yellow;\">Moderate</td>\n",
    "       </tr>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">0.4 – 0.6</td>\n",
    "           <td style=\"text-align:center;background-color:yellowgreen;\">Relatively Strong</td>\n",
    "       </tr>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">0.6 – 0.8</td>\n",
    "           <td style=\"text-align:center;background-color:lawngreen;\">Strong</td>\n",
    "       </tr>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">0.8 – 1.0</td>\n",
    "           <td style=\"text-align:center;background-color:green;\">Very Strong</td>\n",
    "       </tr>\n",
    "    \n",
    "    \n",
    "</table>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 207,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Relatively Strong'"
      ]
     },
     "execution_count": 207,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.SOA5"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 2.2</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### SOA6 (Matthews's benchmark)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "MCC is a confusion matrix method of calculating the Pearson product-moment correlation coefficient (not to be confused with Pearson's C). Therefore, it has the same interpretation [[2]](#ref2).\n",
    "\n",
    "For more information visit [[49]](#ref49)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<table>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">Overall MCC</td>\n",
    "           <td style=\"text-align:center\">Strength of Association</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\">0.3 ></td>\n",
    "           <td style=\"text-align:center;background-color:red;\">Negligible</td>\n",
    "       </tr>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">0.3 - 0.5</td>\n",
    "           <td style=\"text-align:center;background-color:orange;\">Weak</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\">0.5 - 0.7</td>\n",
    "           <td style=\"text-align:center;background-color:yellow;\">Moderate</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\"> 0.7 - 0.9</td>\n",
    "           <td style=\"text-align:center;background-color:lawngreen;\">Strong</td>\n",
    "       </tr>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">0.9 - 1.0</td>\n",
    "           <td style=\"text-align:center;background-color:green;\">Very Strong</td>\n",
    "       </tr>\n",
    "    \n",
    "</table>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 208,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Weak'"
      ]
     },
     "execution_count": 208,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.SOA6"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 2.2</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  only positive values are considered</li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### SOA7 (Goodman & Kruskal's lambda A benchmark)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For more information visit [[84]](#ref84)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<table>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">Lambda A</td>\n",
    "           <td style=\"text-align:center\">Strength of Association</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\">0 - 0.2</td>\n",
    "           <td style=\"text-align:center;background-color:red;\">Very Weak</td>\n",
    "       </tr>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">0.2 - 0.4</td>\n",
    "           <td style=\"text-align:center;background-color:OrangeRed;\">Weak</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\">0.4 - 0.6</td>\n",
    "           <td style=\"text-align:center;background-color:Orange;\">Moderate</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\">0.6 - 0.8</td>\n",
    "           <td style=\"text-align:center;background-color:Yellow;\">Strong</td>\n",
    "       </tr>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">0.8 - 1.0</td>\n",
    "           <td style=\"text-align:center;background-color:LawnGreen;\">Very Strong</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\">1.0</td>\n",
    "           <td style=\"text-align:center;background-color:Green;\">Perfect</td>\n",
    "       </tr>\n",
    "    \n",
    "</table>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 209,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Moderate'"
      ]
     },
     "execution_count": 209,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.SOA7"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 3.8</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### SOA8 (Goodman & Kruskal's lambda B benchmark)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For more information visit [[84]](#ref84)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<table>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">Lambda B</td>\n",
    "           <td style=\"text-align:center\">Strength of Association</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\">0 - 0.2</td>\n",
    "           <td style=\"text-align:center;background-color:red;\">Very Weak</td>\n",
    "       </tr>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">0.2 - 0.4</td>\n",
    "           <td style=\"text-align:center;background-color:OrangeRed;\">Weak</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\">0.4 - 0.6</td>\n",
    "           <td style=\"text-align:center;background-color:Orange;\">Moderate</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\">0.6 - 0.8</td>\n",
    "           <td style=\"text-align:center;background-color:Yellow;\">Strong</td>\n",
    "       </tr>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">0.8 - 1.0</td>\n",
    "           <td style=\"text-align:center;background-color:LawnGreen;\">Very Strong</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\">1.0</td>\n",
    "           <td style=\"text-align:center;background-color:Green;\">Perfect</td>\n",
    "       </tr>\n",
    "    \n",
    "</table>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 210,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Very Weak'"
      ]
     },
     "execution_count": 210,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.SOA8"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 3.8</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### SOA9 (Krippendorff's alpha benchmark)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For more information visit [[85]](#ref85)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<table>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">Alpha</td>\n",
    "           <td style=\"text-align:center\">Strength of Agreement</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\">0.667 ></td>\n",
    "           <td style=\"text-align:center;background-color:Red;\">Low</td>\n",
    "       </tr>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">0.667 - 0.8</td>\n",
    "           <td style=\"text-align:center;background-color:LawnGreen;\">Tentative</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\">0.8 < </td>\n",
    "           <td style=\"text-align:center;background-color:Green;\">High</td>\n",
    "       </tr>\n",
    "</table>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 211,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Low'"
      ]
     },
     "execution_count": 211,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.SOA9"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 3.8</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### SOA10 (Pearson's C benchmark)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For more information visit [[86]](#ref86)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<table>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">C</td>\n",
    "           <td style=\"text-align:center\">Strength of Association</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\">0 - 0.1</td>\n",
    "           <td style=\"text-align:center;background-color:Red;\">Not Appreciable</td>\n",
    "       </tr>\n",
    "       <tr>\n",
    "           <td style=\"text-align:center\">0.1 - 0.2</td>\n",
    "           <td style=\"text-align:center;background-color:Orange;\">Weak</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\">0.2 - 0.3</td>\n",
    "           <td style=\"text-align:center;background-color:LawnGreen;\">Medium</td>\n",
    "       </tr>\n",
    "        <tr>\n",
    "           <td style=\"text-align:center\">0.3 < </td>\n",
    "           <td style=\"text-align:center;background-color:Green;\">Strong</td>\n",
    "       </tr>\n",
    "</table>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 212,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Strong'"
      ]
     },
     "execution_count": 212,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.SOA10"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 3.8</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Overall_ACC"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For more information visit [[3]](#ref3)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$ACC_{Overall}=\\frac{\\sum_{i=1}^{|C|}TP_i}{POP}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Equals to [TPR Micro](#TPR_Micro), [F1 Micro](#F1_Micro) and [PPV Micro](#PPV_Micro)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 213,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.5833333333333334"
      ]
     },
     "execution_count": 213,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.Overall_ACC"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.4</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Overall_RACC"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For more information visit [[24]](#ref24)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$RACC_{Overall}=\\sum_{i=1}^{|C|}RACC_i$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 214,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.3541666666666667"
      ]
     },
     "execution_count": 214,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.Overall_RACC"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.4</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Overall_RACCU"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For more information visit [[25]](#ref25)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$RACCU_{Overall}=\\sum_{i=1}^{|C|}RACCU_i$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 215,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.3645833333333333"
      ]
     },
     "execution_count": 215,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.Overall_RACCU"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.8.1</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### PPV_Micro"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For more information visit [[3]](#ref3)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$PPV_{Micro}=\\frac{\\sum_{i=1}^{|C|}TP_i}{\\sum_{i=1}^{|C|}TP_i+FP_i}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Equals to [TPR Micro](#TPR_Micro), [F1 Micro](#F1_Micro) and [Overall ACC](#Overall_ACC)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 216,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.5833333333333334"
      ]
     },
     "execution_count": 216,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.PPV_Micro"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.4</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### NPV_Micro"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For more information visit [[3]](#ref3)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$NPV_{Micro}=\\frac{\\sum_{i=1}^{|C|}TN_i}{\\sum_{i=1}^{|C|}TN_i+FN_i}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 217,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.7916666666666666"
      ]
     },
     "execution_count": 217,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.NPV_Micro"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 3.9</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### TPR_Micro"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For more information visit [[3]](#ref3)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$TPR_{Micro}=\\frac{\\sum_{i=1}^{|C|}TP_i}{\\sum_{i=1}^{|C|}TP_i+FN_i}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Equals to [PPV Micro](#PPV_Micro), [F1 Micro](#F1_Micro) and [Overall ACC](#Overall_ACC)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 218,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.5833333333333334"
      ]
     },
     "execution_count": 218,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.TPR_Micro"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.4</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### TNR_Micro"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For more information visit [[3]](#ref3)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$TNR_{Micro}=\\frac{\\sum_{i=1}^{|C|}TN_i}{\\sum_{i=1}^{|C|}TN_i+FP_i}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 219,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.7916666666666666"
      ]
     },
     "execution_count": 219,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.TNR_Micro"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 2.6</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### FPR_Micro"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For more information visit [[3]](#ref3)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$FPR_{Micro}=\\frac{\\sum_{i=1}^{|C|}FP_i}{\\sum_{i=1}^{|C|}TN_i+FP_i}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 220,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.20833333333333337"
      ]
     },
     "execution_count": 220,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.FPR_Micro"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 2.6</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### FNR_Micro"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For more information visit [[3]](#ref3)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$FNR_{Micro}=\\frac{\\sum_{i=1}^{|C|}FN_i}{\\sum_{i=1}^{|C|}TP_i+FN_i}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 221,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.41666666666666663"
      ]
     },
     "execution_count": 221,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.FNR_Micro"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 2.6</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### F1_Micro"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For more information visit [[3]](#ref3)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$F_{1_{Micro}}=2\\frac{\\sum_{i=1}^{|C|}TPR_i\\times PPV_i}{\\sum_{i=1}^{|C|}TPR_i+PPV_i}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Equals to [PPV Micro](#PPV_Micro), [TPR Micro](#TPR_Micro) and [Overall ACC](#Overall_ACC)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 222,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.5833333333333334"
      ]
     },
     "execution_count": 222,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.F1_Micro"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 2.2</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### PPV_Macro"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For more information visit [[3]](#ref3)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$PPV_{Macro}=\\frac{1}{|C|}\\sum_{i=1}^{|C|}\\frac{TP_i}{TP_i+FP_i}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 223,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.611111111111111"
      ]
     },
     "execution_count": 223,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.PPV_Macro"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.4</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### NPV_Macro"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For more information visit [[3]](#ref3)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$NPV_{Macro}=\\frac{1}{|C|}\\sum_{i=1}^{|C|}\\frac{TN_i}{TN_i+FN_i}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 224,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.7777777777777777"
      ]
     },
     "execution_count": 224,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.NPV_Macro"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 3.9</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### TPR_Macro"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For more information visit [[3]](#ref3)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$TPR_{Macro}=\\frac{1}{|C|}\\sum_{i=1}^{|C|}\\frac{TP_i}{TP_i+FN_i}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 225,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.5666666666666668"
      ]
     },
     "execution_count": 225,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.TPR_Macro"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.4</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### TNR_Macro"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For more information visit [[3]](#ref3)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$TNR_{Macro}=\\frac{1}{|C|}\\sum_{i=1}^{|C|}\\frac{TN_i}{TN_i+FP_i}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 226,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.7904761904761904"
      ]
     },
     "execution_count": 226,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.TNR_Macro"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 2.6</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### FPR_Macro"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For more information visit [[3]](#ref3)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$FPR_{Macro}=\\frac{1}{|C|}\\sum_{i=1}^{|C|}\\frac{FP_i}{TN_i+FP_i}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 227,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.20952380952380956"
      ]
     },
     "execution_count": 227,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.FPR_Macro"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 2.6</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### FNR_Macro"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For more information visit [[3]](#ref3)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$FNR_{Macro}=\\frac{1}{|C|}\\sum_{i=1}^{|C|}\\frac{FN_i}{TP_i+FN_i}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 228,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.43333333333333324"
      ]
     },
     "execution_count": 228,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.FNR_Macro"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 2.6</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### F1_Macro"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For more information visit [[3]](#ref3)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$F_{1_{Macro}}=\\frac{2}{|C|}\\sum_{i=1}^{|C|}\\frac{TPR_i\\times PPV_i}{TPR_i+PPV_i}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 229,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.5651515151515151"
      ]
     },
     "execution_count": 229,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.F1_Macro"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 2.2</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### ACC_Macro"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For more information visit [[3]](#ref3)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$ACC_{Macro}=\\frac{1}{|C|}\\sum_{i=1}^{|C|}{ACC_i}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 230,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.7222222222222223"
      ]
     },
     "execution_count": 230,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.ACC_Macro"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 2.2</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Overall_J"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For more information visit [[29]](#ref29)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$J_{Mean}=\\frac{1}{|C|}\\sum_{i=1}^{|C|}J_i$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$J_{Sum}=\\sum_{i=1}^{|C|}J_i$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$J_{Overall}=(J_{Sum},J_{Mean})$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 231,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1.225, 0.4083333333333334)"
      ]
     },
     "execution_count": 231,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.Overall_J"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.9</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Hamming loss"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The average Hamming loss or Hamming distance between two sets of samples [[31]](#ref31)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$L_{Hamming}=\\frac{1}{POP}\\sum_{i=1}^{POP}1(y_i \\neq \\widehat{y}_i)$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 232,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.41666666666666663"
      ]
     },
     "execution_count": 232,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.HammingLoss"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 1.0</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Zero-one loss"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Zero-one loss is a common  loss function used with  classification learning. It assigns $ 0 $ to loss for a correct classification and $ 1 $ for an incorrect classification [[31]](#ref31)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$L_{0-1}=\\sum_{i=1}^{POP}1(y_i \\neq \\widehat{y}_i)$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 233,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 233,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.ZeroOneLoss"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 1.1</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### NIR (No information rate)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Largest class percentage in the data [[57]](#ref57)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$NIR=\\frac{1}{POP}Max(P)$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 234,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.4166666666666667"
      ]
     },
     "execution_count": 234,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.NIR"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 1.2</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### P-Value"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In statistical hypothesis testing, the p-value or probability value is, for a given statistical model, the probability that, when the null hypothesis is true, the statistical summary (such as the absolute value of the sample mean difference between two compared groups) would be greater than or equal to the actual observed results [[31]](#ref31) .    \n",
    "Here a one-sided binomial test to see if the accuracy is better than the no information rate [[57]](#ref57).\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/P-value\">Wikipedia Page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$x=\\sum_{i=1}^{|C|}TP_{i}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$p=NIR$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$n=POP$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$P-Value_{(ACC > NIR)}=1-\\sum_{i=1}^{x}\\left(\\begin{array}{c}n\\\\ i\\end{array}\\right)p^{i}(1-p)^{n-i}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 235,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.18926430237560654"
      ]
     },
     "execution_count": 235,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.PValue"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 1.2</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Overall_CEN"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For more information visit [[17]](#ref17)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$P_j=\\frac{\\sum_{k=1}^{|C|}\\Big(Matrix(j,k)+Matrix(k,j)\\Big)}{2\\sum_{k,l=1}^{|C|}Matrix(k,l)}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$CEN_{Overall}=\\sum_{j=1}^{|C|}P_jCEN_j$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 236,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.4638112995385119"
      ]
     },
     "execution_count": 236,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.Overall_CEN"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 1.3</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Overall_MCEN"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For more information visit [[19]](#ref19)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\\alpha=\\begin{cases}1 & |C| > 2\\\\0 & |C| = 2\\end{cases}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$P_j=\\frac{\\sum_{k=1}^{|C|}\\Big(Matrix(j,k)+Matrix(k,j)\\Big)-Matrix(j,j)}{2\\sum_{k,l=1}^{|C|}Matrix(k,l)-\\alpha \\sum_{k=1}^{|C|}Matrix(k,k)}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$MCEN_{Overall}=\\sum_{j=1}^{|C|}P_jMCEN_j$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 237,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.5189369467580801"
      ]
     },
     "execution_count": 237,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.Overall_MCEN"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 1.3</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Overall_MCC"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For more information visit [[20]](#ref20) [[27]](#ref27).\n",
    "\n",
    "<a href=\"#SOA6-(Matthews's-benchmark)\">Benchmark</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$MCC_{Overall}=\\frac{cov(X,Y)}{\\sqrt{cov(X,X)\\times cov(Y,Y)}}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$cov(X,Y)=\\sum_{i,j,k=1}^{|C|}\\Big(Matrix(i,i)Matrix(k,j)-Matrix(j,i)Matrix(i,k)\\Big)$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$cov(X,X) = \\sum_{i=1}^{|C|}\\Bigg[\\Big(\\sum_{j=1}^{|C|}Matrix(j,i)\\Big)\\Big(\\sum_{k,l=1,k\\neq i}^{|C|}Matrix(l,k)\\Big)\\Bigg]$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$cov(Y,Y) = \\sum_{i=1}^{|C|}\\Bigg[\\Big(\\sum_{j=1}^{|C|}Matrix(i,j)\\Big)\\Big(\\sum_{k,l=1,k\\neq i}^{|C|}Matrix(k,l)\\Big)\\Bigg]$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 238,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.36666666666666664"
      ]
     },
     "execution_count": 238,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.Overall_MCC"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 1.4</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### RR (Global performance index)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For more information visit [[21]](#ref21)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$RR=\\frac{1}{|C|}\\sum_{i,j=1}^{|C|}Matrix(i,j)$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 239,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4.0"
      ]
     },
     "execution_count": 239,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.RR"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 1.4</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### CBA (Class balance accuracy)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "As an evaluation tool, CBA creates an overall assessment of\n",
    "model predictive power by scrutinizing measures simultaneously across each class in a conservative manner that guarantees that a model’s ability to recall observations from each class and\n",
    "its ability to do so efficiently won’t fall below the bound [[22]](#ref22) [[51]](#ref51)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$CBA=\\frac{\\sum_{i=1}^{|C|}\\frac{Matrix(i,i)}{Max(TOP_i,P_i)}}{|C|}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 240,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.4777777777777778"
      ]
     },
     "execution_count": 240,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.CBA"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 1.4</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### AUNU"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "When dealing with multiclass problems, a global measure of classification performances based on the ROC approach (AUNU) has been proposed as the average of single-class measures [[23]](#ref23)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$AUNU=\\frac{\\sum_{i=1}^{|C|}AUC_i}{|C|}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 241,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.6785714285714285"
      ]
     },
     "execution_count": 241,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.AUNU"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 1.4</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### AUNP"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Another option (AUNP) is that of averaging the $ AUC_i $ values with weights proportional to the number of samples experimentally belonging to each class, that is, the a priori class distribution [[23]](#ref23)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$AUNP=\\sum_{i=1}^{|C|}\\frac{P_i}{POP}AUC_i$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 242,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.6857142857142857"
      ]
     },
     "execution_count": 242,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.AUNP"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 1.4</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### RCI (Relative classifier information)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Performance of different classifiers on the same domain can be measured by\n",
    "comparing relative classifier information while classifier information (mutual information) can be used for comparison across different decision problems [[32]](#ref32) [[22]](#ref22)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$H_d=-\\sum_{i=1}^{|C|}\\Big(\\frac{\\sum_{l=1}^{|C|}Matrix(i,l)}{\\sum_{h,k=1}^{|C|}Matrix(h,k)}log_2\\frac{\\sum_{l=1}^{|C|}Matrix(i,l)}{\\sum_{h,k=1}^{|C|}Matrix(h,k)}\\Big)=Entropy_{Reference}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$H_o=\\sum_{j=1}^{|C|}\\Big(\\frac{\\sum_{k=1}^{|C|}Matrix(k,j)}{\\sum_{h,l=0}^{|C|}Matrix(h,l)}H_{oj}\\Big)=Entropy_{Conditional}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$H_{oj}=-\\sum_{i=1}^{|C|}\\Big(\\frac{Matrix(i,j)}{\\sum_{k=1}^{|C|}Matrix(k,j)}log_2\\frac{Matrix(i,j)}{\\sum_{k=1}^{|C|}Matrix(k,j)}\\Big)$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$RCI=\\frac{H_d-H_o}{H_d}=\\frac{MI}{Entropy_{Reference}}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 243,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.3533932006492363"
      ]
     },
     "execution_count": 243,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.RCI"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 1.5</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Pearson's C"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The contingency coefficient is a coefficient of association that tells whether two variables or data sets are independent or dependent of/on each other. It is also known as Pearson’s coefficient (not to be confused with Pearson’s coefficient of skewness) [[43]](#ref43) [[44]](#ref44)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$C=\\sqrt{\\frac{\\chi^2}{\\chi^2+POP}}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 244,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.5956833971812706"
      ]
     },
     "execution_count": 244,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.C"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 2.0</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### CSI (Classification success index)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The Classification Success Index (CSI) is an overall\n",
    "measure defined by averaging ICSI over all classes [[58]](#ref58)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$CSI=\\frac{1}{|C|}\\sum_{i=1}^{|C|}{ICSI_i}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 245,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.1777777777777778"
      ]
     },
     "execution_count": 245,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.CSI"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 2.5</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### ARI (Adjusted Rand index)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The Rand index or Rand measure (named after William M. Rand) in statistics, and in particular in data clustering, is a measure of the similarity between two data clusterings. A form of the Rand index may be defined that is adjusted for the chance grouping of elements, this is the adjusted Rand index. From a mathematical standpoint, Rand index is related to the accuracy, but is applicable even when class labels are not used [[68]](#ref68).\n",
    "\n",
    "The Adjusted Rand Index (ARI) is frequently used in cluster validation since it is a measure of agreement between two partitions: one given by the clustering process and the other defined by external criteria, but it can also be used in supervised learning [[69]](#ref69).\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/Rand_index#Adjusted_Rand_index\">Wikipedia Page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$X=\\frac{\\sum_{i}C_{2}^{P_i}\\times \\sum_{j}C_{2}^{TOP_j}}{C_2^{POP}}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$ARI=\\frac{\\sum_{i,j}C_{2}^{Matrix(i,j)}-X}{\\frac{1}{2}[\\sum_{i}C_{2}^{P_i} + \\sum_{j}C_{2}^{TOP_j}]-X}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 246,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.09206349206349207"
      ]
     },
     "execution_count": 246,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.ARI"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  $ C_{r}^{n} $ is the number of combinations of $ n $ objects taken $ r $</li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 2.6</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Bangdiwala's B"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Bangdiwala's B statistic was created by Shrikant Bangdiwala in 1985 and is a measure of inter-rater agreement. While not as commonly used as the kappa statistic the B test has been used by various workers [[72]](#ref72) [[73]](#ref73).\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/Bangdiwala%27s_B\">Wikipedia Page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$B=\\frac{\\sum_{i=1}^{|C|}TP_i^2}{\\sum_{i=1}^{|C|}TOP_i\\times P_i}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 247,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.37254901960784315"
      ]
     },
     "execution_count": 247,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.B"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 2.7</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Krippendorff's alpha"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Krippendorff's alpha coefficient, named after academic Klaus Krippendorff, is a statistical measure of the agreement achieved when coding a set of units of analysis in terms of the values of a variable.\n",
    "Krippendorff's alpha generalizes several known statistics, often called measures of inter-coder agreement, inter-rater reliability, reliability of coding given sets of units (as distinct from unitizing) but it also distinguishes itself from statistics that are called reliability coefficients but are unsuitable to the particulars of coding data generated for subsequent analysis [[74]](#ref74).\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/Krippendorff%27s_alpha\">Wikipedia Page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\\epsilon = \\frac{1}{2\\times POP}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$P_a=(1-\\epsilon)\\times ACC_{Overall}+\\epsilon$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$P_e=RACCU_{Overall}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\\alpha=\\frac{P_a-P_e}{1-P_e}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 248,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.3715846994535519"
      ]
     },
     "execution_count": 248,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.Alpha"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 2.8</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Weighted alpha"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Weighted Krippendorff's alpha coefficient [[74]](#ref74)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\\epsilon = \\frac{1}{2\\times POP}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$v_{ij}=1-\\frac{w_{ij}}{max(w)}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$P_e=\\sum_{i,j=1}^{|C|}(\\frac{TOP_i \\times P_j}{2 \\times POP})^2\\times v_{ij}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$P_a^*=\\sum_{i,j=1}^{|C|}\\frac{Matrix(i,j)}{POP}\\times v_{ij}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$P_a=(1-\\epsilon)\\times P_a^*+\\epsilon$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\\alpha_{Weighted}=\\frac{P_a-P_e}{1-P_e}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 249,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.374757281553398"
      ]
     },
     "execution_count": 249,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.weighted_alpha(\n",
    "    weight={\n",
    "        \"L1\": {\"L1\": 0, \"L2\": 1, \"L3\": 2},\n",
    "        \"L2\": {\"L1\": 1, \"L2\": 0, \"L3\": 1},\n",
    "        \"L3\": {\"L1\": 2, \"L2\": 1, \"L3\": 0}})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 250,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\Sepkjaer\\AppData\\Local\\Programs\\Python\\Python35-32\\lib\\site-packages\\pycm-4.2-py3.5.egg\\pycm\\cm.py:873: RuntimeWarning: Invalid weight format; the result is for unweighted alpha.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "0.3715846994535519"
      ]
     },
     "execution_count": 250,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.weighted_alpha()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Parameters "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. `weight` : weight matrix (type : `dict`, default : `None`)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Output"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`Weighted alpha`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 2.8</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Aickin's alpha"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Aickin's alpha coefficient [[75]](#ref75)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\\alpha^{(t+1)}=\\frac{p_a-p_e^{(t)}}{1-p_e^{(t)}}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$p_e^{(t)}=\\sum_{k=1}^{|C|}p_{k|H}^{A(t)}\\times p_{k|H}^{B(t)}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$p_a=ACC_{Overall}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$p_{k|H}^{A(t+1)}=\\frac{TOP_k}{(1-\\alpha^{(t)})+\\alpha^{(t)}\\times \\frac{p_{k|H}^{B(t)}}{p_e^{(t)}}\\times POP}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$p_{k|H}^{B(t+1)}=\\frac{P_k}{(1-\\alpha^{(t)})+\\alpha^{(t)}\\times \\frac{p_{k|H}^{A(t)}}{p_e^{(t)}}\\times POP}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$Stop:|\\alpha^{(t+1)}-\\alpha^{(t)}|<\\epsilon$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 251,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.38540577344968524"
      ]
     },
     "execution_count": 251,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.aickin_alpha()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 252,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.38545857383594895"
      ]
     },
     "execution_count": 252,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.aickin_alpha(max_iter=2000, epsilon=0.00003)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Parameters "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. `epsilon` : difference threshold (type : `float`, default : `0.0001`)\n",
    "2. `max_iter` : maximum number of iterations (type : `int`, default : `200`)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Output"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`Aickin's alpha`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 2.8</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Brier score"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The Brier Score is a strictly proper score function or strictly proper scoring rule that measures the accuracy of probabilistic predictions. For unidimensional predictions, it is strictly equivalent to the mean squared error as applied to predicted probabilities [[78]](#ref78) [[79]](#ref79).\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/Brier_score\">Wikipedia Page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$BS=\\frac{1}{N} \\sum_{t=1}^{N}(f_t-o_t)^2$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "in which $f_t$ is the probability that was forecast, $o_t$ the actual outcome of the event at instance $t$ ($0$ if it does not happen and $1$ if it does happen) and $N$ is the number of forecasting instances."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 253,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.03749999999999999"
      ]
     },
     "execution_count": 253,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm_test = ConfusionMatrix([0, 1, 1, 0], [0.1, 0.9, 0.8, 0.3], threshold=lambda x: 1)\n",
    "cm_test.brier_score()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 254,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.6875"
      ]
     },
     "execution_count": 254,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm_test.brier_score(pos_class=0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Parameters "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. `pos_class` : positive class name (type : `int/str`, default : `None`)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Output"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`Brier score`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 3.4</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  This option only works in binary probability mode</li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  <code>pos_class</code> always defaults to the greater class name (i.e. <code>max(classes)</code>), unless, the <code>actual_vector</code> contains string. In that case, <code>pos_class</code> does not have any default value, and it must be explicitly specified or else an error will result.</li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Log loss"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In information theory, the cross-entropy between two probability distributions \n",
    "$p$ and $q$ over the same underlying set of events measures the average number of bits needed to identify an event drawn from the set if a coding scheme used for the set is optimized for an estimated probability distribution $q$, rather than the true distribution $p$.\n",
    "This is also known as the log loss (logarithmic loss or logistic loss); the terms \"log loss\" and \"cross-entropy loss\" are used interchangeably. [[30]](#ref30).\n",
    "\n",
    "<a href=\"https://en.wikipedia.org/wiki/Cross_entropy\">Wikipedia Page</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$L_{\\log}(y, p) = -(y \\log (p) + (1 - y) \\log (1 - p))$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 255,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.19763488164214868"
      ]
     },
     "execution_count": 255,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm_test.log_loss()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 256,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.854645225687032"
      ]
     },
     "execution_count": 256,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm_test.log_loss(pos_class=0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Parameters "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. `pos_class` : positive class name (type : `int/str`, default : `None`)\n",
    "2. `normalize` : normalization flag (type : `bool`, default : `True`)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Output"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`Log loss`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 3.9</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  This option only works in binary probability mode</li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  <code>pos_class</code> always defaults to the greater class name (i.e. <code>max(classes)</code>), unless, the <code>actual_vector</code> contains string. In that case, <code>pos_class</code> does not have any default value, and it must be explicitly specified or else an error will result.</li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Print"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Full"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 257,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Predict  L1       L2       L3       \n",
      "Actual\n",
      "L1       3        0        2        \n",
      "\n",
      "L2       0        1        1        \n",
      "\n",
      "L3       0        2        3        \n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "Overall Statistics : \n",
      "\n",
      "95% CI                                                            (0.30439,0.86228)\n",
      "ACC Macro                                                         0.72222\n",
      "ARI                                                               0.09206\n",
      "AUNP                                                              0.68571\n",
      "AUNU                                                              0.67857\n",
      "Bangdiwala B                                                      0.37255\n",
      "Bennett S                                                         0.375\n",
      "CBA                                                               0.47778\n",
      "CSI                                                               0.17778\n",
      "Chi-Squared                                                       6.6\n",
      "Chi-Squared DF                                                    4\n",
      "Conditional Entropy                                               0.97579\n",
      "Cramer V                                                          0.5244\n",
      "Cross Entropy                                                     1.58333\n",
      "F1 Macro                                                          0.56515\n",
      "F1 Micro                                                          0.58333\n",
      "FNR Macro                                                         0.43333\n",
      "FNR Micro                                                         0.41667\n",
      "FPR Macro                                                         0.20952\n",
      "FPR Micro                                                         0.20833\n",
      "Gwet AC1                                                          0.38931\n",
      "Hamming Loss                                                      0.41667\n",
      "Joint Entropy                                                     2.45915\n",
      "KL Divergence                                                     0.09998\n",
      "Kappa                                                             0.35484\n",
      "Kappa 95% CI                                                      (-0.07708,0.78675)\n",
      "Kappa No Prevalence                                               0.16667\n",
      "Kappa Standard Error                                              0.22036\n",
      "Kappa Unbiased                                                    0.34426\n",
      "Krippendorff Alpha                                                0.37158\n",
      "Lambda A                                                          0.42857\n",
      "Lambda B                                                          0.16667\n",
      "Mutual Information                                                0.52421\n",
      "NIR                                                               0.41667\n",
      "NPV Macro                                                         0.77778\n",
      "NPV Micro                                                         0.79167\n",
      "Overall ACC                                                       0.58333\n",
      "Overall CEN                                                       0.46381\n",
      "Overall J                                                         (1.225,0.40833)\n",
      "Overall MCC                                                       0.36667\n",
      "Overall MCEN                                                      0.51894\n",
      "Overall RACC                                                      0.35417\n",
      "Overall RACCU                                                     0.36458\n",
      "P-Value                                                           0.18926\n",
      "PPV Macro                                                         0.61111\n",
      "PPV Micro                                                         0.58333\n",
      "Pearson C                                                         0.59568\n",
      "Phi-Squared                                                       0.55\n",
      "RCI                                                               0.35339\n",
      "RR                                                                4.0\n",
      "Reference Entropy                                                 1.48336\n",
      "Response Entropy                                                  1.5\n",
      "SOA1(Landis & Koch)                                               Fair\n",
      "SOA2(Fleiss)                                                      Poor\n",
      "SOA3(Altman)                                                      Fair\n",
      "SOA4(Cicchetti)                                                   Poor\n",
      "SOA5(Cramer)                                                      Relatively Strong\n",
      "SOA6(Matthews)                                                    Weak\n",
      "SOA7(Lambda A)                                                    Moderate\n",
      "SOA8(Lambda B)                                                    Very Weak\n",
      "SOA9(Krippendorff Alpha)                                          Low\n",
      "SOA10(Pearson C)                                                  Strong\n",
      "Scott PI                                                          0.34426\n",
      "Standard Error                                                    0.14232\n",
      "TNR Macro                                                         0.79048\n",
      "TNR Micro                                                         0.79167\n",
      "TPR Macro                                                         0.56667\n",
      "TPR Micro                                                         0.58333\n",
      "Zero-one Loss                                                     5\n",
      "\n",
      "Class Statistics :\n",
      "\n",
      "Classes                                                           L1            L2            L3            \n",
      "ACC(Accuracy)                                                     0.83333       0.75          0.58333       \n",
      "AGF(Adjusted F-score)                                             0.72859       0.62869       0.61009       \n",
      "AGM(Adjusted geometric mean)                                      0.85764       0.70861       0.58034       \n",
      "AM(Difference between automatic and manual classification)        -2            1             1             \n",
      "AUC(Area under the ROC curve)                                     0.8           0.65          0.58571       \n",
      "AUCI(AUC value interpretation)                                    Very Good     Fair          Poor          \n",
      "AUPR(Area under the PR curve)                                     0.8           0.41667       0.55          \n",
      "BB(Braun-Blanquet similarity)                                     0.6           0.33333       0.5           \n",
      "BCD(Bray-Curtis dissimilarity)                                    0.08333       0.04167       0.04167       \n",
      "BM(Informedness or bookmaker informedness)                        0.6           0.3           0.17143       \n",
      "CEN(Confusion entropy)                                            0.25          0.49658       0.60442       \n",
      "DOR(Diagnostic odds ratio)                                        None          4.0           2.0           \n",
      "DP(Discriminant power)                                            None          0.33193       0.16597       \n",
      "DPI(Discriminant power interpretation)                            None          Poor          Poor          \n",
      "ERR(Error rate)                                                   0.16667       0.25          0.41667       \n",
      "F0.5(F0.5 score)                                                  0.88235       0.35714       0.51724       \n",
      "F1(F1 score - harmonic mean of precision and sensitivity)         0.75          0.4           0.54545       \n",
      "F2(F2 score)                                                      0.65217       0.45455       0.57692       \n",
      "FDR(False discovery rate)                                         0.0           0.66667       0.5           \n",
      "FN(False negative/miss/type 2 error)                              2             1             2             \n",
      "FNR(Miss rate or false negative rate)                             0.4           0.5           0.4           \n",
      "FOR(False omission rate)                                          0.22222       0.11111       0.33333       \n",
      "FP(False positive/type 1 error/false alarm)                       0             2             3             \n",
      "FPR(Fall-out or false positive rate)                              0.0           0.2           0.42857       \n",
      "G(G-measure geometric mean of precision and sensitivity)          0.7746        0.40825       0.54772       \n",
      "GI(Gini index)                                                    0.6           0.3           0.17143       \n",
      "GM(G-mean geometric mean of specificity and sensitivity)          0.7746        0.63246       0.58554       \n",
      "HD(Hamming distance)                                              2             3             5             \n",
      "IBA(Index of balanced accuracy)                                   0.36          0.28          0.35265       \n",
      "ICSI(Individual classification success index)                     0.6           -0.16667      0.1           \n",
      "IS(Information score)                                             1.26303       1.0           0.26303       \n",
      "J(Jaccard index)                                                  0.6           0.25          0.375         \n",
      "LS(Lift score)                                                    2.4           2.0           1.2           \n",
      "MCC(Matthews correlation coefficient)                             0.68313       0.2582        0.16903       \n",
      "MCCI(Matthews correlation coefficient interpretation)             Moderate      Negligible    Negligible    \n",
      "MCEN(Modified confusion entropy)                                  0.26439       0.5           0.6875        \n",
      "MK(Markedness)                                                    0.77778       0.22222       0.16667       \n",
      "N(Condition negative)                                             7             10            7             \n",
      "NLR(Negative likelihood ratio)                                    0.4           0.625         0.7           \n",
      "NLRI(Negative likelihood ratio interpretation)                    Poor          Negligible    Negligible    \n",
      "NPV(Negative predictive value)                                    0.77778       0.88889       0.66667       \n",
      "OC(Overlap coefficient)                                           1.0           0.5           0.6           \n",
      "OOC(Otsuka-Ochiai coefficient)                                    0.7746        0.40825       0.54772       \n",
      "OP(Optimized precision)                                           0.58333       0.51923       0.55894       \n",
      "P(Condition positive or support)                                  5             2             5             \n",
      "PLR(Positive likelihood ratio)                                    None          2.5           1.4           \n",
      "PLRI(Positive likelihood ratio interpretation)                    None          Poor          Poor          \n",
      "POP(Population)                                                   12            12            12            \n",
      "PPV(Precision or positive predictive value)                       1.0           0.33333       0.5           \n",
      "PRE(Prevalence)                                                   0.41667       0.16667       0.41667       \n",
      "Q(Yule Q - coefficient of colligation)                            None          0.6           0.33333       \n",
      "QI(Yule Q interpretation)                                         None          Moderate      Weak          \n",
      "RACC(Random accuracy)                                             0.10417       0.04167       0.20833       \n",
      "RACCU(Random accuracy unbiased)                                   0.11111       0.0434        0.21007       \n",
      "TN(True negative/correct rejection)                               7             8             4             \n",
      "TNR(Specificity or true negative rate)                            1.0           0.8           0.57143       \n",
      "TON(Test outcome negative)                                        9             9             6             \n",
      "TOP(Test outcome positive)                                        3             3             6             \n",
      "TP(True positive/hit)                                             3             1             3             \n",
      "TPR(Sensitivity, recall, hit rate, or true positive rate)         0.6           0.5           0.6           \n",
      "Y(Youden index)                                                   0.6           0.3           0.17143       \n",
      "dInd(Distance index)                                              0.4           0.53852       0.58624       \n",
      "sInd(Similarity index)                                            0.71716       0.61921       0.58547       \n",
      "\n"
     ]
    }
   ],
   "source": [
    "print(cm)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Matrix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 258,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Predict  L1       L2       L3       \n",
      "Actual\n",
      "L1       3        0        2        \n",
      "\n",
      "L2       0        1        1        \n",
      "\n",
      "L3       0        2        3        \n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "cm.print_matrix()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 259,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': {'L1': 3, 'L2': 0, 'L3': 2},\n",
       " 'L2': {'L1': 0, 'L2': 1, 'L3': 1},\n",
       " 'L3': {'L1': 0, 'L2': 2, 'L3': 3}}"
      ]
     },
     "execution_count": 259,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.matrix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 260,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Predict  L1       ~        \n",
      "Actual\n",
      "L1       3        2        \n",
      "\n",
      "~        0        7        \n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "cm.print_matrix(one_vs_all=True, class_name=\"L1\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 261,
   "metadata": {},
   "outputs": [],
   "source": [
    "sparse_cm = ConfusionMatrix(matrix={1: {1: 0, 2: 2}, 2: {1: 0, 2: 18}})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 262,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Predict  2        \n",
      "Actual\n",
      "1        2        \n",
      "\n",
      "2        18       \n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "sparse_cm.print_matrix(sparse=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Parameters "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. `one_vs_all` : one-vs-all mode flag (type : `bool`, default : `False`)\n",
    "2. `class_name` : target class name for one-vs-all mode (type : `any valid type`, default : `None`)\n",
    "3. `sparse` : sparse mode printing flag (type : `bool`, default : `False`)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  <code>one_vs_all</code> option, new in <span style=\"color:red;\">version 1.4 </span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  <code>matrix()</code> renamed to <code>print_matrix()</code> and <code>matrix</code> return confusion matrix as <code>dict</code> in <span style=\"color:red;\">version 1.5</span></li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  <code>sparse</code> option, new in <span style=\"color:red;\">version 2.6 </span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Normalized matrix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 263,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Predict   L1        L2        L3        \n",
      "Actual\n",
      "L1        0.6       0.0       0.4       \n",
      "\n",
      "L2        0.0       0.5       0.5       \n",
      "\n",
      "L3        0.0       0.4       0.6       \n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "cm.print_normalized_matrix()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 264,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'L1': {'L1': 0.6, 'L2': 0.0, 'L3': 0.4},\n",
       " 'L2': {'L1': 0.0, 'L2': 0.5, 'L3': 0.5},\n",
       " 'L3': {'L1': 0.0, 'L2': 0.4, 'L3': 0.6}}"
      ]
     },
     "execution_count": 264,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.normalized_matrix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 265,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Predict   L1        ~         \n",
      "Actual\n",
      "L1        0.6       0.4       \n",
      "\n",
      "~         0.0       1.0       \n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "cm.print_normalized_matrix(one_vs_all=True, class_name=\"L1\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 266,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Predict   2         \n",
      "Actual\n",
      "1         1.0       \n",
      "\n",
      "2         1.0       \n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "sparse_cm.print_normalized_matrix(sparse=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Parameters "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. `one_vs_all` : one-vs-all mode flag (type : `bool`, default : `False`)\n",
    "2. `class_name` : target class name for one-vs-all mode (type : `any valid type`, default : `None`)\n",
    "3. `sparse` : sparse mode printing flag (type : `bool`, default : `False`)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  <code>one_vs_all</code> option, new in <span style=\"color:red;\">version 1.4 </span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  <code>normalized_matrix()</code> renamed to <code>print_normalized_matrix()</code> and <code>normalized_matrix</code> return normalized confusion matrix as <code>dict</code> in <span style=\"color:red;\">version 1.5</span></li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  <code>sparse</code> option, new in <span style=\"color:red;\">version 2.6 </span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Stat"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 267,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Overall Statistics : \n",
      "\n",
      "95% CI                                                            (0.30439,0.86228)\n",
      "ACC Macro                                                         0.72222\n",
      "ARI                                                               0.09206\n",
      "AUNP                                                              0.68571\n",
      "AUNU                                                              0.67857\n",
      "Bangdiwala B                                                      0.37255\n",
      "Bennett S                                                         0.375\n",
      "CBA                                                               0.47778\n",
      "CSI                                                               0.17778\n",
      "Chi-Squared                                                       6.6\n",
      "Chi-Squared DF                                                    4\n",
      "Conditional Entropy                                               0.97579\n",
      "Cramer V                                                          0.5244\n",
      "Cross Entropy                                                     1.58333\n",
      "F1 Macro                                                          0.56515\n",
      "F1 Micro                                                          0.58333\n",
      "FNR Macro                                                         0.43333\n",
      "FNR Micro                                                         0.41667\n",
      "FPR Macro                                                         0.20952\n",
      "FPR Micro                                                         0.20833\n",
      "Gwet AC1                                                          0.38931\n",
      "Hamming Loss                                                      0.41667\n",
      "Joint Entropy                                                     2.45915\n",
      "KL Divergence                                                     0.09998\n",
      "Kappa                                                             0.35484\n",
      "Kappa 95% CI                                                      (-0.07708,0.78675)\n",
      "Kappa No Prevalence                                               0.16667\n",
      "Kappa Standard Error                                              0.22036\n",
      "Kappa Unbiased                                                    0.34426\n",
      "Krippendorff Alpha                                                0.37158\n",
      "Lambda A                                                          0.42857\n",
      "Lambda B                                                          0.16667\n",
      "Mutual Information                                                0.52421\n",
      "NIR                                                               0.41667\n",
      "NPV Macro                                                         0.77778\n",
      "NPV Micro                                                         0.79167\n",
      "Overall ACC                                                       0.58333\n",
      "Overall CEN                                                       0.46381\n",
      "Overall J                                                         (1.225,0.40833)\n",
      "Overall MCC                                                       0.36667\n",
      "Overall MCEN                                                      0.51894\n",
      "Overall RACC                                                      0.35417\n",
      "Overall RACCU                                                     0.36458\n",
      "P-Value                                                           0.18926\n",
      "PPV Macro                                                         0.61111\n",
      "PPV Micro                                                         0.58333\n",
      "Pearson C                                                         0.59568\n",
      "Phi-Squared                                                       0.55\n",
      "RCI                                                               0.35339\n",
      "RR                                                                4.0\n",
      "Reference Entropy                                                 1.48336\n",
      "Response Entropy                                                  1.5\n",
      "SOA1(Landis & Koch)                                               Fair\n",
      "SOA2(Fleiss)                                                      Poor\n",
      "SOA3(Altman)                                                      Fair\n",
      "SOA4(Cicchetti)                                                   Poor\n",
      "SOA5(Cramer)                                                      Relatively Strong\n",
      "SOA6(Matthews)                                                    Weak\n",
      "SOA7(Lambda A)                                                    Moderate\n",
      "SOA8(Lambda B)                                                    Very Weak\n",
      "SOA9(Krippendorff Alpha)                                          Low\n",
      "SOA10(Pearson C)                                                  Strong\n",
      "Scott PI                                                          0.34426\n",
      "Standard Error                                                    0.14232\n",
      "TNR Macro                                                         0.79048\n",
      "TNR Micro                                                         0.79167\n",
      "TPR Macro                                                         0.56667\n",
      "TPR Micro                                                         0.58333\n",
      "Zero-one Loss                                                     5\n",
      "\n",
      "Class Statistics :\n",
      "\n",
      "Classes                                                           L1            L2            L3            \n",
      "ACC(Accuracy)                                                     0.83333       0.75          0.58333       \n",
      "AGF(Adjusted F-score)                                             0.72859       0.62869       0.61009       \n",
      "AGM(Adjusted geometric mean)                                      0.85764       0.70861       0.58034       \n",
      "AM(Difference between automatic and manual classification)        -2            1             1             \n",
      "AUC(Area under the ROC curve)                                     0.8           0.65          0.58571       \n",
      "AUCI(AUC value interpretation)                                    Very Good     Fair          Poor          \n",
      "AUPR(Area under the PR curve)                                     0.8           0.41667       0.55          \n",
      "BB(Braun-Blanquet similarity)                                     0.6           0.33333       0.5           \n",
      "BCD(Bray-Curtis dissimilarity)                                    0.08333       0.04167       0.04167       \n",
      "BM(Informedness or bookmaker informedness)                        0.6           0.3           0.17143       \n",
      "CEN(Confusion entropy)                                            0.25          0.49658       0.60442       \n",
      "DOR(Diagnostic odds ratio)                                        None          4.0           2.0           \n",
      "DP(Discriminant power)                                            None          0.33193       0.16597       \n",
      "DPI(Discriminant power interpretation)                            None          Poor          Poor          \n",
      "ERR(Error rate)                                                   0.16667       0.25          0.41667       \n",
      "F0.5(F0.5 score)                                                  0.88235       0.35714       0.51724       \n",
      "F1(F1 score - harmonic mean of precision and sensitivity)         0.75          0.4           0.54545       \n",
      "F2(F2 score)                                                      0.65217       0.45455       0.57692       \n",
      "FDR(False discovery rate)                                         0.0           0.66667       0.5           \n",
      "FN(False negative/miss/type 2 error)                              2             1             2             \n",
      "FNR(Miss rate or false negative rate)                             0.4           0.5           0.4           \n",
      "FOR(False omission rate)                                          0.22222       0.11111       0.33333       \n",
      "FP(False positive/type 1 error/false alarm)                       0             2             3             \n",
      "FPR(Fall-out or false positive rate)                              0.0           0.2           0.42857       \n",
      "G(G-measure geometric mean of precision and sensitivity)          0.7746        0.40825       0.54772       \n",
      "GI(Gini index)                                                    0.6           0.3           0.17143       \n",
      "GM(G-mean geometric mean of specificity and sensitivity)          0.7746        0.63246       0.58554       \n",
      "HD(Hamming distance)                                              2             3             5             \n",
      "IBA(Index of balanced accuracy)                                   0.36          0.28          0.35265       \n",
      "ICSI(Individual classification success index)                     0.6           -0.16667      0.1           \n",
      "IS(Information score)                                             1.26303       1.0           0.26303       \n",
      "J(Jaccard index)                                                  0.6           0.25          0.375         \n",
      "LS(Lift score)                                                    2.4           2.0           1.2           \n",
      "MCC(Matthews correlation coefficient)                             0.68313       0.2582        0.16903       \n",
      "MCCI(Matthews correlation coefficient interpretation)             Moderate      Negligible    Negligible    \n",
      "MCEN(Modified confusion entropy)                                  0.26439       0.5           0.6875        \n",
      "MK(Markedness)                                                    0.77778       0.22222       0.16667       \n",
      "N(Condition negative)                                             7             10            7             \n",
      "NLR(Negative likelihood ratio)                                    0.4           0.625         0.7           \n",
      "NLRI(Negative likelihood ratio interpretation)                    Poor          Negligible    Negligible    \n",
      "NPV(Negative predictive value)                                    0.77778       0.88889       0.66667       \n",
      "OC(Overlap coefficient)                                           1.0           0.5           0.6           \n",
      "OOC(Otsuka-Ochiai coefficient)                                    0.7746        0.40825       0.54772       \n",
      "OP(Optimized precision)                                           0.58333       0.51923       0.55894       \n",
      "P(Condition positive or support)                                  5             2             5             \n",
      "PLR(Positive likelihood ratio)                                    None          2.5           1.4           \n",
      "PLRI(Positive likelihood ratio interpretation)                    None          Poor          Poor          \n",
      "POP(Population)                                                   12            12            12            \n",
      "PPV(Precision or positive predictive value)                       1.0           0.33333       0.5           \n",
      "PRE(Prevalence)                                                   0.41667       0.16667       0.41667       \n",
      "Q(Yule Q - coefficient of colligation)                            None          0.6           0.33333       \n",
      "QI(Yule Q interpretation)                                         None          Moderate      Weak          \n",
      "RACC(Random accuracy)                                             0.10417       0.04167       0.20833       \n",
      "RACCU(Random accuracy unbiased)                                   0.11111       0.0434        0.21007       \n",
      "TN(True negative/correct rejection)                               7             8             4             \n",
      "TNR(Specificity or true negative rate)                            1.0           0.8           0.57143       \n",
      "TON(Test outcome negative)                                        9             9             6             \n",
      "TOP(Test outcome positive)                                        3             3             6             \n",
      "TP(True positive/hit)                                             3             1             3             \n",
      "TPR(Sensitivity, recall, hit rate, or true positive rate)         0.6           0.5           0.6           \n",
      "Y(Youden index)                                                   0.6           0.3           0.17143       \n",
      "dInd(Distance index)                                              0.4           0.53852       0.58624       \n",
      "sInd(Similarity index)                                            0.71716       0.61921       0.58547       \n",
      "\n"
     ]
    }
   ],
   "source": [
    "cm.stat()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 268,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Overall Statistics : \n",
      "\n",
      "Kappa                                                             0.35484\n",
      "\n",
      "Class Statistics :\n",
      "\n",
      "Classes                                                           L1            L2            L3            \n",
      "ACC(Accuracy)                                                     0.83333       0.75          0.58333       \n",
      "AUC(Area under the ROC curve)                                     0.8           0.65          0.58571       \n",
      "TPR(Sensitivity, recall, hit rate, or true positive rate)         0.6           0.5           0.6           \n",
      "\n"
     ]
    }
   ],
   "source": [
    "cm.stat(overall_param=[\"Kappa\"], class_param=[\"ACC\", \"AUC\", \"TPR\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 269,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Overall Statistics : \n",
      "\n",
      "Kappa                                                             0.35484\n",
      "\n",
      "Class Statistics :\n",
      "\n",
      "Classes                                                           L1            L3            \n",
      "ACC(Accuracy)                                                     0.83333       0.58333       \n",
      "AUC(Area under the ROC curve)                                     0.8           0.58571       \n",
      "TPR(Sensitivity, recall, hit rate, or true positive rate)         0.6           0.6           \n",
      "\n"
     ]
    }
   ],
   "source": [
    "cm.stat(overall_param=[\"Kappa\"], class_param=[\"ACC\", \"AUC\", \"TPR\"], class_name=[\"L1\", \"L3\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 270,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Overall Statistics : \n",
      "\n",
      "ACC Macro                                                         0.72222\n",
      "F1 Macro                                                          0.56515\n",
      "FPR Macro                                                         0.20952\n",
      "Kappa                                                             0.35484\n",
      "NPV Macro                                                         0.77778\n",
      "Overall ACC                                                       0.58333\n",
      "PPV Macro                                                         0.61111\n",
      "SOA1(Landis & Koch)                                               Fair\n",
      "TPR Macro                                                         0.56667\n",
      "Zero-one Loss                                                     5\n",
      "\n",
      "Class Statistics :\n",
      "\n",
      "Classes                                                           L1            L2            L3            \n",
      "ACC(Accuracy)                                                     0.83333       0.75          0.58333       \n",
      "AUC(Area under the ROC curve)                                     0.8           0.65          0.58571       \n",
      "AUCI(AUC value interpretation)                                    Very Good     Fair          Poor          \n",
      "F1(F1 score - harmonic mean of precision and sensitivity)         0.75          0.4           0.54545       \n",
      "FN(False negative/miss/type 2 error)                              2             1             2             \n",
      "FP(False positive/type 1 error/false alarm)                       0             2             3             \n",
      "FPR(Fall-out or false positive rate)                              0.0           0.2           0.42857       \n",
      "N(Condition negative)                                             7             10            7             \n",
      "P(Condition positive or support)                                  5             2             5             \n",
      "POP(Population)                                                   12            12            12            \n",
      "PPV(Precision or positive predictive value)                       1.0           0.33333       0.5           \n",
      "TN(True negative/correct rejection)                               7             8             4             \n",
      "TON(Test outcome negative)                                        9             9             6             \n",
      "TOP(Test outcome positive)                                        3             3             6             \n",
      "TP(True positive/hit)                                             3             1             3             \n",
      "TPR(Sensitivity, recall, hit rate, or true positive rate)         0.6           0.5           0.6           \n",
      "\n"
     ]
    }
   ],
   "source": [
    "cm.stat(summary=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Parameters "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. `overall_param` : overall parameters list for print (type : `list`, default : `None`)\n",
    "2. `class_param` : class parameters list for print (type : `list`, default : `None`)\n",
    "3. `class_name` : class name (a subset of classes names) (type : `list`, default : `None`)\n",
    "4. `summary` : summary mode flag (type : `bool`, default : `False`)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  <code>cm.params()</code> in prev versions (0.2 >) </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  <code>overall_param</code> & <code>class_param</code> , new in <span style=\"color:red;\">version 1.6 </span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  <code>class_name</code> , new in <span style=\"color:red;\">version 1.7 </span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  <code>summary</code> , new in <span style=\"color:red;\">version 2.4 </span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Compare report"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 271,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Best : cm2\n",
      "\n",
      "Rank  Name   Class-Score       Overall-Score\n",
      "1     cm2    0.50278           0.58095\n",
      "2     cm3    0.33611           0.52857\n",
      "\n"
     ]
    }
   ],
   "source": [
    "cp.print_report()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 272,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Best : cm2\n",
      "\n",
      "Rank  Name   Class-Score       Overall-Score\n",
      "1     cm2    0.50278           0.58095\n",
      "2     cm3    0.33611           0.52857\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print(cp)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Save"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 273,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "if \"Document_files\" not in os.listdir():\n",
    "    os.mkdir(\"Document_files\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### .pycm file"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 274,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Message': 'D:\\\\For Asus Laptop\\\\projects\\\\pycm\\\\Document\\\\Document_files\\\\cm1.pycm',\n",
       " 'Status': True}"
      ]
     },
     "execution_count": 274,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.save_stat(os.path.join(\"Document_files\", \"cm1\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"Document_files\\cm1.pycm\">Open File</a>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 275,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Message': 'D:\\\\For Asus Laptop\\\\projects\\\\pycm\\\\Document\\\\Document_files\\\\cm1_filtered.pycm',\n",
       " 'Status': True}"
      ]
     },
     "execution_count": 275,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.save_stat(\n",
    "    os.path.join(\"Document_files\", \"cm1_filtered\"),\n",
    "    overall_param=[\"Kappa\"],\n",
    "    class_param=[\"ACC\", \"AUC\", \"TPR\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"Document_files\\cm1_filtered.pycm\">Open File</a>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 276,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Message': 'D:\\\\For Asus Laptop\\\\projects\\\\pycm\\\\Document\\\\Document_files\\\\cm1_filtered2.pycm',\n",
       " 'Status': True}"
      ]
     },
     "execution_count": 276,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.save_stat(\n",
    "    os.path.join(\"Document_files\", \"cm1_filtered2\"),\n",
    "    overall_param=[\"Kappa\"],\n",
    "    class_param=[\"ACC\", \"AUC\", \"TPR\"],\n",
    "    class_name=[\"L1\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"Document_files\\cm1_filtered2.pycm\">Open File</a>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 277,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Message': 'D:\\\\For Asus Laptop\\\\projects\\\\pycm\\\\Document\\\\Document_files\\\\cm1_summary.pycm',\n",
       " 'Status': True}"
      ]
     },
     "execution_count": 277,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.save_stat(\n",
    "    os.path.join(\"Document_files\", \"cm1_summary\"),\n",
    "    summary=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"Document_files\\cm1_summary.pycm\">Open File</a>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 278,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Message': 'D:\\\\For Asus Laptop\\\\projects\\\\pycm\\\\Document\\\\Document_files\\\\sparse_cm.pycm',\n",
       " 'Status': True}"
      ]
     },
     "execution_count": 278,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sparse_cm.save_stat(\n",
    "    os.path.join(\"Document_files\", \"sparse_cm\"),\n",
    "    summary=True,\n",
    "    sparse=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"Document_files\\sparse_cm.pycm\">Open File</a>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 279,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Message': \"[Errno 2] No such file or directory: 'cm1asdasd/.pycm'\",\n",
       " 'Status': False}"
      ]
     },
     "execution_count": 279,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.save_stat(\"cm1asdasd/\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Parameters "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. `name` : filename (type : `str`)\n",
    "2. `address` : flag for address return (type : `bool`, default : `True`)\n",
    "3. `overall_param` : overall parameters list for save (type : `list`, default : `None`)\n",
    "4. `class_param` : class parameters list for save (type : `list`, default : `None`)\n",
    "5. `class_name` : class name (subset of classes names) (type : `list`, default : `None`)\n",
    "6. `summary` : summary mode flag (type : `bool`, default : `False`)\n",
    "7. `sparse` : sparse mode printing flag (type : `bool`, default : `False`)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.4</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  <code>overall_param</code> & <code>class_param</code> , new in <span style=\"color:red;\">version 1.6 </span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  <code>class_name</code> , new in <span style=\"color:red;\">version 1.7 </span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  <code>summary</code> , new in <span style=\"color:red;\">version 2.4 </span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  <code>sparse</code>, new in <span style=\"color:red;\">version 2.6 </span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### HTML"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 280,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Message': 'D:\\\\For Asus Laptop\\\\projects\\\\pycm\\\\Document\\\\Document_files\\\\cm1.html',\n",
       " 'Status': True}"
      ]
     },
     "execution_count": 280,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.save_html(os.path.join(\"Document_files\", \"cm1\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"Document_files\\cm1.html\">Open File</a>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 281,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Message': 'D:\\\\For Asus Laptop\\\\projects\\\\pycm\\\\Document\\\\Document_files\\\\cm1_filtered.html',\n",
       " 'Status': True}"
      ]
     },
     "execution_count": 281,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.save_html(\n",
    "    os.path.join(\"Document_files\", \"cm1_filtered\"),\n",
    "    overall_param=[\"Kappa\"],\n",
    "    class_param=[\"ACC\", \"AUC\", \"TPR\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"Document_files\\cm1_filtered.html\">Open File</a>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 282,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Message': 'D:\\\\For Asus Laptop\\\\projects\\\\pycm\\\\Document\\\\Document_files\\\\cm1_filtered2.html',\n",
       " 'Status': True}"
      ]
     },
     "execution_count": 282,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.save_html(\n",
    "    os.path.join(\"Document_files\", \"cm1_filtered2\"),\n",
    "    overall_param=[\"Kappa\"],\n",
    "    class_param=[\"ACC\", \"AUC\", \"TPR\"],\n",
    "    class_name=[\"L1\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"Document_files\\cm1_filtered2.html\">Open File</a>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 283,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Message': 'D:\\\\For Asus Laptop\\\\projects\\\\pycm\\\\Document\\\\Document_files\\\\cm1_colored.html',\n",
       " 'Status': True}"
      ]
     },
     "execution_count": 283,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.save_html(\n",
    "    os.path.join(\"Document_files\", \"cm1_colored\"),\n",
    "    color=(255, 204, 255))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"Document_files\\cm1_colored.html\">Open File</a>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 284,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Message': 'D:\\\\For Asus Laptop\\\\projects\\\\pycm\\\\Document\\\\Document_files\\\\cm1_colored2.html',\n",
       " 'Status': True}"
      ]
     },
     "execution_count": 284,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.save_html(\n",
    "    os.path.join(\"Document_files\", \"cm1_colored2\"),\n",
    "    color=\"Crimson\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"Document_files\\cm1_colored2.html\">Open File</a>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 285,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Message': 'D:\\\\For Asus Laptop\\\\projects\\\\pycm\\\\Document\\\\Document_files\\\\cm1_normalized.html',\n",
       " 'Status': True}"
      ]
     },
     "execution_count": 285,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.save_html(\n",
    "    os.path.join(\"Document_files\", \"cm1_normalized\"),\n",
    "    color=\"Crimson\",\n",
    "    normalize=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"Document_files\\cm1_normalized.html\">Open File</a>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 286,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Message': 'D:\\\\For Asus Laptop\\\\projects\\\\pycm\\\\Document\\\\Document_files\\\\cm1_summary.html',\n",
       " 'Status': True}"
      ]
     },
     "execution_count": 286,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.save_html(\n",
    "    os.path.join(\"Document_files\", \"cm1_summary\"),\n",
    "    summary=True,\n",
    "    normalize=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"Document_files\\cm1_summary.html\">Open File</a>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 287,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Message': \"[Errno 2] No such file or directory: 'cm1asdasd/.html'\",\n",
       " 'Status': False}"
      ]
     },
     "execution_count": 287,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.save_html(\"cm1asdasd/\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Parameters "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. `name` : filename (type : `str`)\n",
    "2. `address` : flag for address return (type : `bool`, default : `True`)\n",
    "3. `overall_param` : overall parameters list for save (type : `list`, default : `None`)\n",
    "4. `class_param` : class parameters list for save (type : `list`, default : `None`)\n",
    "5. `class_name` : class name (subset of classes names) (type : `list`, default : `None`)\n",
    "6. `color` : matrix color in RGB as (R, G, B) (type : `tuple`/`str`, default : `(0,0,0)`), support <a href=\"https://en.wikipedia.org/wiki/X11_color_names\">X11 color names</a>\n",
    "7. `normalize` : save normalize matrix flag (type : `bool`, default : `False`)\n",
    "8. `summary` : summary mode flag (type : `bool`, default : `False`)\n",
    "9. `alt_link` : alternative link for document flag (type : `bool`, default : `False`)\n",
    "10. `shortener` : class name shortener flag (type : `bool`, default : `True`)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.5</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  <code>overall_param</code> & <code>class_param</code> , new in <span style=\"color:red;\">version 1.6 </span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  <code>class_name</code> , new in <span style=\"color:red;\">version 1.7 </span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> : <code>color</code>, new in <span style=\"color:red;\">version 1.8 </span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  <code>normalize</code>, new in <span style=\"color:red;\">version 2.0 </span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> : <code>summary</code> and <code>alt_link</code> , new in <span style=\"color:red;\">version 2.4 </span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> : <code>shortener</code>, new in <span style=\"color:red;\">version 3.2 </span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  If PyCM website is not available, set <code>alt_link=True</code></li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### CSV"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 288,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Message': 'D:\\\\For Asus Laptop\\\\projects\\\\pycm\\\\Document\\\\Document_files\\\\cm1.csv',\n",
       " 'Status': True}"
      ]
     },
     "execution_count": 288,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.save_csv(os.path.join(\"Document_files\", \"cm1\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"Document_files\\cm1.csv\">Open Stat File</a>\n",
    "<br/>\n",
    "<a href=\"Document_files\\cm1_matrix.csv\">Open Matrix File</a>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 289,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Message': 'D:\\\\For Asus Laptop\\\\projects\\\\pycm\\\\Document\\\\Document_files\\\\cm1_filtered.csv',\n",
       " 'Status': True}"
      ]
     },
     "execution_count": 289,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.save_csv(\n",
    "    os.path.join(\"Document_files\", \"cm1_filtered\"),\n",
    "    class_param=[\"ACC\", \"AUC\", \"TPR\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"Document_files\\cm1_filtered.csv\">Open Stat File</a>\n",
    "<br/>\n",
    "<a href=\"Document_files\\cm1_filtered_matrix.csv\">Open Matrix File</a>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 290,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Message': 'D:\\\\For Asus Laptop\\\\projects\\\\pycm\\\\Document\\\\Document_files\\\\cm1_filtered2.csv',\n",
       " 'Status': True}"
      ]
     },
     "execution_count": 290,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.save_csv(\n",
    "    os.path.join(\"Document_files\", \"cm1_filtered2\"),\n",
    "    class_param=[\"ACC\", \"AUC\", \"TPR\"],\n",
    "    normalize=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"Document_files\\cm1_filtered2.csv\">Open Stat File</a>\n",
    "<br/>\n",
    "<a href=\"Document_files\\cm1_filtered2_matrix.csv\">Open Matrix File</a>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 291,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Message': 'D:\\\\For Asus Laptop\\\\projects\\\\pycm\\\\Document\\\\Document_files\\\\cm1_filtered3.csv',\n",
       " 'Status': True}"
      ]
     },
     "execution_count": 291,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.save_csv(\n",
    "    os.path.join(\"Document_files\", \"cm1_filtered3\"),\n",
    "    class_param=[\"ACC\", \"AUC\", \"TPR\"],\n",
    "    class_name=[\"L1\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"Document_files\\cm1_filtered3.csv\">Open Stat File</a>\n",
    "<br/>\n",
    "<a href=\"Document_files\\cm1_filtered3_matrix.csv\">Open Matrix File</a>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 292,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Message': 'D:\\\\For Asus Laptop\\\\projects\\\\pycm\\\\Document\\\\Document_files\\\\cm1_header.csv',\n",
       " 'Status': True}"
      ]
     },
     "execution_count": 292,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.save_csv(\n",
    "    os.path.join(\"Document_files\", \"cm1_header\"),\n",
    "    header=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"Document_files\\cm1_header.csv\">Open Stat File</a>\n",
    "<br/>\n",
    "<a href=\"Document_files\\cm1_header_matrix.csv\">Open Matrix File</a>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 293,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Message': 'D:\\\\For Asus Laptop\\\\projects\\\\pycm\\\\Document\\\\Document_files\\\\cm1_summary.csv',\n",
       " 'Status': True}"
      ]
     },
     "execution_count": 293,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.save_csv(\n",
    "    os.path.join(\"Document_files\", \"cm1_summary\"),\n",
    "    summary=True,\n",
    "    matrix_save=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"Document_files\\cm1_summary.csv\">Open Stat File</a>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 294,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Message': \"[Errno 2] No such file or directory: 'cm1asdasd/.csv'\",\n",
       " 'Status': False}"
      ]
     },
     "execution_count": 294,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.save_csv(\"cm1asdasd/\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Parameters "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. `name` : filename (type : `str`)\n",
    "2. `address` : flag for address return (type : `bool`, default : `True`)\n",
    "4. `class_param` : class parameters list for save (type : `list`, default : `None`)\n",
    "5. `class_name` : class name (subset of classes names) (type : `list`, default : `None`)\n",
    "6. `matrix_save` : save matrix flag (type : `bool`, default : `True`)\n",
    "7. `normalize` : save normalize matrix flag (type : `bool`, default : `False`)\n",
    "8. `summary` : summary mode flag (type : `bool`, default : `False`)\n",
    "9. `header` : add headers to .csv file (type : `bool`, default : `False`)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.6</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  <code>class_param</code> , new in <span style=\"color:red;\">version 1.6 </span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> : <code>class_name</code> , new in <span style=\"color:red;\">version 1.7 </span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> : <code>matrix_save</code> and <code>normalize</code>, new in <span style=\"color:red;\">version 1.9 </span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> : <code>summary</code> , new in <span style=\"color:red;\">version 2.4 </span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> : <code>header</code> , new in <span style=\"color:red;\">version 2.6 </span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### OBJ"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 295,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Message': 'D:\\\\For Asus Laptop\\\\projects\\\\pycm\\\\Document\\\\Document_files\\\\cm1.obj',\n",
       " 'Status': True}"
      ]
     },
     "execution_count": 295,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.save_obj(os.path.join(\"Document_files\", \"cm1\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"Document_files\\cm1.obj\">Open File</a>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 296,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Message': 'D:\\\\For Asus Laptop\\\\projects\\\\pycm\\\\Document\\\\Document_files\\\\cm1_stat.obj',\n",
       " 'Status': True}"
      ]
     },
     "execution_count": 296,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.save_obj(\n",
    "    os.path.join(\"Document_files\", \"cm1_stat\"),\n",
    "    save_stat=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"Document_files\\cm1_stat.obj\">Open File</a>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 297,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Message': 'D:\\\\For Asus Laptop\\\\projects\\\\pycm\\\\Document\\\\Document_files\\\\cm1_no_vectors.obj',\n",
       " 'Status': True}"
      ]
     },
     "execution_count": 297,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.save_obj(\n",
    "    os.path.join(\"Document_files\", \"cm1_no_vectors\"),\n",
    "    save_vector=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"Document_files\\cm1_no_vectors.obj\">Open File</a>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 298,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Message': \"[Errno 2] No such file or directory: 'cm1asdasd/.obj'\",\n",
       " 'Status': False}"
      ]
     },
     "execution_count": 298,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cm.save_obj(\"cm1asdasd/\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Parameters "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. `name` : filename (type : `str`)\n",
    "2. `address` : flag for address return (type : `bool`, default : `True`)\n",
    "3. `save_stat` : save statistics flag (type : `bool`, default : `False`)\n",
    "4. `save_vector` : save vectors flag (type : `bool`, default : `True`)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 0.9.5</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> : <code>save_vector</code> and <code>save_stat</code>, new in <span style=\"color:red;\">version 2.3 </span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  For more information visit <a href=\"#Example-4-(File)\">Example 4</a></li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### comp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 299,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Message': 'D:\\\\For Asus Laptop\\\\projects\\\\pycm\\\\Document\\\\Document_files\\\\cp.comp',\n",
       " 'Status': True}"
      ]
     },
     "execution_count": 299,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cp.save_report(os.path.join(\"Document_files\", \"cp\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"Document_files\\cp.comp\">Open File</a>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 300,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Message': \"[Errno 2] No such file or directory: 'cm1asdasd/.comp'\",\n",
       " 'Status': False}"
      ]
     },
     "execution_count": 300,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cp.save_report(\"cm1asdasd/\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Parameters "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. `name` : filename (type : `str`)\n",
    "2. `address` : flag for address return (type : `bool`, default : `True`)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  new in <span style=\"color:red;\">version 2.0</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Input errors"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 301,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Input vectors must be provided as a list or a NumPy array.\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    cm2 = ConfusionMatrix(y_actu, 2)\n",
    "except pycmVectorError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 302,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Input vectors must have the same length.\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    cm3 = ConfusionMatrix(y_actu, [1, 2, 3])\n",
    "except pycmVectorError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 303,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Input vectors must not be empty.\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    cm_4 = ConfusionMatrix([], [])\n",
    "except pycmVectorError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 304,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Input vectors must have the same length.\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    cm_5 = ConfusionMatrix([1, 1, 1, ], [1, 1, 1, 1])\n",
    "except pycmVectorError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 305,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Invalid input confusion matrix format.\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    cm3 = ConfusionMatrix(matrix={})\n",
    "except pycmMatrixError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 306,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "All input matrix classes must be of the same type.\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    cm_4 = ConfusionMatrix(matrix={1: {1: 2, \"1\": 2}, \"1\": {1: 2, \"1\": 3}})\n",
    "except pycmMatrixError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 307,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The number of classes must be at least 2.\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    cm_5 = ConfusionMatrix(matrix={1: {1: 2}})\n",
    "except pycmMatrixError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 308,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Input must be provided as a dictionary.\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    cp = Compare([cm2, cm3])\n",
    "except pycmCompareError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 309,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "All ConfusionMatrix objects must have the same domain (same sample size and number of classes).\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    cp = Compare({\"cm1\": cm, \"cm2\": cm2})\n",
    "except pycmCompareError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 310,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Input must be a dictionary containing pycm.ConfusionMatrix objects.\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    cp = Compare({\"cm1\": [], \"cm2\": cm2})\n",
    "except pycmCompareError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 311,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "At least 2 confusion matrices are required for comparison.\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    cp = Compare({\"cm2\": cm2})\n",
    "except pycmCompareError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 312,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "`class_weight` must be a dictionary and specified for all classes.\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    cp = Compare(\n",
    "        {\"cm1\": cm2, \"cm2\": cm3},\n",
    "        by_class=True,\n",
    "        class_weight={1: 2, 2: 0})\n",
    "except pycmCompareError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 313,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "`class_benchmark_weight` must be a dictionary and specified for all class benchmarks.\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    cp = Compare(\n",
    "        {\"cm1\":cm2, \"cm2\":cm3},\n",
    "        class_benchmark_weight={1: 2, 2: 0})\n",
    "except pycmCompareError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 314,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "`overall_benchmark_weight` must be a dictionary and specified for all overall benchmarks.\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    cp = Compare(\n",
    "        {\"cm1\": cm2, \"cm2\": cm3},\n",
    "        overall_benchmark_weight={1: 2, 2: 0})\n",
    "except pycmCompareError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 315,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Confidence interval calculation for this parameter is not supported in this version of pycm.\n",
      " Supported parameters are: TPR, TNR, PPV, NPV, ACC, PLR, NLR, FPR, FNR, AUC, PRE, Kappa, Overall ACC\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    cm.CI(\"MCC\")\n",
    "except pycmCIError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 316,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Input must be provided as a string.\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    cm.CI(2)\n",
    "except pycmCIError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 317,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Invalid parameter!\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    cm.average(\"AXY\")\n",
    "except pycmAverageError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 318,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Invalid parameter!\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    cm.weighted_average(\"AXY\")\n",
    "except pycmAverageError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 319,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "`weight` must be a dictionary and specified for all classes."
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    cm.weighted_average(\"AUC\", weight={1: 22})\n",
    "except pycmAverageError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 320,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "This option is only available in vector mode."
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    cm.position()\n",
    "except pycmVectorError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 321,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Input must be an instance of pycm.ConfusionMatrix.\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    cm.combine(2)\n",
    "except pycmMatrixError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 322,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The number of classes must be at least 2.\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    cm6 = ConfusionMatrix([1, 1, 1, 1], [1, 1, 1, 1], classes=[])\n",
    "except pycmMatrixError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 323,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "`classes` must contain unique labels with no duplicates.\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    cm7 = ConfusionMatrix([1, 1, 1, 1], [1, 1, 1, 1], classes=[1, 1, 2])\n",
    "except pycmVectorError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 324,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Input vectors must be provided as a list or a NumPy array.\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    crv = ROCCurve([1, 2, 2, 1], {1, 2, 2, 1}, classes=[1, 2])\n",
    "except pycmCurveError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 325,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Input vectors must have the same length.\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    crv = ROCCurve([1, 2, 2, 1],[[0.1, 0.9]], classes=[1, 2])\n",
    "except pycmCurveError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 326,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The sum of the probability values must equal 1.\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    crv = ROCCurve(\n",
    "        [1, 2, 2, 1],\n",
    "        [[0.1, 0.9], [0.1, 0.9], [0.1, 0.9], [0.2, 0.9]],\n",
    "        classes=[1, 2])\n",
    "except pycmCurveError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 327,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "`classes` must be provided as a list.\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    crv = ROCCurve(\n",
    "        [1, 2, 2, 1],\n",
    "        [[0.1, 0.9], [0.1, 0.9], [0.1, 0.9], [0.1, 0.9]],\n",
    "        classes={1, 2})\n",
    "except pycmCurveError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 328,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "`classes` does not match the actual vector.\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    crv = ROCCurve(\n",
    "        [1, 2, 2, 1],\n",
    "        [[0.1, 0.9], [0.1, 0.9], [0.1, 0.9], [0.1, 0.9]],\n",
    "        classes=[1, 2, 3])\n",
    "except pycmCurveError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 329,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The number of classes must be at least 2.\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    crv = ROCCurve(\n",
    "        [1, 1, 1, 1],\n",
    "        [[0.1, 0.9], [0.1, 0.9], [0.1, 0.9], [0.1, 0.9]],\n",
    "        classes=[1])\n",
    "except pycmCurveError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 330,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Probability vector elements must be numeric.\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    crv = ROCCurve(\n",
    "        [1, 2, 2, 1],\n",
    "        [[0.1, 0.9], [0.1, 0.9], [0.1, 0.9], [0.2, \"s\"]],\n",
    "        classes=[1, 2])\n",
    "except pycmCurveError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 331,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "`thresholds` must be provided as a list or a NumPy array.\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    crv = ROCCurve(\n",
    "        [1, 2, 2, 1],\n",
    "        [[0.1, 0.9],[0.1, 0.9], [0.1, 0.9], [0.2, 0.8]],\n",
    "        classes=[1, 2],\n",
    "        thresholds={1, 2})\n",
    "except pycmCurveError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 332,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The number of thresholds must be at least 2.\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    crv = ROCCurve(\n",
    "        [1, 2, 2, 1],\n",
    "        [[0.1, 0.9], [0.1, 0.9], [0.1, 0.9], [0.2, 0.8]],\n",
    "        classes=[1, 2],\n",
    "        thresholds=[0.1])\n",
    "except pycmCurveError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 333,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "`thresholds` must contain only numeric values.\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    crv = ROCCurve(\n",
    "        [1, 2, 2, 1],\n",
    "        [[0.1, 0.9], [0.1, 0.9], [0.1, 0.9], [0.2, 0.8]],\n",
    "        classes=[1, 2],\n",
    "        thresholds=[0.1, \"q\"])\n",
    "except pycmCurveError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 334,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "`classes` must contain unique labels with no duplicates.\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    crv = ROCCurve(\n",
    "        [1, 2, 2, 1],\n",
    "        [[0.1, 0.9], [0.1, 0.9], [0.1, 0.9], [0.2, 0.8]],\n",
    "        classes=[1, 1, 2])\n",
    "except pycmCurveError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 335,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "All elements of the probability vector must have the same length and match the number of classes.\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    crv = ROCCurve(\n",
    "        [1, 2, 2, 1],\n",
    "        [[0.1, 0.9], [0.1, 0.9], [0.1, 0.8, 0.1], [0.2, 0.8]],\n",
    "        classes=[1, 2])\n",
    "except pycmCurveError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 336,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The integral method must be either 'trapezoidal' or 'midpoint'.\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    crv = ROCCurve(\n",
    "        actual_vector=numpy.array([1, 1, 2, 2]),\n",
    "        probs=numpy.array([[0.1, 0.9], [0.4, 0.6], [0.35, 0.65], [0.8, 0.2]]),\n",
    "        classes=[2, 1])\n",
    "    crv.area(method=\"trpz\")\n",
    "except pycmCurveError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 337,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Failed to extract classes from input. Input vectors should be a list of sets with unified types.\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    mlcm = MultiLabelCM([[0, 1], [1, 1]], [[1, 0], [1, 0]])\n",
    "except pycmVectorError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 338,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The specified class name is not among the confusion matrix's classes.\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    mlcm = MultiLabelCM([{'dog'}, {'cat', 'dog'}], [{'cat'}, {'cat'}])\n",
    "    mlcm.get_cm_by_class(1)\n",
    "except pycmMultiLabelError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 339,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Index is out of range for the given vector.\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    mlcm.get_cm_by_sample(2)\n",
    "except pycmMultiLabelError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 340,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Input vectors must be provided as a list or a NumPy array."
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    mlcm = MultiLabelCM(2, [{1, 0}, {1, 0}])\n",
    "except pycmVectorError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 341,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Input vectors must have the same length.\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    mlcm = MultiLabelCM([{1, 0}, {1, 0}, {1,1}], [{1, 0}, {1, 0}])\n",
    "except pycmVectorError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 342,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Input vectors must not be empty.\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    mlcm = MultiLabelCM([], [])\n",
    "except pycmVectorError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 343,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "`classes` must contain unique labels with no duplicates.\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    mlcm = MultiLabelCM([{1, 0}, {1, 0}], [{1, 0}, {1, 0}], classes=[1,0,1])\n",
    "except pycmVectorError as e:\n",
    "    print(str(e))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<ul>\n",
    "    <li><span style=\"color:red;\">Notice </span> :  updated in <span style=\"color:red;\">version 4.0</span> </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Examples"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "### Example-1 (Comparison of three different classifiers)\t\n",
    "\n",
    "- [Jupyter Notebook](https://nbviewer.jupyter.org/github/sepandhaghighi/pycm/blob/master/Document/Example1.ipynb)\n",
    "- [HTML](http://www.pycm.io/doc/Example1.html)\n",
    "\n",
    "### Example-2 (How to plot via matplotlib)\n",
    "\n",
    "- [Jupyter Notebook](https://nbviewer.jupyter.org/github/sepandhaghighi/pycm/blob/master/Document/Example2.ipynb)\n",
    "- [HTML](http://www.pycm.io/doc/Example2.html)\n",
    "\n",
    "### Example-3 (Activation threshold)\n",
    "\n",
    "- [Jupyter Notebook](https://nbviewer.jupyter.org/github/sepandhaghighi/pycm/blob/master/Document/Example3.ipynb)\n",
    "- [HTML](http://www.pycm.io/doc/Example3.html)\n",
    "\n",
    "### Example-4 (File)\n",
    "\n",
    "- [Jupyter Notebook](https://nbviewer.jupyter.org/github/sepandhaghighi/pycm/blob/master/Document/Example4.ipynb)\n",
    "- [HTML](http://www.pycm.io/doc/Example4.html)\n",
    "\n",
    "### Example-5 (Sample weights)\n",
    "\n",
    "- [Jupyter Notebook](https://nbviewer.jupyter.org/github/sepandhaghighi/pycm/blob/master/Document/Example5.ipynb)\n",
    "- [HTML](http://www.pycm.io/doc/Example5.html)\n",
    "\n",
    "### Example-6 (Unbalanced data)\n",
    "\n",
    "- [Jupyter Notebook](https://nbviewer.jupyter.org/github/sepandhaghighi/pycm/blob/master/Document/Example6.ipynb)\n",
    "- [HTML](http://www.pycm.io/doc/Example6.html)\n",
    "\n",
    "### Example-7 (How to plot via seaborn+pandas)\n",
    "\n",
    "- [Jupyter Notebook](https://nbviewer.jupyter.org/github/sepandhaghighi/pycm/blob/master/Document/Example7.ipynb)\n",
    "- [HTML](http://www.pycm.io/doc/Example7.html)\n",
    "\n",
    "### Example-8 (Confidence interval)\n",
    "\n",
    "- [Jupyter Notebook](https://nbviewer.jupyter.org/github/sepandhaghighi/pycm/blob/master/Document/Example8.ipynb)\n",
    "- [HTML](http://www.pycm.io/doc/Example8.html)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Cite"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If you use PyCM in your research, we would appreciate citations to the following paper :"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<pre>Haghighi, S., Jasemi, M., Hessabi, S. and Zolanvari, A. (2018). PyCM: Multiclass confusion matrix library in Python.<br/>Journal of Open Source Software, 3(25), p.729.</pre>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<pre>\n",
    "@article{Haghighi2018,\n",
    "  doi = {10.21105/joss.00729},\n",
    "  url = {https://doi.org/10.21105/joss.00729},\n",
    "  year  = {2018},\n",
    "  month = {may},\n",
    "  publisher = {The Open Journal},\n",
    "  volume = {3},\n",
    "  number = {25},\n",
    "  pages = {729},\n",
    "  author = {Sepand Haghighi and Masoomeh Jasemi and Shaahin Hessabi and Alireza Zolanvari},\n",
    "  title = {{PyCM}: Multiclass confusion matrix library in Python},\n",
    "  journal = {Journal of Open Source Software}\n",
    "}\n",
    "</pre>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Download <a href=\"http://www.pycm.io/PYCM.bib\">PyCM.bib</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## References"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<blockquote id=\"ref1\">1- J. R. Landis and G. G. Koch, \"The measurement of observer agreement for categorical data,\" <i>biometrics</i>, pp. 159-174, 1977.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref2\">2- D. M. Powers, \"Evaluation: from precision, recall and F-measure to ROC, informedness, markedness and correlation,\" <i>arXiv preprint arXiv:2010.16061</i>, 2020.</blockquote>\n",
    "\n",
    "\n",
    "<blockquote id=\"ref3\">3- C. Sammut and G. I. Webb, <i>Encyclopedia of machine learning</i>. Springer Science & Business Media, 2011.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref4\">4- J. L. Fleiss, \"Measuring nominal scale agreement among many raters,\" <i>Psychological bulletin</i>, vol. 76, no. 5, p. 378, 1971.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref5\">5- D. G. Altman, <i>Practical statistics for medical research</i>. CRC press, 1990.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref6\">6- K. L. Gwet, \"Computing inter-rater reliability and its variance in the presence of high agreement,\" <i>British Journal of Mathematical and Statistical Psychology</i>, vol. 61, no. 1, pp. 29-48, 2008.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref7\">7- W. A. Scott, \"Reliability of content analysis: The case of nominal scale coding,\" <i>Public opinion quarterly</i>, pp. 321-325, 1955.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref8\">8- E. M. Bennett, R. Alpert, and A. Goldstein, \"Communications through limited-response questioning,\" <i>Public Opinion Quarterly</i>, vol. 18, no. 3, pp. 303-308, 1954.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref9\">9- D. V. Cicchetti, \"Guidelines, criteria, and rules of thumb for evaluating normed and standardized assessment instruments in psychology,\" <i>Psychological assessment</i>, vol. 6, no. 4, p. 284, 1994.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref10\">10- R. B. Davies, \"Algorithm AS 155: The distribution of a linear combination of χ2 random variables,\" <i>Applied Statistics</i>, pp. 323-333, 1980.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref11\">11- S. Kullback and R. A. Leibler, \"On information and sufficiency,\" <i>The annals of mathematical statistics</i>, vol. 22, no. 1, pp. 79-86, 1951.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref12\">12- L. A. Goodman and W. H. Kruskal, \"Measures of association for cross classifications, IV: Simplification of asymptotic variances,\" <i>Journal of the American Statistical Association</i>, vol. 67, no. 338, pp. 415-421, 1972.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref13\">13- L. A. Goodman and W. H. Kruskal, \"Measures of association for cross classifications III: Approximate sampling theory,\" <i>Journal of the American Statistical Association</i>, vol. 58, no. 302, pp. 310-364, 1963.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref14\">14- T. Byrt, J. Bishop, and J. B. Carlin, \"Bias, prevalence and kappa,\" <i>Journal of clinical epidemiology</i>, vol. 46, no. 5, pp. 423-429, 1993.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref15\">15- M. Shepperd, D. Bowes, and T. Hall, \"Researcher bias: The use of machine learning in software defect prediction,\" <i>IEEE Transactions on Software Engineering</i>, vol. 40, no. 6, pp. 603-616, 2014.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref16\">16- X. Deng, Q. Liu, Y. Deng, and S. Mahadevan, \"An improved method to construct basic probability assignment based on the confusion matrix for classification problem,\" <i>Information Sciences</i>, vol. 340, pp. 250-261, 2016.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref17\">17- J.-M. Wei, X.-J. Yuan, Q.-H. Hu, and S.-Q. Wang, \"A novel measure for evaluating classifiers,\" <i>Expert Systems with Applications</i>, vol. 37, no. 5, pp. 3799-3809, 2010.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref18\">18- I. Kononenko and I. Bratko, \"Information-based evaluation criterion for classifier's performance,\" <i>Machine learning</i>, vol. 6, no. 1, pp. 67-80, 1991.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref19\">19- R. Delgado and J. D. Núnez-González, \"Enhancing confusion entropy as measure for evaluating classifiers,\" in <i>The 13th International Conference on Soft Computing Models in Industrial and Environmental Applications</i>, 2018: Springer, pp. 79-89.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref20\">20- J. Gorodkin, \"Comparing two K-category assignments by a K-category correlation coefficient,\" <i>Computational biology and chemistry</i>, vol.28, no. 5-6, pp. 367-374, 2004.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref21\">21- C. O. Freitas, J. M. De Carvalho, J. Oliveira, S. B. Aires, and R. Sabourin, \"Confusion matrix disagreement for multiple classifiers,\" in <i>Iberoamerican Congress on Pattern Recognition</i>, 2007: Springer, pp. 387-396.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref22\">22- P. Branco, L. Torgo, and R. P. Ribeiro, \"Relevance-based evaluation metrics for multi-class imbalanced domains,\" in <i>Pacific-Asia Conference on Knowledge Discovery and Data Mining</i>, 2017: Springer, pp. 698-710.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref23\">23- D. Ballabio, F. Grisoni, and R. Todeschini, \"Multivariate comparison of classification performance measures,\" <i>Chemometrics and Intelligent Laboratory Systems</i>, vol. 174, pp. 33-44, 2018.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref24\">24- J. Cohen, \"A coefficient of agreement for nominal scales,\" <i>Educational and psychological measurement</i>, vol. 20, no. 1, pp. 37-46, 1960.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref25\">25- S. Siegel, \"Nonparametric statistics for the behavioral sciences,\" 1956.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref26\">26- H. Cramér, <i>Mathematical methods of statistics</i>. Princeton university press, 1999.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref27\">27- B. W. Matthews, \"Comparison of the predicted and observed secondary structure of T4 phage lysozyme,\" <i>Biochimica et Biophysica Acta (BBA)-Protein Structure</i>, vol. 405, no. 2, pp. 442-451, 1975.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref28\">28- J. A. Swets, \"The relative operating characteristic in psychology: a technique for isolating effects of response bias finds wide use in the study of perception and cognition,\" <i>Science</i>, vol. 182, no. 4116, pp. 990-1000, 1973.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref29\">29- P. Jaccard, \"Étude comparative de la distribution florale dans une portion des Alpes et des Jura,\" <i>Bull Soc Vaudoise Sci Nat</i>, vol. 37, pp. 547-579, 1901.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref30\">30- T. M. Cover and J. A. Thomas, <i>Elements of Information Theory</i>. John Wiley & Sons, 2012.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref31\">31- E. S. Keeping, <i>Introduction to statistical inference</i>. Courier Corporation, 1995.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref32\">32- V. Sindhwani, P. Bhattacharya, and S. Rakshit, \"Information theoretic feature crediting in multiclass support vector machines,\" in <i>Proceedings of the 2001 SIAM International Conference on Data Mining</i>, 2001: SIAM, pp. 1-18.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref33\">33- M. Bekkar, H. K. Djemaa, and T. A. Alitouche, \"Evaluation measures for models assessment over imbalanced data sets,\" <i>J Inf Eng Appl</i>, vol. 3, no. 10, 2013.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref34\">34- W. J. Youden, \"Index for rating diagnostic tests,\" <i>Cancer</i>, vol. 3, no. 1, pp. 32-35, 1950.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref35\">35- S. Brin, R. Motwani, J. D. Ullman, and S. Tsur, \"Dynamic itemset counting and implication rules for market basket data,\" in <i>Proceedings of the 1997 ACM SIGMOD international conference on Management of data</i>, 1997, pp. 255-264.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref36\">36- S. Raschka, \"MLxtend: Providing machine learning and data science utilities and extensions to Python's scientific computing stack,\" <i>Journal of open source software</i>, vol. 3, no. 24, p. 638, 2018.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref37\">37- J. R. Bray and J. T. Curtis, \"An ordination of the upland forest communities of southern Wisconsin,\" Ecological monographs, vol. 27, no. 4, pp. 325-349, 1957.</blockquote>\t\n",
    "\n",
    "<blockquote id=\"ref38\">38- J. L. Fleiss, J. Cohen, and B. S. Everitt, \"Large sample standard errors of kappa and weighted kappa,\" <i>Psychological bulletin</i>, vol. 72, no. 5, p. 323, 1969.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref39\">39- M. Felkin, \"Comparing classification results between n-ary and binary problems,\" in <i>Quality Measures in Data Mining</i>: Springer, 2007, pp. 277-301.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref40\">40- R. Ranawana and V. Palade, \"Optimized precision-a new measure for classifier performance evaluation,\" in <i>2006 IEEE International Conference on Evolutionary Computation</i>, 2006: IEEE, pp. 2254-2261.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref41\">41- V. García, R. A. Mollineda, and J. S. Sánchez, \"Index of balanced accuracy: A performance measure for skewed class distributions,\" in <i>Iberian conference on pattern recognition and image analysis</i>, 2009: Springer, pp. 441-448.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref42\">42- P. Branco, L. Torgo, and R. P. Ribeiro, \"A survey of predictive modeling on imbalanced domains,\" <i>ACM Computing Surveys (CSUR)</i>, vol. 49, no. 2, pp. 1-50, 2016.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref43\">43- K. Pearson, \"Notes on Regression and Inheritance in the Case of Two Parents,\" in <i>Proceedings of the Royal Society of London</i>, p. 240-242, 1895.</blockquote> \n",
    "\n",
    "<blockquote id=\"ref44\">44- W. J. Conover, <i>Practical nonparametric statistics</i>. John Wiley & Sons, 1998.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref45\">45- G. U. Yule, \"On the methods of measuring association between two attributes,\" <i>Journal of the Royal Statistical Society</i>, vol. 75, no. 6, pp. 579-652, 1912.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref46\">46- R. Batuwita and V. Palade, \"A new performance measure for class imbalance learning. application to bioinformatics problems,\" in <i>2009 International Conference on Machine Learning and Applications</i>, 2009: IEEE, pp. 545-550.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref47\">47- D. K. Lee, \"Alternatives to P value: confidence interval and effect size,\" <i>Korean journal of anesthesiology</i>, vol. 69, no. 6, p. 555, 2016.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref48\">48- M. A. Raslich, R. J. Markert, and S. A. Stutes, \"Selecting and interpreting diagnostic tests,\" <i>Biochemia Medica</i>, vol. 17, no. 2, pp. 151-161, 2007.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref49\">49- D. E. Hinkle, W. Wiersma, and S. G. Jurs, <i>Applied statistics for the behavioral sciences</i>. Houghton Mifflin College Division, 2003.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref50\">50- A. Maratea, A. Petrosino, and M. Manzo, \"Adjusted F-measure and kernel scaling for imbalanced data learning,\" <i>Information Sciences</i>, vol. 257, pp. 331-341, 2014.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref51\">51- L. Mosley, \"A balanced approach to the multi-class imbalance problem,\" 2013.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref52\">52- M. Vijaymeena and K. Kavitha, \"A survey on similarity measures in text mining,\" <i>Machine Learning and Applications: An International Journal</i>, vol. 3, no. 2, pp. 19-28, 2016.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref53\">53- Y. Otsuka, \"The faunal character of the Japanese Pleistocene marine Mollusca, as evidence of climate having become colder during the Pleistocene in Japan,\" <i>Biogeograph Soc Japan</i>, vol. 6, no. 16, pp. 165-170, 1936.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref54\">54- A. Tversky, \"Features of similarity,\" <i>Psychological review</i>, vol. 84, no. 4, p. 327, 1977.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref55\">55- K. Boyd, K. H. Eng, and C. D. Page, \"Area under the precision-recall curve: point estimates and confidence intervals,\" in <i>Joint European conference on machine learning and knowledge discovery in databases</i>, 2013: Springer, pp. 451-466.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref56\">56- J. Davis and M. Goadrich, \"The relationship between Precision-Recall and ROC curves,\" in <i>Proceedings of the 23rd international conference on Machine learning</i>, 2006, pp. 233-240.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref57\">57- M. Kuhn, \"Building predictive models in R using the caret package,\" <i>J Stat Softw</i>, vol. 28, no. 5, pp. 1-26, 2008.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref58\">58- V. Labatut and H. Cherifi, \"Accuracy measures for the comparison of classifiers,\" <i>arXiv preprint arXiv:1207.3790</i>, 2012.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref59\">59- S. Wallis, \"Binomial confidence intervals and contingency tests: mathematical fundamentals and the evaluation of alternative methods,\" <i>Journal of Quantitative Linguistics</i>, vol. 20, no. 3, pp. 178-208, 2013.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref60\">60- D. Altman, D. Machin, T. Bryant, and M. Gardner, <i>Statistics with confidence: confidence intervals and statistical guidelines</i>. John Wiley & Sons, 2013.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref61\">61- J. A. Hanley and B. J. McNeil, \"The meaning and use of the area under a receiver operating characteristic (ROC) curve,\" <i>Radiology</i>, vol. 143, no. 1, pp. 29-36, 1982.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref62\">62- E. B. Wilson, \"Probable inference, the law of succession, and statistical inference,\" <i>Journal of the American Statistical Association</i>, vol. 22, no. 158, pp. 209-212, 1927.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref63\">63- A. Agresti and B. A. Coull, \"Approximate is better than “exact” for interval estimation of binomial proportions,\" <i>The American Statistician</i>, vol. 52, no. 2, pp. 119-126, 1998.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref64\">64- C. S. Peirce, \"The numerical measure of the success of predictions,\" <i>Science</i>, no. 93, pp. 453-454, 1884.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref65\">65- E. W. Steyerberg, B. Van Calster, and M. J. Pencina, \"Performance measures for prediction models and markers: evaluation of predictions and classifications,\" <i>Revista Española de Cardiología (English Edition)</i>, vol. 64, no. 9, pp. 788-794, 2011.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref66\">66- A. J. Vickers and E. B. Elkin, \"Decision curve analysis: a novel method for evaluating prediction models,\" <i>Medical Decision Making</i>, vol. 26, no. 6, pp. 565-574, 2006.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref67\">67- G. W. Bohrnstedt and D. Knoke,\"Statistics for social data analysis,\" 1982.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref68\">68- W. M. Rand, \"Objective criteria for the evaluation of clustering methods,\" <i>Journal of the American Statistical association</i>, vol. 66, no. 336, pp. 846-850, 1971.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref69\">69- J. M. Santos and M. Embrechts, \"On the use of the adjusted rand index as a metric for evaluating supervised classification,\" in <i>International conference on artificial neural networks</i>, 2009: Springer, pp. 175-184.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref70\">70- J. Cohen, \"Weighted kappa: nominal scale agreement provision for scaled disagreement or partial credit,\" <i>Psychological bulletin</i>, vol. 70, no. 4, p. 213, 1968.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref71\">71- R. Bakeman and J. M. Gottman, <i>Observing interaction: An introduction to sequential analysis</i>. Cambridge university press, 1997.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref72\">72- S. Bangdiwala, \"A graphical test for observer agreement,\" in <i>45th International Statistical Institute Meeting</i>, 1985, vol. 1985, p. 307.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref73\">73- K. Bangdiwala and H. Bryan, \"Using SAS software graphical procedures for the observer agreement chart,\" in <i>Proceedings of the SAS Users Group International Conference</i>, 1987, vol. 12, pp. 1083-1088.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref74\">74- A. F. Hayes and K. Krippendorff, \"Answering the call for a standard reliability measure for coding data,\" <i>Communication methods and measures</i>, vol. 1, no. 1, pp. 77-89, 2007.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref75\">75- M. Aickin, \"Maximum likelihood estimation of agreement in the constant predictive probability model, and its relation to Cohen's kappa,\" <i>Biometrics</i>, pp. 293-302, 1990.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref76\">76- N. A. Macmillan and C. D. Creelman, <i>Detectiontheory: A user's guide</i>. Psychology press, 2004.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref77\">77- D. J. Hand, P. Christen, and N. Kirielle, \"F*: an interpretable transformation of the F-measure,\" <i>Machine Learning</i>, vol. 110, no. 3, pp. 451-456, 2021.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref78\">78- G. W. Brier, \"Verification of forecasts expressed in terms of probability,\" <i>Monthly weather review</i>, vol. 78, no. 1, pp. 1-3, 1950.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref79\">79- L. Buitinck et al., \"API design for machine learning software: experiences from the scikit-learn project,\" <i>arXiv preprint arXiv:1309.0238</i>, 2013.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref80\">80- R. W. Hamming, \"Error detecting and error correcting codes,\" The Bell system technical journal, vol. 29, no. 2, pp. 147-160, 1950.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref81\">81- S. S. Choi, S. H. Cha, and C. C. Tappert, \"A survey of binary similarity and distance measures,\" Journal of systemics, cybernetics and informatics, vol. 8, no. 1, pp. 43-48, 2010.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref82\">82- J. Braun-Blanquet, \"Plant sociology. The study of plant communities,\" Plant sociology. The study of plant communities. First ed., 1932.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref83\">83- C. C. Little, \"Abydos Documentation,\" 2020.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref84\">84- K. Villela, A. Silva, T. Vale, and E. S. de Almeida, \"A survey on software variability management approaches,\" in <i>Proceedings of the 18th International Software Product Line Conference-Volume 1</i>, 2014, pp. 147-156.</blockquote>\n",
    "    \n",
    "<blockquote id=\"ref85\">85- J. R. Saura, A. Reyes-Menendez, and P. Palos-Sanchez, \"Are black Friday deals worth it? Mining Twitter users’ sentiment and behavior response,\" <i>Journal of Open Innovation: Technology, Market, and Complexity</i>, vol. 5, no. 3, p. 58, 2019.</blockquote>\n",
    "\n",
    "<blockquote id=\"ref86\">86- P. Schubert and U. Leimstoll, \"Importance and use of information technology in small and medium‐sized companies,\" <i>Electronic Markets</i>, vol. 17, no. 1, pp. 38-55, 2007.</blockquote>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<script type=\"text/javascript\">\n",
    "var sc_project=12845182; \n",
    "var sc_invisible=1; \n",
    "var sc_security=\"001dde8f\"; \n",
    "</script>\n",
    "<script type=\"text/javascript\"\n",
    "src=\"https://www.statcounter.com/counter/counter.js\" async></script>\n",
    "<noscript><div class=\"statcounter\"><a title=\"Web Analytics\"\n",
    "href=\"https://statcounter.com/\" target=\"_blank\"><img class=\"statcounter\"\n",
    "src=\"https://c.statcounter.com/12845182/0/001dde8f/1/\" alt=\"Web Analytics\"\n",
    "referrerPolicy=\"no-referrer-when-downgrade\"></a></div></noscript>"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": false,
   "sideBar": true,
   "skip_h1_title": true,
   "title_cell": "PyCM Document",
   "title_sidebar": "PyCM Document",
   "toc_cell": true,
   "toc_position": {
    "height": "382px",
    "left": "10px",
    "top": "10px",
    "width": "256px"
   },
   "toc_section_display": false,
   "toc_window_display": true
  },
  "vscode": {
   "interpreter": {
    "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
