{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Example-3 (Activation threshold)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from pycm import ConfusionMatrix\n", "\n", "def activation_1(i):\n", " if i<0.75:\n", " return 1\n", " else:\n", " return 0" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "y_actual = [1,1,0,1,1,0]\n", "y_pred = [0.65,0.34,0.80,0.54,0.32,0.12]" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[0, 1]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cm = ConfusionMatrix(y_actual,y_pred,threshold=activation_1)\n", "cm.classes" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Predict 0 1 \n", "Actual\n", "0 1 1 \n", "\n", "1 0 4 \n", "\n", "\n", "\n", "\n", "\n", "Overall Statistics : \n", "\n", "95% CI (0.53513,1.13154)\n", "AUNP 0.75\n", "AUNU 0.75\n", "Bennett S 0.66667\n", "CBA 0.65\n", "Chi-Squared 2.4\n", "Chi-Squared DF 1\n", "Conditional Entropy 0.33333\n", "Cramer V 0.63246\n", "Cross Entropy 1.03701\n", "Gwet AC1 0.73333\n", "Hamming Loss 0.16667\n", "Joint Entropy 1.25163\n", "KL Divergence 0.11871\n", "Kappa 0.57143\n", "Kappa 95% CI (-0.19538,1.33824)\n", "Kappa No Prevalence 0.66667\n", "Kappa Standard Error 0.39123\n", "Kappa Unbiased 0.55556\n", "Lambda A 0.5\n", "Lambda B 0.0\n", "Mutual Information 0.31669\n", "NIR 0.66667\n", "Overall ACC 0.83333\n", "Overall CEN 0.39624\n", "Overall J (1.3,0.65)\n", "Overall MCC 0.63246\n", "Overall MCEN 0.27683\n", "Overall RACC 0.61111\n", "Overall RACCU 0.625\n", "P-Value 0.35117\n", "PPV Macro 0.9\n", "PPV Micro 0.83333\n", "Pearson C 0.53452\n", "Phi-Squared 0.4\n", "RCI 0.34487\n", "RR 3.0\n", "Reference Entropy 0.9183\n", "Response Entropy 0.65002\n", "SOA1(Landis & Koch) Moderate\n", "SOA2(Fleiss) Intermediate to Good\n", "SOA3(Altman) Moderate\n", "SOA4(Cicchetti) Fair\n", "Scott PI 0.55556\n", "Standard Error 0.15215\n", "TPR Macro 0.75\n", "TPR Micro 0.83333\n", "Zero-one Loss 1\n", "\n", "Class Statistics :\n", "\n", "Classes 0 1 \n", "ACC(Accuracy) 0.83333 0.83333 \n", "AGM(Adjusted geometric mean) 0.82426 0.65533 \n", "AM(Difference between automatic and manual classification) -1 1 \n", "AUC(Area under the roc curve) 0.75 0.75 \n", "AUCI(AUC value interpretation) Good Good \n", "BCD(Bray-Curtis dissimilarity) 0.08333 0.08333 \n", "BM(Informedness or bookmaker informedness) 0.5 0.5 \n", "CEN(Confusion entropy) 0.52832 0.35221 \n", "DOR(Diagnostic odds ratio) None None \n", "DP(Discriminant power) None None \n", "DPI(Discriminant power interpretation) None None \n", "ERR(Error rate) 0.16667 0.16667 \n", "F0.5(F0.5 score) 0.83333 0.83333 \n", "F1(F1 score - harmonic mean of precision and sensitivity) 0.66667 0.88889 \n", "F2(F2 score) 0.55556 0.95238 \n", "FDR(False discovery rate) 0.0 0.2 \n", "FN(False negative/miss/type 2 error) 1 0 \n", "FNR(Miss rate or false negative rate) 0.5 0.0 \n", "FOR(False omission rate) 0.2 0.0 \n", "FP(False positive/type 1 error/false alarm) 0 1 \n", "FPR(Fall-out or false positive rate) 0.0 0.5 \n", "G(G-measure geometric mean of precision and sensitivity) 0.70711 0.89443 \n", "GI(Gini index) 0.5 0.5 \n", "GM(G-mean geometric mean of specificity and sensitivity) 0.70711 0.70711 \n", "IBA(Index of balanced accuracy) 0.25 0.75 \n", "IS(Information score) 1.58496 0.26303 \n", "J(Jaccard index) 0.5 0.8 \n", "LS(Lift score) 3.0 1.2 \n", "MCC(Matthews correlation coefficient) 0.63246 0.63246 \n", "MCEN(Modified confusion entropy) 0.5 0.46439 \n", "MK(Markedness) 0.8 0.8 \n", "N(Condition negative) 4 2 \n", "NLR(Negative likelihood ratio) 0.5 0.0 \n", "NPV(Negative predictive value) 0.8 1.0 \n", "OP(Optimized precision) 0.5 0.5 \n", "P(Condition positive or support) 2 4 \n", "PLR(Positive likelihood ratio) None 2.0 \n", "PLRI(Positive likelihood ratio interpretation) None Poor \n", "POP(Population) 6 6 \n", "PPV(Precision or positive predictive value) 1.0 0.8 \n", "PRE(Prevalence) 0.33333 0.66667 \n", "Q(Yule Q - coefficient of colligation) None None \n", "RACC(Random accuracy) 0.05556 0.55556 \n", "RACCU(Random accuracy unbiased) 0.0625 0.5625 \n", "TN(True negative/correct rejection) 4 1 \n", "TNR(Specificity or true negative rate) 1.0 0.5 \n", "TON(Test outcome negative) 5 1 \n", "TOP(Test outcome positive) 1 5 \n", "TP(True positive/hit) 1 4 \n", "TPR(Sensitivity, recall, hit rate, or true positive rate) 0.5 1.0 \n", "Y(Youden index) 0.5 0.5 \n", "dInd(Distance index) 0.5 0.5 \n", "sInd(Similarity index) 0.64645 0.64645 \n", "\n" ] } ], "source": [ "print(cm)" ] } ], "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 }