\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",
"
"
]
},
{
"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": [
"
\n",
" \n",
"
\n",
"
Fig2. Parameter Recommender Block Diagram
"
]
},
{
"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": [
"
Notice : 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.
"
]
},
{
"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": [
"
Notice : From version 3.8, 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.
\n",
"
"
]
},
{
"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": [
""
]
},
"execution_count": 92,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEjCAYAAADdZh27AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJzt3Xt0nXWd7/H3t21ubdKmbZI2zaUpbaE3FKSFERgsS2UKjKDgKKgLmAV2nfGgeDk6lTnHC3POwoPjKB45MozjAjkKo7jQynRERUCmA9KyQKWFYoFkZ6dp7k3a5rZ38j1/7J3tbpqkaZtnXz+vtbLWfp7nl/18n9w+eW7fx9wdERERgFnpLkBERDKHQkFERBIUCiIikqBQEBGRBIWCiIgkKBRERCRBoSAiIgkKBclKZtZoZgNmdsTMDprZ/WZWOm7MhWb2azM7bGa9ZvYzM1s3bsx8M/uGmYXi77U/Pl0xyXrNzD5hZi+b2VEzC5vZj8zs7CC3VyRVFAqSzd7j7qXAOcC5wOfHFpjZ24FfAD8FlgErgN8BO83sjPiYQuAJYD2wBZgPXAh0AedPss67gduATwCLgDOBnwBXnmzxZjbnZD9HJGimO5olG5lZI3CLu/8qPn0XsN7dr4xPPwP8wd0/Nu7z/h3ocPcbzOwW4H8BK939yDTWuRp4FXi7uz8/y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1588UXuuOMObr/9dgD27dvHOeecM+HHoUOHaGlpoba2NrGu2tpaWlpaJt2G/v5+fv7zn3Pttdcm5pkZl112Geeddx733XdfYn5bWxvV1bHTQdXV1bS3tyeWbdy4kWeeeeZUv5QieSUajQKx37WamhrWrl1LTU0Ns2al7k91YOcUzOwhYDNQYWZh4ItAAYC73wvsAK4A9gP9wF/P1Lobtv3bTL1VwnSP4x05coRrr72Wb3zjG8yfP5/W1lYqK//UmPDJJ5/krrvuor+/n+7ubtavX8973vMeAD74wQ8mxv3qV79i7969iem+vj4OHz5Mb28vN954I3/84x8xMyKR2DHss846i5deemnSusb2SJJNdQXQz372My666CIWLVqUmLdz506WLVtGe3s77373u1mzZs0Jz5NUVVVx4EDW7gCKpEx3dzfNzc3U1NRQUVFBeXl5WuoILBTcfcrjDvFjXP81iHUHfiJmEpFIhGuvvZYPf/jDXHPNNQCUlJQkrscfHBzkYx/7GLt376auro4vfelLx1yrP2/evMTr0dFRnn32WUpKSo5Zx8c//nEuvfRSHn30URobG9m8eTMQ21NIDpVkTz31FLW1tYTD4cS8cDjMsmXLJt2Whx9++LhDR2Pjq6qqeN/73sfzzz/PJZdcwpIlS2htbaW6uprW1laqqqoSnzM4OHjcNojInwwPDxMKhejt7WXevHmUlpamtR71Ppoh7s7NN9/M2rVr+fSnP52Yv3btWvbv3w+QCICKigqOHDnCI488Mun7XXbZZXzrW99KTI/tBfT29lJTUwPA/fffn1g+tqcw0Ud5eTnV1dWUlZXx3HPP4e5873vf4+qrr55w3b29vTz99NPHLD969CiHDx9OvP7FL37Bhg0bALjqqqt44IEHAHjggQeO+bzXXnstMU5EjtXd3c3evXs5fPgwdXV1nHXWWRQXF6e1JoXCDNm5cycPPvggv/71rxPH8nfs2MGVV17JU089BUB5eTkf/ehHOfvss3nve9/Lpk2bJn2/b37zm+zevZu3vOUtrFu3jnvvvReAz33uc3z+85/noosuYmRk5KRq/Pa3v80tt9zCqlWrWLlyJZdffjkA9957b+L9AR599FEuu+yyY/Z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Hxy80s8XEeiztGTd/IbH+Q79JTZkip06Hj0Sm77jDR3F/bmYvAqPAV+JtGDbH5/8eOCs+/2AKaxU5JQoFkdP3jLv/5WTzzexM4D/i5xReSnVxIidDh49EAuburwF3An+b7lpETkShIJIa9wKXmNmKdBciMhV1SRURkQTtKYiISIJCQUREEhQKIiKSoFAQEZEEhYKIiCQoFEREJEGhICIiCQoFERFJ+P8LjK4I8/KaBAAAAABJRU5ErkJggg==\n",
"text/plain": [
"
"
]
},
{
"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.0-py3.5.egg\\pycm\\pycm_curve.py:382: RuntimeWarning: The curve axes contain 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": [
""
]
},
"execution_count": 94,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEjCAYAAADdZh27AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJzt3Xl0nPV97/H319ZuyZJtSbZWy3jBO3YiAiFpgCamQMoSSBtIchN6ADehhDRJs5Em4bo3t0la2sAJJ9S5UAgngbY0SX24DulNwhJoXDCxcWyDF0AzGnnRLi/ape/9Y6TJWJYt2daj0cx8XufonJl5npn5PpJGH/2e5fszd0dERARgWqILEBGRqUOhICIiMQoFERGJUSiIiEiMQkFERGIUCiIiEqNQEBGRGIWCpBQzqzOzLjM7ZmaHzeyfzSx/aNmzZtY9tKzZzH5sZmVjvN47zGyzmbWbWauZvWRmfzY5WyMy+RQKkoqucfd84G3AhcBfxy27c2jZIiAf+PtTvYiZvRP4FfDc0PpzgE8CV51NUWY2/WyeJzKZFAqSsty9AfgZsHKUZe3AT4E1p3mJvwMedfdvuXuzR73i7n8KYGa3mNkL8U8wMzezRUO3HzGz7w2NNI4DXzazQ/HhYGYfMLMdQ7enmdmXzOwNM2sxs381s9nn+G0QOSMKBUlZZlYFXA1sG2XZHOAGYP8pnpsHvBN48hzL+DDwDaCA6KjkOPCHI5b/aOj2XcD1wKVAOdAGPHCO7y9yRhQKkop+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77zndjjn//851m6dCmrV6/mAx/4AO3t7QD87ne/45Zbbgl8u6aC/kHn4w+/lOgyJAUdPXqU3bt388Ybb0zK+yUyFEbbf3DyXynA3Te6e62715aUjHmVdkJkZGRw77338tprr7FlyxYeeOABdu/eTWtrK1u2bOE973nPuF+rv78/kBo/+clPsnHjRvbt28e+fft4+umnT1pnwYIFPPfcc+zYsYOvfvWrrF+/HoCdO3fy/e9/n5deeolXX32Vp556in379gGwbt06du7cyY4dO1iyZAl/+7d/C8CqVauIRCKEw+FAtkcklQ0MDBAKhdi7dy8AlZWVk/K+iQyFCFAVd78SOJCgWs5ZWVkZb3tb9Fh5QUEBy5Yto6GhgSeffJIrr/z9oZUNGzZw4YUXsnLlStavXx/7b/2yyy7j7rvv5tJLL+W+++6jqamJG2+8kQsvvJALL7yQF198EYCXXnqJSy65hLVr13LJJZewZ8+ecdV38OBBjhw5wjvf+U7MjI997GP89Kc/PWm9Sy65hFmzZgFw8cUXE4lEAHjttde4+OKLycvLIyMjg0svvZSf/OQnAFxxxRVkZGSc9ByAa665hieeeOKMvpci6c7def3112lubmbevHksX76cgoKCSXnvRIbCJuBjQ2chXQx0uPvBBNYzYerq6ti2bRsXXXQRL774Im9/+9tjy+68805efvlldu7cSVdXF0899VRsWXt7O8899xyf+9zn+PSnP81nPvMZXn75Zf793/+d2267DYClS5fy/PPPs23bNjZs2MDdd98NwJ49e1izZs2oX+3t7TQ0NJzwn0ZlZSUNDQ2n3Y6HHnqIq666CoCVK1fy/PPP09LSQmdnJ5s3b6a+vv6k5zz88MOx5wDU1tby61//+iy+iyLpZ3gvgZlRUVHBsmXLqKioYNq0yftTHdh1Cmb2OHAZUGxmEeDrQCaAuz8IbAauBvYDncCfTdR713zp/07US8XUffP941rv2LFj3HjjjXznO99h5syZHDx4kPhdXs888wzf/va36ezspLW1lRUrVnDNNdcA8KEPfSi23i9+8Qt2794du3/kyBGOHj1KR0cHH//4x9m3bx9mRl9fHwDnn38+27dvP2Vdox0/ON0ZQM888wwPPfQQL7zwAgDLli3ji1/8IuvWrSM/P58LLrggNjoY9o1vfIOMjAw+8pGPxB4rLS3lwIGkHQCKTJrW1lbq6+upqKiguLiYoqKihNQRWCi4+81jLHfgL4J47/H+AZ9ofX193HjjjXzkIx/hhhtuACA3Nzd2Pn53dzd33HEHW7dupaqqinvuueeEc/VnzJgRuz04OMhvfvMbcnNzT3iPT33qU1x++eX85Cc/oa6ujssuuwyIjhTiQyXes88+S2Vl5Qm7dSKRCOXl5aOuv2PHDm677TZ+9rOfMWfOnNjjt956K7feeisAd9999wkjj0cffZSnnnqKX/7ylyeETXd390nbICK/19vbSzgcpqOjgxkzZpCfn5/QetT7aIK4O7feeivLli3js5/9bOzxZcuWsX//foBYABQXF3Ps2DGefPLJU77eFVdcwXe/+93Y/eFRQEdHBxUV0ZO0Hnnkkdjy4ZHCaF9FRUWUlZVRUFDAli1bcHd+8IMfcN111530vuFwmBtuuIHHHnuMJUuWnLCssbExts6Pf/xjbr45mvtPP/003/rWt9i0aRN5eXknPGfv3r2sXLny9N88kTTV2trK7t27OXr0KFVVVZx//vnk5OQktCaFwgR58cUXeeyxx/jVr34V25e/efNm3v/+9/Pss88CUFRUxO23386qVau4/vrrufDCC0/5evfffz9bt25l9erVLF++nAcffBCAL3zhC3z5y1/mXe96FwMDA2dU4/e+9z1uu+02Fi1axMKFC2P7/h988MHY62/YsIGWlhbuuOMO1qxZQ21tbez5N954I8uXL+eaa67hgQceiB2QvvPOOzl69Cjr1q1jzZo1fOITn4g955lnnuH970/MyE1kqsvIyGDGjBksX76c0tLSKXFRp422r3kqq62t9ZGT7Lz22mssW7YsQRWN7d3vfjdPPfVUwvYRJkpPTw+XXnopL7zwwknHH2Dq/9zORG//ICu+/jT7vnF1okuRKczdaWxsZHBwkLKyyb1W18xecffasdZLiYZ4U929995LOBxOu1AIh8N885vfHDUQRNJNV1cXdXV1dHZ2xkbZU5E+rZPgoosuSnQJCbF48WIWL16c6DJEEsrdOXjwIIcOHWL69Omcd955C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RGIwUREYlRKIiISIxCQUREYhQKIiISo1AQEZEYhYKIiMQoFEREJEahICIiMf8f9tF+MrgrIL0AAAAASUVORK5CYII=\n",
"text/plain": [
"
Notice : overall_benchmark_weight and class_benchmark_weight, new in version 3.3
\n",
"
"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"ROCCurve"
]
},
{
"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": [
"PRCurve"
]
},
{
"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": [
"MultiLabelCM"
]
},
{
"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": [
"* Wikipedia page"
]
},
{
"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",
"Wikipedia page"
]
},
{
"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",
"Wikipedia page"
]
},
{
"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",
"Wikipedia page"
]
},
{
"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",
"Wikipedia page"
]
},
{
"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",
"Wikipedia page"
]
},
{
"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",
"Wikipedia page"
]
},
{
"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",
"Wikipedia page"
]
},
{
"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",
"Wikipedia page"
]
},
{
"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",
"Wikipedia page"
]
},
{
"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": [
"
\n",
"
Notice : new in version 0.4
\n",
"
"
]
},
{
"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",
"Wikipedia page"
]
},
{
"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": [
"
\n",
"
Notice : new in version 0.4
\n",
"
"
]
},
{
"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",
"Interpretation\n",
"\n",
"Wikipedia page"
]
},
{
"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 Youden Index"
]
},
{
"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",
"Interpretation\n",
"\n",
"Wikipedia page"
]
},
{
"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": [
"
\n",
"
Notice : LR+ renamed to PLR in version 1.5
\n",
"
"
]
},
{
"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",
"Interpretation\n",
"\n",
"Wikipedia page"
]
},
{
"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": [
"
\n",
"
Notice : LR- renamed to NLR in version 1.5
\n",
"
"
]
},
{
"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",
"Wikipedia page"
]
},
{
"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",
"Wikipedia page"
]
},
{
"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",
"Wikipedia page"
]
},
{
"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": [
"
\n",
"
Notice : new in version 0.3
\n",
"
"
]
},
{
"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": [
"
\n",
"
Notice : new in version 0.8.1
\n",
"
"
]
},
{
"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",
"Wikipedia page\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": [
"
\n",
"
Notice : new in version 0.9
\n",
"
"
]
},
{
"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": [
"
\n",
"
Notice : new in version 1.3
\n",
"
"
]
},
{
"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": [
"
"
]
},
{
"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",
"Interpretation"
]
},
{
"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": [
"
\n",
"
Notice : new in version 1.4
\n",
"
Notice : this is an approximate calculation of AUC
\n",
"
"
]
},
{
"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": [
"
"
]
},
{
"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": [
"
\n",
"
Notice : new in version 2.3
\n",
"
"
]
},
{
"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",
"Wikipedia page"
]
},
{
"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": [
"
\n",
"
Notice : new in version 2.3
\n",
"
"
]
},
{
"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": [
"
\n",
"
Notice : new in version 3.6
\n",
"
"
]
},
{
"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",
"Wikipedia page"
]
},
{
"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": [
"
\n",
"
Notice : new in version 2.3
\n",
"
"
]
},
{
"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",
"Wikipedia page"
]
},
{
"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": [
"
\n",
"
Notice : new in version 2.4
\n",
"
"
]
},
{
"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": [
"
\n",
"
Notice : new in version 2.4
\n",
"
Notice : this is an approximate calculation of AUPR
\n",
"
"
]
},
{
"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": [
"
\n",
"
Notice : new in version 2.5
\n",
"
"
]
},
{
"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": [
"
"
]
},
{
"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",
"Wikipedia page"
]
},
{
"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": [
"
\n",
"
Notice : new in version 3.1
\n",
"
"
]
},
{
"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": [
"Wikipedia page"
]
},
{
"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": [
"
\n",
"
Notice : new in version 3.6
\n",
"
"
]
},
{
"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",
"Benchmark1\n",
"Benchmark2\n",
"Benchmark3\n",
"Benchmark4\n",
"\n",
"Wikipedia page"
]
},
{
"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": [
"
\n",
"
Notice : new in version 0.3
\n",
"
"
]
},
{
"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": [
"
"
]
},
{
"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",
"Wikipedia page"
]
},
{
"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": [
"
\n",
"
Notice : new in version 0.7
\n",
"
"
]
},
{
"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",
"Benchmark\n",
"\n",
"Wikipedia page"
]
},
{
"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": [
"
\n",
"
Notice : new in version 0.7
\n",
"
"
]
},
{
"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",
"Wikipedia page"
]
},
{
"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": [
"
\n",
"
Notice : new in version 0.7
\n",
"
"
]
},
{
"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",
"Wikipedia page"
]
},
{
"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": [
"
"
]
},
{
"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",
"Wikipedia Page"
]
},
{
"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": [
"
\n",
"
Notice : new in version 0.5
\n",
"
"
]
},
{
"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",
"Wikipedia page\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": [
"
\n",
"
Notice : new in version 0.5
\n",
"
"
]
},
{
"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": [
"
\n",
"
Notice : new in version 0.5
\n",
"
"
]
},
{
"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": [
"
\n",
"
Notice : new in version 0.8.1
\n",
"
"
]
},
{
"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": [
"
\n",
"
Notice : new in version 0.8.1
\n",
"
"
]
},
{
"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",
"Wikipedia page"
]
},
{
"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": [
"
"
]
},
{
"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",
"Wikipedia Page"
]
},
{
"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": [
"
"
]
},
{
"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",
"Wikipedia Page"
]
},
{
"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": [
"
\n",
"
Notice : $ C_{r}^{n} $ is the number of combinations of $ n $ objects taken $ r $
"
]
},
{
"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",
"Wikipedia Page"
]
},
{
"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": [
"
\n",
"
Notice : new in version 2.7
\n",
"
"
]
},
{
"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",
"Wikipedia Page"
]
},
{
"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": [
"
Notice : pos_class always defaults to the greater class name (i.e. max(classes)), unless, the actual_vector contains string. In that case, pos_class does not have any default value, and it must be explicitly specified or else an error will result.
\n",
"
"
]
},
{
"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",
"Wikipedia Page"
]
},
{
"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": [
"
Notice : pos_class always defaults to the greater class name (i.e. max(classes)), unless, the actual_vector contains string. In that case, pos_class does not have any default value, and it must be explicitly specified or else an error will result.
"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Input errors"
]
},
{
"cell_type": "code",
"execution_count": 301,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The type of input vectors is assumed to be 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 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 are 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 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": [
"Input confusion matrix format error\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": [
"Type of the input matrix classes is assumed be the same\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": [
"Number of the classes is lower than 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": [
"The input type is supposed to be dictionary but it's not!\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": [
"The domain of all ConfusionMatrix objects must be same! The sample size or the number of classes are different.\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": [
"The input is supposed to consist of pycm.ConfusionMatrix object but it's not!\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": [
"Lower than two confusion matrices is given for comparing. The minimum number of confusion matrix for comparing is 2.\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": [
"The class_weight type must be dictionary and also must be specified for all of the 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": [
"The class_benchmark_weight type must be dictionary and also must be specified for all of the 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": [
"The overall_benchmark_weight type must be dictionary and also must be specified for all of the 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": [
"CI calculation for this parameter is not supported on this version of pycm.\n",
"Supported parameters : 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": [
"The input type is supposed to be string but it's not!\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": [
"The weight type must be dictionary and also must be specified for all of the classes.\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 only works in vector mode\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": [
"The input type is supposed to be pycm.ConfusionMatrix object but it's not!\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": [
"Number of the classes is lower than 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": [
"The classes list isn't unique. It contains duplicated labels.\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": [
"The type of input vectors is assumed to be 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 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 probability values must be one\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": [
"The type of classes is assumed to be 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": [
"The classes don't match to 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": [
"Number of the classes is lower than 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": [
"The elements of the probability vector can only contain 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, \"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": [
"The type of thresholds is assumed to be list or 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": [
"Number of the thresholds is lower than 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": [
"The thresholds can only contain 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": [
"The classes list isn't unique. It contains duplicated labels.\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": [
"Probability vector elements must have same length and equal to 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 numeric integral method can only be selected between 'trapezoidal' and '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": [
"Class extraction from input failed. 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": [
"Given class name is not among problem'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": [
"Given index is out of vector's range.\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": [
"The type of input vectors is assumed to be a list or a NumPy array\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 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 are 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": [
"The classes list isn't unique. It contains duplicated labels.\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": [
"
\n",
"
Notice : updated in version 4.0
\n",
"
"
]
},
{
"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": [
"
Haghighi, S., Jasemi, M., Hessabi, S. and Zolanvari, A. (2018). PyCM: Multiclass confusion matrix library in Python. Journal of Open Source Software, 3(25), p.729.
1- J. R. Landis and G. G. Koch, \"The measurement of observer agreement for categorical data,\" biometrics, pp. 159-174, 1977.
\n",
"\n",
"
2- D. M. Powers, \"Evaluation: from precision, recall and F-measure to ROC, informedness, markedness and correlation,\" arXiv preprint arXiv:2010.16061, 2020.
\n",
"\n",
"\n",
"
3- C. Sammut and G. I. Webb, Encyclopedia of machine learning. Springer Science & Business Media, 2011.
\n",
"\n",
"
4- J. L. Fleiss, \"Measuring nominal scale agreement among many raters,\" Psychological bulletin, vol. 76, no. 5, p. 378, 1971.
\n",
"\n",
"
5- D. G. Altman, Practical statistics for medical research. CRC press, 1990.
\n",
"\n",
"
6- K. L. Gwet, \"Computing inter-rater reliability and its variance in the presence of high agreement,\" British Journal of Mathematical and Statistical Psychology, vol. 61, no. 1, pp. 29-48, 2008.
\n",
"\n",
"
7- W. A. Scott, \"Reliability of content analysis: The case of nominal scale coding,\" Public opinion quarterly, pp. 321-325, 1955.
\n",
"\n",
"
8- E. M. Bennett, R. Alpert, and A. Goldstein, \"Communications through limited-response questioning,\" Public Opinion Quarterly, vol. 18, no. 3, pp. 303-308, 1954.
\n",
"\n",
"
9- D. V. Cicchetti, \"Guidelines, criteria, and rules of thumb for evaluating normed and standardized assessment instruments in psychology,\" Psychological assessment, vol. 6, no. 4, p. 284, 1994.
\n",
"\n",
"
10- R. B. Davies, \"Algorithm AS 155: The distribution of a linear combination of χ2 random variables,\" Applied Statistics, pp. 323-333, 1980.
\n",
"\n",
"
11- S. Kullback and R. A. Leibler, \"On information and sufficiency,\" The annals of mathematical statistics, vol. 22, no. 1, pp. 79-86, 1951.
\n",
"\n",
"
12- L. A. Goodman and W. H. Kruskal, \"Measures of association for cross classifications, IV: Simplification of asymptotic variances,\" Journal of the American Statistical Association, vol. 67, no. 338, pp. 415-421, 1972.
\n",
"\n",
"
13- L. A. Goodman and W. H. Kruskal, \"Measures of association for cross classifications III: Approximate sampling theory,\" Journal of the American Statistical Association, vol. 58, no. 302, pp. 310-364, 1963.
\n",
"\n",
"
14- T. Byrt, J. Bishop, and J. B. Carlin, \"Bias, prevalence and kappa,\" Journal of clinical epidemiology, vol. 46, no. 5, pp. 423-429, 1993.
\n",
"\n",
"
15- M. Shepperd, D. Bowes, and T. Hall, \"Researcher bias: The use of machine learning in software defect prediction,\" IEEE Transactions on Software Engineering, vol. 40, no. 6, pp. 603-616, 2014.
\n",
"\n",
"
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,\" Information Sciences, vol. 340, pp. 250-261, 2016.
\n",
"\n",
"
17- J.-M. Wei, X.-J. Yuan, Q.-H. Hu, and S.-Q. Wang, \"A novel measure for evaluating classifiers,\" Expert Systems with Applications, vol. 37, no. 5, pp. 3799-3809, 2010.
\n",
"\n",
"
18- I. Kononenko and I. Bratko, \"Information-based evaluation criterion for classifier's performance,\" Machine learning, vol. 6, no. 1, pp. 67-80, 1991.
\n",
"\n",
"
19- R. Delgado and J. D. Núnez-González, \"Enhancing confusion entropy as measure for evaluating classifiers,\" in The 13th International Conference on Soft Computing Models in Industrial and Environmental Applications, 2018: Springer, pp. 79-89.
\n",
"\n",
"
20- J. Gorodkin, \"Comparing two K-category assignments by a K-category correlation coefficient,\" Computational biology and chemistry, vol.28, no. 5-6, pp. 367-374, 2004.
\n",
"\n",
"
21- C. O. Freitas, J. M. De Carvalho, J. Oliveira, S. B. Aires, and R. Sabourin, \"Confusion matrix disagreement for multiple classifiers,\" in Iberoamerican Congress on Pattern Recognition, 2007: Springer, pp. 387-396.
\n",
"\n",
"
22- P. Branco, L. Torgo, and R. P. Ribeiro, \"Relevance-based evaluation metrics for multi-class imbalanced domains,\" in Pacific-Asia Conference on Knowledge Discovery and Data Mining, 2017: Springer, pp. 698-710.
\n",
"\n",
"
23- D. Ballabio, F. Grisoni, and R. Todeschini, \"Multivariate comparison of classification performance measures,\" Chemometrics and Intelligent Laboratory Systems, vol. 174, pp. 33-44, 2018.
\n",
"\n",
"
24- J. Cohen, \"A coefficient of agreement for nominal scales,\" Educational and psychological measurement, vol. 20, no. 1, pp. 37-46, 1960.
\n",
"\n",
"
25- S. Siegel, \"Nonparametric statistics for the behavioral sciences,\" 1956.
\n",
"\n",
"
26- H. Cramér, Mathematical methods of statistics. Princeton university press, 1999.
\n",
"\n",
"
27- B. W. Matthews, \"Comparison of the predicted and observed secondary structure of T4 phage lysozyme,\" Biochimica et Biophysica Acta (BBA)-Protein Structure, vol. 405, no. 2, pp. 442-451, 1975.
\n",
"\n",
"
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,\" Science, vol. 182, no. 4116, pp. 990-1000, 1973.
\n",
"\n",
"
29- P. Jaccard, \"Étude comparative de la distribution florale dans une portion des Alpes et des Jura,\" Bull Soc Vaudoise Sci Nat, vol. 37, pp. 547-579, 1901.
\n",
"\n",
"
30- T. M. Cover and J. A. Thomas, Elements of Information Theory. John Wiley & Sons, 2012.
\n",
"\n",
"
31- E. S. Keeping, Introduction to statistical inference. Courier Corporation, 1995.
\n",
"\n",
"
32- V. Sindhwani, P. Bhattacharya, and S. Rakshit, \"Information theoretic feature crediting in multiclass support vector machines,\" in Proceedings of the 2001 SIAM International Conference on Data Mining, 2001: SIAM, pp. 1-18.
\n",
"\n",
"
33- M. Bekkar, H. K. Djemaa, and T. A. Alitouche, \"Evaluation measures for models assessment over imbalanced data sets,\" J Inf Eng Appl, vol. 3, no. 10, 2013.
\n",
"\n",
"
34- W. J. Youden, \"Index for rating diagnostic tests,\" Cancer, vol. 3, no. 1, pp. 32-35, 1950.
\n",
"\n",
"
35- S. Brin, R. Motwani, J. D. Ullman, and S. Tsur, \"Dynamic itemset counting and implication rules for market basket data,\" in Proceedings of the 1997 ACM SIGMOD international conference on Management of data, 1997, pp. 255-264.
\n",
"\n",
"
36- S. Raschka, \"MLxtend: Providing machine learning and data science utilities and extensions to Python's scientific computing stack,\" Journal of open source software, vol. 3, no. 24, p. 638, 2018.
\n",
"\n",
"
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.
\t\n",
"\n",
"
38- J. L. Fleiss, J. Cohen, and B. S. Everitt, \"Large sample standard errors of kappa and weighted kappa,\" Psychological bulletin, vol. 72, no. 5, p. 323, 1969.
\n",
"\n",
"
39- M. Felkin, \"Comparing classification results between n-ary and binary problems,\" in Quality Measures in Data Mining: Springer, 2007, pp. 277-301.
\n",
"\n",
"
40- R. Ranawana and V. Palade, \"Optimized precision-a new measure for classifier performance evaluation,\" in 2006 IEEE International Conference on Evolutionary Computation, 2006: IEEE, pp. 2254-2261.
\n",
"\n",
"
41- V. García, R. A. Mollineda, and J. S. Sánchez, \"Index of balanced accuracy: A performance measure for skewed class distributions,\" in Iberian conference on pattern recognition and image analysis, 2009: Springer, pp. 441-448.
\n",
"\n",
"
42- P. Branco, L. Torgo, and R. P. Ribeiro, \"A survey of predictive modeling on imbalanced domains,\" ACM Computing Surveys (CSUR), vol. 49, no. 2, pp. 1-50, 2016.
\n",
"\n",
"
43- K. Pearson, \"Notes on Regression and Inheritance in the Case of Two Parents,\" in Proceedings of the Royal Society of London, p. 240-242, 1895.
\n",
"\n",
"
44- W. J. Conover, Practical nonparametric statistics. John Wiley & Sons, 1998.
\n",
"\n",
"
45- G. U. Yule, \"On the methods of measuring association between two attributes,\" Journal of the Royal Statistical Society, vol. 75, no. 6, pp. 579-652, 1912.
\n",
"\n",
"
46- R. Batuwita and V. Palade, \"A new performance measure for class imbalance learning. application to bioinformatics problems,\" in 2009 International Conference on Machine Learning and Applications, 2009: IEEE, pp. 545-550.
\n",
"\n",
"
47- D. K. Lee, \"Alternatives to P value: confidence interval and effect size,\" Korean journal of anesthesiology, vol. 69, no. 6, p. 555, 2016.
\n",
"\n",
"
48- M. A. Raslich, R. J. Markert, and S. A. Stutes, \"Selecting and interpreting diagnostic tests,\" Biochemia Medica, vol. 17, no. 2, pp. 151-161, 2007.
\n",
"\n",
"
49- D. E. Hinkle, W. Wiersma, and S. G. Jurs, Applied statistics for the behavioral sciences. Houghton Mifflin College Division, 2003.
\n",
"\n",
"
50- A. Maratea, A. Petrosino, and M. Manzo, \"Adjusted F-measure and kernel scaling for imbalanced data learning,\" Information Sciences, vol. 257, pp. 331-341, 2014.
\n",
"\n",
"
51- L. Mosley, \"A balanced approach to the multi-class imbalance problem,\" 2013.
\n",
"\n",
"
52- M. Vijaymeena and K. Kavitha, \"A survey on similarity measures in text mining,\" Machine Learning and Applications: An International Journal, vol. 3, no. 2, pp. 19-28, 2016.
\n",
"\n",
"
53- Y. Otsuka, \"The faunal character of the Japanese Pleistocene marine Mollusca, as evidence of climate having become colder during the Pleistocene in Japan,\" Biogeograph Soc Japan, vol. 6, no. 16, pp. 165-170, 1936.
\n",
"\n",
"
54- A. Tversky, \"Features of similarity,\" Psychological review, vol. 84, no. 4, p. 327, 1977.
\n",
"\n",
"
55- K. Boyd, K. H. Eng, and C. D. Page, \"Area under the precision-recall curve: point estimates and confidence intervals,\" in Joint European conference on machine learning and knowledge discovery in databases, 2013: Springer, pp. 451-466.
\n",
"\n",
"
56- J. Davis and M. Goadrich, \"The relationship between Precision-Recall and ROC curves,\" in Proceedings of the 23rd international conference on Machine learning, 2006, pp. 233-240.
\n",
"\n",
"
57- M. Kuhn, \"Building predictive models in R using the caret package,\" J Stat Softw, vol. 28, no. 5, pp. 1-26, 2008.
\n",
"\n",
"
58- V. Labatut and H. Cherifi, \"Accuracy measures for the comparison of classifiers,\" arXiv preprint arXiv:1207.3790, 2012.
\n",
"\n",
"
59- S. Wallis, \"Binomial confidence intervals and contingency tests: mathematical fundamentals and the evaluation of alternative methods,\" Journal of Quantitative Linguistics, vol. 20, no. 3, pp. 178-208, 2013.
\n",
"\n",
"
60- D. Altman, D. Machin, T. Bryant, and M. Gardner, Statistics with confidence: confidence intervals and statistical guidelines. John Wiley & Sons, 2013.
\n",
"\n",
"
61- J. A. Hanley and B. J. McNeil, \"The meaning and use of the area under a receiver operating characteristic (ROC) curve,\" Radiology, vol. 143, no. 1, pp. 29-36, 1982.
\n",
"\n",
"
62- E. B. Wilson, \"Probable inference, the law of succession, and statistical inference,\" Journal of the American Statistical Association, vol. 22, no. 158, pp. 209-212, 1927.
\n",
"\n",
"
63- A. Agresti and B. A. Coull, \"Approximate is better than “exact” for interval estimation of binomial proportions,\" The American Statistician, vol. 52, no. 2, pp. 119-126, 1998.
\n",
"\n",
"
64- C. S. Peirce, \"The numerical measure of the success of predictions,\" Science, no. 93, pp. 453-454, 1884.
\n",
"\n",
"
65- E. W. Steyerberg, B. Van Calster, and M. J. Pencina, \"Performance measures for prediction models and markers: evaluation of predictions and classifications,\" Revista Española de Cardiología (English Edition), vol. 64, no. 9, pp. 788-794, 2011.
\n",
"\n",
"
66- A. J. Vickers and E. B. Elkin, \"Decision curve analysis: a novel method for evaluating prediction models,\" Medical Decision Making, vol. 26, no. 6, pp. 565-574, 2006.
\n",
"\n",
"
67- G. W. Bohrnstedt and D. Knoke,\"Statistics for social data analysis,\" 1982.
\n",
"\n",
"
68- W. M. Rand, \"Objective criteria for the evaluation of clustering methods,\" Journal of the American Statistical association, vol. 66, no. 336, pp. 846-850, 1971.
\n",
"\n",
"
69- J. M. Santos and M. Embrechts, \"On the use of the adjusted rand index as a metric for evaluating supervised classification,\" in International conference on artificial neural networks, 2009: Springer, pp. 175-184.
\n",
"\n",
"
70- J. Cohen, \"Weighted kappa: nominal scale agreement provision for scaled disagreement or partial credit,\" Psychological bulletin, vol. 70, no. 4, p. 213, 1968.
\n",
"\n",
"
71- R. Bakeman and J. M. Gottman, Observing interaction: An introduction to sequential analysis. Cambridge university press, 1997.
\n",
"\n",
"
72- S. Bangdiwala, \"A graphical test for observer agreement,\" in 45th International Statistical Institute Meeting, 1985, vol. 1985, p. 307.
\n",
"\n",
"
73- K. Bangdiwala and H. Bryan, \"Using SAS software graphical procedures for the observer agreement chart,\" in Proceedings of the SAS Users Group International Conference, 1987, vol. 12, pp. 1083-1088.
\n",
"\n",
"
74- A. F. Hayes and K. Krippendorff, \"Answering the call for a standard reliability measure for coding data,\" Communication methods and measures, vol. 1, no. 1, pp. 77-89, 2007.
\n",
"\n",
"
75- M. Aickin, \"Maximum likelihood estimation of agreement in the constant predictive probability model, and its relation to Cohen's kappa,\" Biometrics, pp. 293-302, 1990.
\n",
"\n",
"
76- N. A. Macmillan and C. D. Creelman, Detectiontheory: A user's guide. Psychology press, 2004.
\n",
"\n",
"
77- D. J. Hand, P. Christen, and N. Kirielle, \"F*: an interpretable transformation of the F-measure,\" Machine Learning, vol. 110, no. 3, pp. 451-456, 2021.
\n",
"\n",
"
78- G. W. Brier, \"Verification of forecasts expressed in terms of probability,\" Monthly weather review, vol. 78, no. 1, pp. 1-3, 1950.
\n",
"\n",
"
79- L. Buitinck et al., \"API design for machine learning software: experiences from the scikit-learn project,\" arXiv preprint arXiv:1309.0238, 2013.
\n",
"\n",
"
80- R. W. Hamming, \"Error detecting and error correcting codes,\" The Bell system technical journal, vol. 29, no. 2, pp. 147-160, 1950.
\n",
"\n",
"
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.
\n",
"\n",
"
82- J. Braun-Blanquet, \"Plant sociology. The study of plant communities,\" Plant sociology. The study of plant communities. First ed., 1932.
\n",
"\n",
"
83- C. C. Little, \"Abydos Documentation,\" 2020.
\n",
"\n",
"
84- K. Villela, A. Silva, T. Vale, and E. S. de Almeida, \"A survey on software variability management approaches,\" in Proceedings of the 18th International Software Product Line Conference-Volume 1, 2014, pp. 147-156.
\n",
" \n",
"
85- J. R. Saura, A. Reyes-Menendez, and P. Palos-Sanchez, \"Are black Friday deals worth it? Mining Twitter users’ sentiment and behavior response,\" Journal of Open Innovation: Technology, Market, and Complexity, vol. 5, no. 3, p. 58, 2019.
\n",
"\n",
"
86- P. Schubert and U. Leimstoll, \"Importance and use of information technology in small and medium‐sized companies,\" Electronic Markets, vol. 17, no. 1, pp. 38-55, 2007.