{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# The Confusion Matrix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "##Two class Confusion Matrix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[5 1]\n",
      " [8 2]]\n",
      "              precision    recall  f1-score   support\n",
      "\n",
      "         Cat      0.385     0.833     0.526         6\n",
      "        Fish      0.667     0.200     0.308        10\n",
      "\n",
      "    accuracy                          0.438        16\n",
      "   macro avg      0.526     0.517     0.417        16\n",
      "weighted avg      0.561     0.438     0.390        16\n",
      "\n",
      "0.4375\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "list"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "from sklearn import metrics\n",
    "\n",
    "# Constants\n",
    "C = \"Cat\"\n",
    "F = \"Fish\"\n",
    "\n",
    "\n",
    "# True values\n",
    "y_true = [C, C, C, C, C, C, F, F, F, F, F, F, F, F, F, F]\n",
    "# Predicted values\n",
    "y_pred = [C, C, C, C, F, C, C, C, C, C, C, F, F, C, C, C,]\n",
    "\n",
    "# Print the confusion matrix\n",
    "print(metrics.confusion_matrix(y_true, y_pred))\n",
    "\n",
    "# Print the precision and recall, among other metrics\n",
    "print(metrics.classification_report(y_true, y_pred, digits=3))\n",
    "print(metrics.accuracy_score(y_true, y_pred))\n",
    "type(y_true)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Multi-class Confusion Matrix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[4 1 1]\n",
      " [6 2 2]\n",
      " [3 0 6]]\n",
      "              precision    recall  f1-score   support\n",
      "\n",
      "         Cat      0.308     0.667     0.421         6\n",
      "        Fish      0.667     0.200     0.308        10\n",
      "         Hen      0.667     0.667     0.667         9\n",
      "\n",
      "    accuracy                          0.480        25\n",
      "   macro avg      0.547     0.511     0.465        25\n",
      "weighted avg      0.581     0.480     0.464        25\n",
      "\n"
     ]
    }
   ],
   "source": [
    "\n",
    "from sklearn import metrics\n",
    "\n",
    "# Constants\n",
    "C = \"Cat\"\n",
    "F = \"Fish\"\n",
    "H = \"Hen\"\n",
    "\n",
    "# True values\n",
    "y_true = [C, C, C, C, C, C, F, F, F, F, F, F, F, F, F, F, H, H, H, H, H, H, H, H, H]\n",
    "# Predicted values\n",
    "y_pred = [C, C, C, C, H, F, C, C, C, C, C, C, H, H, F, F, C, C, C, H, H, H, H, H, H]\n",
    "\n",
    "# Print the confusion matrix\n",
    "print(metrics.confusion_matrix(y_true, y_pred))\n",
    "\n",
    "# Print the precision and recall, among other metrics\n",
    "print(metrics.classification_report(y_true, y_pred, digits=3))\n",
    "\n"
   ]
  }
 ],
 "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.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
