{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Identifying Clusters\n",
    "\n",
    "Before we get too far along, let's take a look at some different sets of data to practice identifying clusters.\n",
    "\n",
    "Start by running the cell below."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from mpl_toolkits.mplot3d import Axes3D\n",
    "from sklearn.cluster import KMeans\n",
    "from sklearn.datasets import make_blobs\n",
    "import helper_functions as h\n",
    "import test_file as t\n",
    "from IPython import display\n",
    "\n",
    "%matplotlib inline\n",
    "\n",
    "# Make the images larger\n",
    "plt.rcParams['figure.figsize'] = (16, 9)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`1.` Run the cell below to generate a set of data.  Then enter an integer next to **`question_1_clusters`** that identifies the number of clusters you think appear in the plot.\n",
    "\n",
    "If you think that there are 2 clusters in the plot, you should enter:\n",
    "\n",
    "```\n",
    "question_1_clusters = 2\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 69060 characters]\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f9808633eb8>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "h.plot_q1_data()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "That's right!  There are 4 clusters in this dataset.\n"
     ]
    }
   ],
   "source": [
    "question_1_clusters = 4\n",
    "\n",
    "#Then this will test your number against what we used to generate the data\n",
    "t.test_question_1(question_1_clusters)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`2.` Run the cell below to generate a set of data.  Then, similar to the first question, enter the number of clusters you think appear in the plot."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 11052 characters]\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f97d68f01d0>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "h.plot_q2_data()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "That's right!  There are 2 clusters in this dataset.\n"
     ]
    }
   ],
   "source": [
    "question_2_clusters = 2\n",
    "\n",
    "#Then this will test your number against what we used to generate the data\n",
    "t.test_question_2(question_2_clusters)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`3.` Run the cell below to generate a set of data.  Then, similar to the previous questions, enter the number of clusters you think appear in the plot."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 67164 characters]\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f97d68a6cc0>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "h.plot_q3_data()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6 is a reasonable guess for a the number of clusters here.  In the next question, you will see a different angle of this data.\n"
     ]
    }
   ],
   "source": [
    "question_3_clusters = 6\n",
    "\n",
    "#Then this will test your number against what we used to generate the data\n",
    "t.test_question_3(question_3_clusters)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`4.` Now one final time, run the cell below, and identify the number of clusters you think are in the plot created. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 84704 characters]\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f97d4fc36a0>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "h.plot_q4_data()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "This data is actually the same as the data used in question 3.  Isn't it crazy how looking at data from a different angle can make us believe there are a different number of clusters in the data!  We will look at how to address this in the upcoming parts of this lesson.\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<img src=\"http://www.reactiongifs.com/wp-content/uploads/2013/03/mind-blown.gif\">"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "question_4_clusters = 7\n",
    "\n",
    "#Then this will test your number against what we used to generate the data\n",
    "display.HTML(t.test_question_4(question_4_clusters))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "**You can find a solution to this by clicking the orange jupyter image at the top of this notebook.**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "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.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
