{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Example-4 (File)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from pycm import ConfusionMatrix\n", "import numpy as np\n", "y_test = np.array([600, 200, 200, 200, 200, 200, 200, 200, 500, 500, 500, 200, 200, 200, 200, 200, 200, 200, 200, 200])\n", "y_pred = np.array([100, 200, 200, 100, 100, 200, 200, 200, 100, 200, 500, 100, 100, 100, 100, 100, 100, 100, 500, 200])" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "pycm.ConfusionMatrix(classes: [100, 200, 500, 600])" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cm=ConfusionMatrix(y_test, y_pred)\n", "cm" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Predict 100 200 500 600 \n", "Actual\n", "100 0 0 0 0 \n", "\n", "200 9 6 1 0 \n", "\n", "500 1 1 1 0 \n", "\n", "600 1 0 0 0 \n", "\n", "\n", "\n", "\n", "\n", "Overall Statistics : \n", "\n", "95% CI (0.14096,0.55904)\n", "AUNP None\n", "AUNU None\n", "Bennett S 0.13333\n", "CBA 0.17708\n", "Chi-Squared None\n", "Chi-Squared DF 9\n", "Conditional Entropy 1.23579\n", "Cramer V None\n", "Cross Entropy 1.70995\n", "Gwet AC1 0.19505\n", "Hamming Loss 0.65\n", "Joint Entropy 2.11997\n", "KL Divergence None\n", "Kappa 0.07801\n", "Kappa 95% CI (-0.2185,0.37453)\n", "Kappa No Prevalence -0.3\n", "Kappa Standard Error 0.15128\n", "Kappa Unbiased -0.12554\n", "Lambda A 0.0\n", "Lambda B 0.0\n", "Mutual Information 0.10088\n", "NIR 0.8\n", "Overall ACC 0.35\n", "Overall CEN 0.3648\n", "Overall J (0.60294,0.15074)\n", "Overall MCC 0.12642\n", "Overall MCEN 0.37463\n", "Overall RACC 0.295\n", "Overall RACCU 0.4225\n", "P-Value 1.0\n", "PPV Macro None\n", "PPV Micro 0.35\n", "Phi-Squared None\n", "RCI 0.11409\n", "RR 5.0\n", "Reference Entropy 0.88418\n", "Response Entropy 1.33667\n", "SOA1(Landis & Koch) Slight\n", "SOA2(Fleiss) Poor\n", "SOA3(Altman) Poor\n", "SOA4(Cicchetti) Poor\n", "Scott PI -0.12554\n", "Standard Error 0.10665\n", "TPR Macro None\n", "TPR Micro 0.35\n", "Zero-one Loss 13\n", "\n", "Class Statistics :\n", "\n", "Classes 100 200 500 600 \n", "ACC(Accuracy) 0.45 0.45 0.85 0.95 \n", "AUC(Area under the roc curve) None 0.5625 0.63725 0.5 \n", "AUCI(Auc value interpretation) None Poor Fair Poor \n", "BM(Informedness or bookmaker informedness) None 0.125 0.27451 0.0 \n", "CEN(Confusion entropy) 0.33496 0.35708 0.53895 0.0 \n", "DOR(Diagnostic odds ratio) None 1.8 8.0 None \n", "DP(Discriminant power) None 0.14074 0.4979 None \n", "DPI(Discriminant power interpretation) None Poor Poor None \n", "ERR(Error rate) 0.55 0.55 0.15 0.05 \n", "F0.5(F0.5 score) 0.0 0.68182 0.45455 0.0 \n", "F1(F1 score - harmonic mean of precision and sensitivity) 0.0 0.52174 0.4 0.0 \n", "F2(F2 score) 0.0 0.42254 0.35714 0.0 \n", "FDR(False discovery rate) 1.0 0.14286 0.5 None \n", "FN(False negative/miss/type 2 error) 0 10 2 1 \n", "FNR(Miss rate or false negative rate) None 0.625 0.66667 1.0 \n", "FOR(False omission rate) 0.0 0.76923 0.11111 0.05 \n", "FP(False positive/type 1 error/false alarm) 11 1 1 0 \n", "FPR(Fall-out or false positive rate) 0.55 0.25 0.05882 0.0 \n", "G(G-measure geometric mean of precision and sensitivity) None 0.56695 0.40825 None \n", "GI(Gini index) None 0.125 0.27451 0.0 \n", "IS(Information score) None 0.09954 1.73697 None \n", "J(Jaccard index) 0.0 0.35294 0.25 0.0 \n", "MCC(Matthews correlation coefficient) None 0.10483 0.32673 None \n", "MCEN(Modified confusion entropy) 0.33496 0.37394 0.58028 0.0 \n", "MK(Markedness) 0.0 0.08791 0.38889 None \n", "N(Condition negative) 20 4 17 19 \n", "NLR(Negative likelihood ratio) None 0.83333 0.70833 1.0 \n", "NPV(Negative predictive value) 1.0 0.23077 0.88889 0.95 \n", "P(Condition positive or support) 0 16 3 1 \n", "PLR(Positive likelihood ratio) None 1.5 5.66667 None \n", "PLRI(Positive likelihood ratio interpretation) None Poor Fair None \n", "POP(Population) 20 20 20 20 \n", "PPV(Precision or positive predictive value) 0.0 0.85714 0.5 None \n", "PRE(Prevalence) 0.0 0.8 0.15 0.05 \n", "RACC(Random accuracy) 0.0 0.28 0.015 0.0 \n", "RACCU(Random accuracy unbiased) 0.07563 0.33062 0.01562 0.00063 \n", "TN(True negative/correct rejection) 9 3 16 19 \n", "TNR(Specificity or true negative rate) 0.45 0.75 0.94118 1.0 \n", "TON(Test outcome negative) 9 13 18 20 \n", "TOP(Test outcome positive) 11 7 2 0 \n", "TP(True positive/hit) 0 6 1 0 \n", "TPR(Sensitivity, recall, hit rate, or true positive rate) None 0.375 0.33333 0.0 \n", "Y(Youden index) None 0.125 0.27451 0.0 \n", "dInd(Distance index) None 0.67315 0.66926 1.0 \n", "sInd(Similarity index) None 0.52401 0.52676 0.29289 \n", "\n" ] } ], "source": [ "print(cm)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Save" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'Message': 'D:\\\\For Asus Laptop\\\\projects\\\\pycm\\\\Document\\\\cm.obj',\n", " 'Status': True}" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cm.save_obj(\"cm\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Load" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "pycm.ConfusionMatrix(classes: [100, 200, 500, 600])" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cm_load = ConfusionMatrix(file=open(\"cm.obj\",\"r\"))\n", "cm" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Predict 100 200 500 600 \n", "Actual\n", "100 0 0 0 0 \n", "\n", "200 9 6 1 0 \n", "\n", "500 1 1 1 0 \n", "\n", "600 1 0 0 0 \n", "\n", "\n", "\n", "\n", "\n", "Overall Statistics : \n", "\n", "95% CI (0.14096,0.55904)\n", "AUNP None\n", "AUNU None\n", "Bennett S 0.13333\n", "CBA 0.17708\n", "Chi-Squared None\n", "Chi-Squared DF 9\n", "Conditional Entropy 1.23579\n", "Cramer V None\n", "Cross Entropy 1.70995\n", "Gwet AC1 0.19505\n", "Hamming Loss 0.65\n", "Joint Entropy 2.11997\n", "KL Divergence None\n", "Kappa 0.07801\n", "Kappa 95% CI (-0.2185,0.37453)\n", "Kappa No Prevalence -0.3\n", "Kappa Standard Error 0.15128\n", "Kappa Unbiased -0.12554\n", "Lambda A 0.0\n", "Lambda B 0.0\n", "Mutual Information 0.10088\n", "NIR 0.8\n", "Overall ACC 0.35\n", "Overall CEN 0.3648\n", "Overall J (0.60294,0.15074)\n", "Overall MCC 0.12642\n", "Overall MCEN 0.37463\n", "Overall RACC 0.295\n", "Overall RACCU 0.4225\n", "P-Value 1.0\n", "PPV Macro None\n", "PPV Micro 0.35\n", "Phi-Squared None\n", "RCI 0.11409\n", "RR 5.0\n", "Reference Entropy 0.88418\n", "Response Entropy 1.33667\n", "SOA1(Landis & Koch) Slight\n", "SOA2(Fleiss) Poor\n", "SOA3(Altman) Poor\n", "SOA4(Cicchetti) Poor\n", "Scott PI -0.12554\n", "Standard Error 0.10665\n", "TPR Macro None\n", "TPR Micro 0.35\n", "Zero-one Loss 13\n", "\n", "Class Statistics :\n", "\n", "Classes 100 200 500 600 \n", "ACC(Accuracy) 0.45 0.45 0.85 0.95 \n", "AUC(Area under the roc curve) None 0.5625 0.63725 0.5 \n", "AUCI(Auc value interpretation) None Poor Fair Poor \n", "BM(Informedness or bookmaker informedness) None 0.125 0.27451 0.0 \n", "CEN(Confusion entropy) 0.33496 0.35708 0.53895 0.0 \n", "DOR(Diagnostic odds ratio) None 1.8 8.0 None \n", "DP(Discriminant power) None 0.14074 0.4979 None \n", "DPI(Discriminant power interpretation) None Poor Poor None \n", "ERR(Error rate) 0.55 0.55 0.15 0.05 \n", "F0.5(F0.5 score) 0.0 0.68182 0.45455 0.0 \n", "F1(F1 score - harmonic mean of precision and sensitivity) 0.0 0.52174 0.4 0.0 \n", "F2(F2 score) 0.0 0.42254 0.35714 0.0 \n", "FDR(False discovery rate) 1.0 0.14286 0.5 None \n", "FN(False negative/miss/type 2 error) 0 10 2 1 \n", "FNR(Miss rate or false negative rate) None 0.625 0.66667 1.0 \n", "FOR(False omission rate) 0.0 0.76923 0.11111 0.05 \n", "FP(False positive/type 1 error/false alarm) 11 1 1 0 \n", "FPR(Fall-out or false positive rate) 0.55 0.25 0.05882 0.0 \n", "G(G-measure geometric mean of precision and sensitivity) None 0.56695 0.40825 None \n", "GI(Gini index) None 0.125 0.27451 0.0 \n", "IS(Information score) None 0.09954 1.73697 None \n", "J(Jaccard index) 0.0 0.35294 0.25 0.0 \n", "MCC(Matthews correlation coefficient) None 0.10483 0.32673 None \n", "MCEN(Modified confusion entropy) 0.33496 0.37394 0.58028 0.0 \n", "MK(Markedness) 0.0 0.08791 0.38889 None \n", "N(Condition negative) 20 4 17 19 \n", "NLR(Negative likelihood ratio) None 0.83333 0.70833 1.0 \n", "NPV(Negative predictive value) 1.0 0.23077 0.88889 0.95 \n", "P(Condition positive or support) 0 16 3 1 \n", "PLR(Positive likelihood ratio) None 1.5 5.66667 None \n", "PLRI(Positive likelihood ratio interpretation) None Poor Fair None \n", "POP(Population) 20 20 20 20 \n", "PPV(Precision or positive predictive value) 0.0 0.85714 0.5 None \n", "PRE(Prevalence) 0.0 0.8 0.15 0.05 \n", "RACC(Random accuracy) 0.0 0.28 0.015 0.0 \n", "RACCU(Random accuracy unbiased) 0.07563 0.33062 0.01562 0.00063 \n", "TN(True negative/correct rejection) 9 3 16 19 \n", "TNR(Specificity or true negative rate) 0.45 0.75 0.94118 1.0 \n", "TON(Test outcome negative) 9 13 18 20 \n", "TOP(Test outcome positive) 11 7 2 0 \n", "TP(True positive/hit) 0 6 1 0 \n", "TPR(Sensitivity, recall, hit rate, or true positive rate) None 0.375 0.33333 0.0 \n", "Y(Youden index) None 0.125 0.27451 0.0 \n", "dInd(Distance index) None 0.67315 0.66926 1.0 \n", "sInd(Similarity index) None 0.52401 0.52676 0.29289 \n", "\n" ] } ], "source": [ "print(cm)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Obj File" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{\"Actual-Vector\": [600, 200, 200, 200, 200, 200, 200, 200, 500, 500, 500, 200, 200, 200, 200, 200, 200, 200, 200, 200], \"Predict-Vector\": [100, 200, 200, 100, 100, 200, 200, 200, 100, 200, 500, 100, 100, 100, 100, 100, 100, 100, 500, 200], \"Matrix\": [[100, [[200, 0], [500, 0], [100, 0], [600, 0]]], [200, [[200, 6], [500, 1], [100, 9], [600, 0]]], [500, [[200, 1], [500, 1], [100, 1], [600, 0]]], [600, [[200, 0], [500, 0], [100, 1], [600, 0]]]], \"Transpose\": false, \"Sample-Weight\": null, \"Digit\": 5}\n" ] } ], "source": [ "print(open(\"cm.obj\",\"r\").read())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.5.2" } }, "nbformat": 4, "nbformat_minor": 2 }