{ "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", "200 9 6 1 0 \n", "500 1 1 1 0 \n", "600 1 0 0 0 \n", "\n", "\n", "\n", "\n", "Overall Statistics : \n", "\n", "95% CI (0.14096,0.55904)\n", "Bennett_S 0.13333\n", "Chi-Squared None\n", "Chi-Squared DF 9\n", "Conditional Entropy None\n", "Cramer_V None\n", "Cross Entropy None\n", "Gwet_AC1 0.19505\n", "Joint Entropy None\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 None\n", "Lambda B None\n", "Mutual Information None\n", "Overall_ACC 0.35\n", "Overall_J (0.60294,0.15074)\n", "Overall_RACC 0.295\n", "Overall_RACCU 0.4225\n", "PPV_Macro None\n", "PPV_Micro 0.35\n", "Phi-Squared None\n", "Reference Entropy None\n", "Response Entropy None\n", "Scott_PI -0.12554\n", "Standard Error 0.10665\n", "Strength_Of_Agreement(Altman) Poor\n", "Strength_Of_Agreement(Cicchetti) Poor\n", "Strength_Of_Agreement(Fleiss) Poor\n", "Strength_Of_Agreement(Landis and Koch) Slight\n", "TPR_Macro None\n", "TPR_Micro 0.35\n", "\n", "Class Statistics :\n", "\n", "Classes 100 200 500 600 \n", "ACC(Accuracy) 0.45 0.45 0.85 0.95 \n", "BM(Informedness or bookmaker informedness) None 0.125 0.27451 0.0 \n", "DOR(Diagnostic odds ratio) None 1.8 8.0 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", "J(Jaccard index) 0.0 0.35294 0.25 0.0 \n", "LR+(Positive likelihood ratio) None 1.5 5.66667 None \n", "LR-(Negative likelihood ratio) None 0.83333 0.70833 1.0 \n", "MCC(Matthews correlation coefficient) None 0.10483 0.32673 None \n", "MK(Markedness) 0.0 0.08791 0.38889 None \n", "N(Condition negative) 20 4 17 19 \n", "NPV(Negative predictive value) 1.0 0.23077 0.88889 0.95 \n", "P(Condition positive) 0 16 3 1 \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", "\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", "200 9 6 1 0 \n", "500 1 1 1 0 \n", "600 1 0 0 0 \n", "\n", "\n", "\n", "\n", "Overall Statistics : \n", "\n", "95% CI (0.14096,0.55904)\n", "Bennett_S 0.13333\n", "Chi-Squared None\n", "Chi-Squared DF 9\n", "Conditional Entropy None\n", "Cramer_V None\n", "Cross Entropy None\n", "Gwet_AC1 0.19505\n", "Joint Entropy None\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 None\n", "Lambda B None\n", "Mutual Information None\n", "Overall_ACC 0.35\n", "Overall_J (0.60294,0.15074)\n", "Overall_RACC 0.295\n", "Overall_RACCU 0.4225\n", "PPV_Macro None\n", "PPV_Micro 0.35\n", "Phi-Squared None\n", "Reference Entropy None\n", "Response Entropy None\n", "Scott_PI -0.12554\n", "Standard Error 0.10665\n", "Strength_Of_Agreement(Altman) Poor\n", "Strength_Of_Agreement(Cicchetti) Poor\n", "Strength_Of_Agreement(Fleiss) Poor\n", "Strength_Of_Agreement(Landis and Koch) Slight\n", "TPR_Macro None\n", "TPR_Micro 0.35\n", "\n", "Class Statistics :\n", "\n", "Classes 100 200 500 600 \n", "ACC(Accuracy) 0.45 0.45 0.85 0.95 \n", "BM(Informedness or bookmaker informedness) None 0.125 0.27451 0.0 \n", "DOR(Diagnostic odds ratio) None 1.8 8.0 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", "J(Jaccard index) 0.0 0.35294 0.25 0.0 \n", "LR+(Positive likelihood ratio) None 1.5 5.66667 None \n", "LR-(Negative likelihood ratio) None 0.83333 0.70833 1.0 \n", "MCC(Matthews correlation coefficient) None 0.10483 0.32673 None \n", "MK(Markedness) 0.0 0.08791 0.38889 None \n", "N(Condition negative) 20 4 17 19 \n", "NPV(Negative predictive value) 1.0 0.23077 0.88889 0.95 \n", "P(Condition positive) 0 16 3 1 \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", "\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": [ "{\"Predict-Vector\": [100, 200, 200, 100, 100, 200, 200, 200, 100, 200, 500, 100, 100, 100, 100, 100, 100, 100, 500, 200], \"Digit\": 5, \"Actual-Vector\": [600, 200, 200, 200, 200, 200, 200, 200, 500, 500, 500, 200, 200, 200, 200, 200, 200, 200, 200, 200], \"Matrix\": {\"200\": {\"200\": 6, \"100\": 9, \"500\": 1, \"600\": 0}, \"500\": {\"200\": 1, \"100\": 1, \"500\": 1, \"600\": 0}, \"100\": {\"200\": 0, \"100\": 0, \"500\": 0, \"600\": 0}, \"600\": {\"200\": 0, \"100\": 1, \"500\": 0, \"600\": 0}}}\n" ] } ], "source": [ "print(open(\"cm.obj\",\"r\").read())" ] } ], "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 }