{ "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", "1 0 4 \n", "\n", "\n", "\n", "\n", "Overall Statistics : \n", "\n", "95% CI (0.53513,1.13154)\n", "Bennett_S 0.66667\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", "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", "Overall_ACC 0.83333\n", "Overall_J (1.3,0.65)\n", "Overall_RACC 0.61111\n", "Overall_RACCU 0.625\n", "PPV_Macro 0.9\n", "PPV_Micro 0.83333\n", "Phi-Squared 0.4\n", "Reference Entropy 0.9183\n", "Response Entropy 0.65002\n", "Scott_PI 0.55556\n", "Standard Error 0.15215\n", "Strength_Of_Agreement(Altman) Moderate\n", "Strength_Of_Agreement(Cicchetti) Fair\n", "Strength_Of_Agreement(Fleiss) Intermediate to Good\n", "Strength_Of_Agreement(Landis and Koch) Moderate\n", "TPR_Macro 0.75\n", "TPR_Micro 0.83333\n", "\n", "Class Statistics :\n", "\n", "Classes 0 1 \n", "ACC(Accuracy) 0.83333 0.83333 \n", "BM(Informedness or bookmaker informedness) 0.5 0.5 \n", "DOR(Diagnostic odds ratio) 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", "J(Jaccard index) 0.5 0.8 \n", "LR+(Positive likelihood ratio) None 2.0 \n", "LR-(Negative likelihood ratio) 0.5 0.0 \n", "MCC(Matthews correlation coefficient) 0.63246 0.63246 \n", "MK(Markedness) 0.8 0.8 \n", "N(Condition negative) 4 2 \n", "NPV(Negative predictive value) 0.8 1.0 \n", "P(Condition positive) 2 4 \n", "POP(Population) 6 6 \n", "PPV(Precision or positive predictive value) 1.0 0.8 \n", "PRE(Prevalence) 0.33333 0.66667 \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", "\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 }