{"nbformat": 4, "metadata": {"kernelspec": {"name": "python3", "language": "python", "display_name": "Python 3"}, "language_info": {"codemirror_mode": {"name": "ipython", "version": 3}, "file_extension": ".py", "nbconvert_exporter": "python", "name": "python", "pygments_lexer": "ipython3", "version": "3.6.4", "mimetype": "text/x-python"}}, "cells": [{"source": ["# This Python 3 environment comes with many helpful analytics libraries installed\n", "# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python\n", "# For example, here's several helpful packages to load in \n", "\n", "import numpy as np # linear algebra\n", "import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n", "\n", "# Input data files are available in the \"../input/\" directory.\n", "# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\n", "\n", "from subprocess import check_output\n", "print(check_output([\"ls\", \"../input\"]).decode(\"utf8\"))\n", "\n", "# Any results you write to the current directory are saved as output."], "execution_count": null, "metadata": {"_cell_guid": "d03816c8-9891-46f4-92e5-a90d8866cecd", "_uuid": "0032aa26934cbc9a6c35f8ef4599d25dc11862dc"}, "cell_type": "code", "outputs": []}, {"source": ["import os\n", "import shutil\n", "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "import random\n", "import matplotlib.image as mpimg\n", "\n", "%matplotlib inline"], "execution_count": null, "metadata": {"collapsed": true}, "cell_type": "code", "outputs": []}, {"source": ["df = pd.read_csv('../input/labels.csv')\n", "\n", "df.head()"], "execution_count": null, "metadata": {}, "cell_type": "code", "outputs": []}, {"source": ["headers = list(df)\n", "\n", "print(headers)"], "execution_count": null, "metadata": {}, "cell_type": "code", "outputs": []}, {"source": ["# Number of images per class\n", "gr_labels = df.groupby(\"breed\").count()\n", "gr_labels = gr_labels.rename(columns = {\"id\" : \"count\"})\n", "images_count = list(gr_labels['count'])\n", "\n", "gr_labels.sort_values(\"count\", ascending=False).head()"], "execution_count": null, "metadata": {}, "cell_type": "code", "outputs": []}, {"source": ["gr_labels.sort_values(\"count\", ascending=False).tail()"], "execution_count": null, "metadata": {}, "cell_type": "code", "outputs": []}, {"source": ["classes = np.unique(df[\"breed\"]).reshape(120, 1)\n", "\n", "avg = sum(images_count) / float(len(images_count))\n", "colors = []\n", "for i in range(0, len(images_count)):\n", "    images_count[i] = images_count[i] - avg\n", "    if images_count[i] < 0:\n", "        colors.append('r')\n", "    else:\n", "        colors.append('b')\n", "        \n", "plt.figure(figsize=(20,10))\n", "\n", "y_pos = np.arange(len(classes))\n", "plt.axhline(y = 0,color='grey') \n", "plt.bar(y_pos, images_count, align='center', color = colors, alpha=0.5, width = 0.3)\n", "plt.ylabel('Deviation from average value')\n", "plt.xlabel('Classes')\n", "plt.title('Distribution of training images')\n", "\n", "for i, v in enumerate(images_count):\n", "    if v < 0:\n", "        yd = -1.5\n", "    else:\n", "        yd = 1.5\n", "    n = int(v + avg)\n", "    plt.text(i-0.75, v + yd, str(n), color='blue')\n", "\n", "plt.show()"], "execution_count": null, "metadata": {}, "cell_type": "code", "outputs": []}], "nbformat_minor": 1}