{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "EDA_Classifier_Streamlit.ipynb",
      "provenance": [],
      "collapsed_sections": [],
      "toc_visible": true,
      "mount_file_id": "1tFH-kv8gBhvmJXgHdy_HnPAiw4i4JzKU",
      "authorship_tag": "ABX9TyN5D4mMaguqn0pOjNTwqsgX",
      "include_colab_link": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/mrm8488/shared_colab_notebooks/blob/master/EDA_Classifier_Streamlit.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "xbhK4dSDP4rO",
        "colab_type": "text"
      },
      "source": [
        "# EDA + Classifier + Streamlit on *Palmer Penguin* dataset\n",
        "\n",
        "> Colab Author: [Manuel Romero/mrm8488](https://twitter.com/mrm8488)\n",
        "\n",
        "> Idea and streamlit code: https://github.com/dataprofessor/penguins-heroku"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "j4qNgk83CKTN",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 225
        },
        "outputId": "795ce97d-f5e6-41ac-abc8-960bda629015"
      },
      "source": [
        "!pip install -q streamlit"
      ],
      "execution_count": 1,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "\u001b[K     |████████████████████████████████| 7.1MB 2.6MB/s \n",
            "\u001b[K     |████████████████████████████████| 112kB 40.2MB/s \n",
            "\u001b[K     |████████████████████████████████| 102kB 11.8MB/s \n",
            "\u001b[K     |████████████████████████████████| 501kB 49.0MB/s \n",
            "\u001b[K     |████████████████████████████████| 4.4MB 47.2MB/s \n",
            "\u001b[K     |████████████████████████████████| 122kB 50.4MB/s \n",
            "\u001b[?25h  Building wheel for blinker (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "  Building wheel for watchdog (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "  Building wheel for validators (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "  Building wheel for tornado (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "  Building wheel for pathtools (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "\u001b[31mERROR: google-colab 1.0.0 has requirement ipykernel~=4.10, but you'll have ipykernel 5.3.1 which is incompatible.\u001b[0m\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "au_2MARsCqJf",
        "colab_type": "text"
      },
      "source": [
        "Reset the exectuion environment after installing **streamlit**"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "eWDsgXuqDQKl",
        "colab_type": "text"
      },
      "source": [
        "## Download the dataset (already cleaned)"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "mKJmTEW3Be_F",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 208
        },
        "outputId": "8e692989-62ac-4c63-a1ff-764e770c6173"
      },
      "source": [
        "!wget https://raw.githubusercontent.com/dataprofessor/penguins-heroku/master/penguins_cleaned.csv"
      ],
      "execution_count": 1,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "--2020-07-08 10:31:12--  https://raw.githubusercontent.com/dataprofessor/penguins-heroku/master/penguins_cleaned.csv\n",
            "Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.0.133, 151.101.64.133, 151.101.128.133, ...\n",
            "Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.0.133|:443... connected.\n",
            "HTTP request sent, awaiting response... 200 OK\n",
            "Length: 15134 (15K) [text/plain]\n",
            "Saving to: ‘penguins_cleaned.csv’\n",
            "\n",
            "\rpenguins_cleaned.cs   0%[                    ]       0  --.-KB/s               \rpenguins_cleaned.cs 100%[===================>]  14.78K  --.-KB/s    in 0.01s   \n",
            "\n",
            "2020-07-08 10:31:12 (1.21 MB/s) - ‘penguins_cleaned.csv’ saved [15134/15134]\n",
            "\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "XVfuvB4NC5-h",
        "colab_type": "text"
      },
      "source": [
        "## A bit of EDA"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "avIXZsYuAB-O",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "import pandas as pd"
      ],
      "execution_count": 2,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "RDGuqdEnBjeI",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "data = pd.read_csv('penguins_cleaned.csv')"
      ],
      "execution_count": 3,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "bt1ttzO1Bn5R",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 424
        },
        "outputId": "ffe70342-f6e3-465f-8f50-b17bb913fdcd"
      },
      "source": [
        "data"
      ],
      "execution_count": 4,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>species</th>\n",
              "      <th>island</th>\n",
              "      <th>bill_length_mm</th>\n",
              "      <th>bill_depth_mm</th>\n",
              "      <th>flipper_length_mm</th>\n",
              "      <th>body_mass_g</th>\n",
              "      <th>sex</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>Adelie</td>\n",
              "      <td>Torgersen</td>\n",
              "      <td>39.1</td>\n",
              "      <td>18.7</td>\n",
              "      <td>181</td>\n",
              "      <td>3750</td>\n",
              "      <td>male</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>Adelie</td>\n",
              "      <td>Torgersen</td>\n",
              "      <td>39.5</td>\n",
              "      <td>17.4</td>\n",
              "      <td>186</td>\n",
              "      <td>3800</td>\n",
              "      <td>female</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>Adelie</td>\n",
              "      <td>Torgersen</td>\n",
              "      <td>40.3</td>\n",
              "      <td>18.0</td>\n",
              "      <td>195</td>\n",
              "      <td>3250</td>\n",
              "      <td>female</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>Adelie</td>\n",
              "      <td>Torgersen</td>\n",
              "      <td>36.7</td>\n",
              "      <td>19.3</td>\n",
              "      <td>193</td>\n",
              "      <td>3450</td>\n",
              "      <td>female</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>Adelie</td>\n",
              "      <td>Torgersen</td>\n",
              "      <td>39.3</td>\n",
              "      <td>20.6</td>\n",
              "      <td>190</td>\n",
              "      <td>3650</td>\n",
              "      <td>male</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>...</th>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>328</th>\n",
              "      <td>Chinstrap</td>\n",
              "      <td>Dream</td>\n",
              "      <td>55.8</td>\n",
              "      <td>19.8</td>\n",
              "      <td>207</td>\n",
              "      <td>4000</td>\n",
              "      <td>male</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>329</th>\n",
              "      <td>Chinstrap</td>\n",
              "      <td>Dream</td>\n",
              "      <td>43.5</td>\n",
              "      <td>18.1</td>\n",
              "      <td>202</td>\n",
              "      <td>3400</td>\n",
              "      <td>female</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>330</th>\n",
              "      <td>Chinstrap</td>\n",
              "      <td>Dream</td>\n",
              "      <td>49.6</td>\n",
              "      <td>18.2</td>\n",
              "      <td>193</td>\n",
              "      <td>3775</td>\n",
              "      <td>male</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>331</th>\n",
              "      <td>Chinstrap</td>\n",
              "      <td>Dream</td>\n",
              "      <td>50.8</td>\n",
              "      <td>19.0</td>\n",
              "      <td>210</td>\n",
              "      <td>4100</td>\n",
              "      <td>male</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>332</th>\n",
              "      <td>Chinstrap</td>\n",
              "      <td>Dream</td>\n",
              "      <td>50.2</td>\n",
              "      <td>18.7</td>\n",
              "      <td>198</td>\n",
              "      <td>3775</td>\n",
              "      <td>female</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "<p>333 rows × 7 columns</p>\n",
              "</div>"
            ],
            "text/plain": [
              "       species     island  ...  body_mass_g     sex\n",
              "0       Adelie  Torgersen  ...         3750    male\n",
              "1       Adelie  Torgersen  ...         3800  female\n",
              "2       Adelie  Torgersen  ...         3250  female\n",
              "3       Adelie  Torgersen  ...         3450  female\n",
              "4       Adelie  Torgersen  ...         3650    male\n",
              "..         ...        ...  ...          ...     ...\n",
              "328  Chinstrap      Dream  ...         4000    male\n",
              "329  Chinstrap      Dream  ...         3400  female\n",
              "330  Chinstrap      Dream  ...         3775    male\n",
              "331  Chinstrap      Dream  ...         4100    male\n",
              "332  Chinstrap      Dream  ...         3775  female\n",
              "\n",
              "[333 rows x 7 columns]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 4
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "cwNg-rQDBwtD",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 260
        },
        "outputId": "ae407494-982e-4b5c-cb7f-4e1ec94ba801"
      },
      "source": [
        "data.info()"
      ],
      "execution_count": 5,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "<class 'pandas.core.frame.DataFrame'>\n",
            "RangeIndex: 333 entries, 0 to 332\n",
            "Data columns (total 7 columns):\n",
            " #   Column             Non-Null Count  Dtype  \n",
            "---  ------             --------------  -----  \n",
            " 0   species            333 non-null    object \n",
            " 1   island             333 non-null    object \n",
            " 2   bill_length_mm     333 non-null    float64\n",
            " 3   bill_depth_mm      333 non-null    float64\n",
            " 4   flipper_length_mm  333 non-null    int64  \n",
            " 5   body_mass_g        333 non-null    int64  \n",
            " 6   sex                333 non-null    object \n",
            "dtypes: float64(2), int64(2), object(3)\n",
            "memory usage: 18.3+ KB\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "o1JTuuUPBz1w",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 300
        },
        "outputId": "686b447a-8950-41c9-8502-f46e2c3dfb11"
      },
      "source": [
        "data.describe()"
      ],
      "execution_count": 6,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>bill_length_mm</th>\n",
              "      <th>bill_depth_mm</th>\n",
              "      <th>flipper_length_mm</th>\n",
              "      <th>body_mass_g</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>count</th>\n",
              "      <td>333.000000</td>\n",
              "      <td>333.000000</td>\n",
              "      <td>333.000000</td>\n",
              "      <td>333.000000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>mean</th>\n",
              "      <td>43.992793</td>\n",
              "      <td>17.164865</td>\n",
              "      <td>200.966967</td>\n",
              "      <td>4207.057057</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>std</th>\n",
              "      <td>5.468668</td>\n",
              "      <td>1.969235</td>\n",
              "      <td>14.015765</td>\n",
              "      <td>805.215802</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>min</th>\n",
              "      <td>32.100000</td>\n",
              "      <td>13.100000</td>\n",
              "      <td>172.000000</td>\n",
              "      <td>2700.000000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>25%</th>\n",
              "      <td>39.500000</td>\n",
              "      <td>15.600000</td>\n",
              "      <td>190.000000</td>\n",
              "      <td>3550.000000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>50%</th>\n",
              "      <td>44.500000</td>\n",
              "      <td>17.300000</td>\n",
              "      <td>197.000000</td>\n",
              "      <td>4050.000000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>75%</th>\n",
              "      <td>48.600000</td>\n",
              "      <td>18.700000</td>\n",
              "      <td>213.000000</td>\n",
              "      <td>4775.000000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>max</th>\n",
              "      <td>59.600000</td>\n",
              "      <td>21.500000</td>\n",
              "      <td>231.000000</td>\n",
              "      <td>6300.000000</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "       bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g\n",
              "count      333.000000     333.000000         333.000000   333.000000\n",
              "mean        43.992793      17.164865         200.966967  4207.057057\n",
              "std          5.468668       1.969235          14.015765   805.215802\n",
              "min         32.100000      13.100000         172.000000  2700.000000\n",
              "25%         39.500000      15.600000         190.000000  3550.000000\n",
              "50%         44.500000      17.300000         197.000000  4050.000000\n",
              "75%         48.600000      18.700000         213.000000  4775.000000\n",
              "max         59.600000      21.500000         231.000000  6300.000000"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 6
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Ojyhlcr0B166",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 86
        },
        "outputId": "866ac518-f7cb-4d4e-dac0-d0b41ce91e85"
      },
      "source": [
        "data.species.value_counts()"
      ],
      "execution_count": 7,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "Adelie       146\n",
              "Gentoo       119\n",
              "Chinstrap     68\n",
              "Name: species, dtype: int64"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 7
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "SsGjYX1pDzFK",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 282
        },
        "outputId": "9445f84e-837b-4342-cd7f-b1fff88a4cde"
      },
      "source": [
        "data.species.hist()"
      ],
      "execution_count": 8,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "<matplotlib.axes._subplots.AxesSubplot at 0x7f0c2ec11fd0>"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 8
        },
        {
          "output_type": "display_data",
          "data": {
            "image/png": "[encoded data, 6760 characters]\n",
            "text/plain": [
              "<Figure size 432x288 with 1 Axes>"
            ]
          },
          "metadata": {
            "tags": [],
            "needs_background": "light"
          }
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "CPNNFTyxDboL",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 86
        },
        "outputId": "c9361e4f-899e-49de-92c8-00d08856374d"
      },
      "source": [
        "data.island.value_counts()"
      ],
      "execution_count": 9,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "Biscoe       163\n",
              "Dream        123\n",
              "Torgersen     47\n",
              "Name: island, dtype: int64"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 9
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "wjTBc9DBDhEF",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 282
        },
        "outputId": "6cdfed59-2724-4cb5-cab8-3b3a2ab172bc"
      },
      "source": [
        "data.island.hist()"
      ],
      "execution_count": 10,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "<matplotlib.axes._subplots.AxesSubplot at 0x7f0c2eaef6a0>"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 10
        },
        {
          "output_type": "display_data",
          "data": {
            "image/png": "[encoded data, 7240 characters]\n",
            "text/plain": [
              "<Figure size 432x288 with 1 Axes>"
            ]
          },
          "metadata": {
            "tags": [],
            "needs_background": "light"
          }
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "YeeQ9dM8Fzsi",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "encode = ['sex','island']\n",
        "for col in encode:\n",
        "    dummy = pd.get_dummies(data[col], prefix=col)\n",
        "    data = pd.concat([data,dummy], axis=1)\n",
        "    del data[col]"
      ],
      "execution_count": 11,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "tNX4rVS6F3Em",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 424
        },
        "outputId": "2f1eb296-4154-404e-9e9f-205ede3d751d"
      },
      "source": [
        "data"
      ],
      "execution_count": 12,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>species</th>\n",
              "      <th>bill_length_mm</th>\n",
              "      <th>bill_depth_mm</th>\n",
              "      <th>flipper_length_mm</th>\n",
              "      <th>body_mass_g</th>\n",
              "      <th>sex_female</th>\n",
              "      <th>sex_male</th>\n",
              "      <th>island_Biscoe</th>\n",
              "      <th>island_Dream</th>\n",
              "      <th>island_Torgersen</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>Adelie</td>\n",
              "      <td>39.1</td>\n",
              "      <td>18.7</td>\n",
              "      <td>181</td>\n",
              "      <td>3750</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>Adelie</td>\n",
              "      <td>39.5</td>\n",
              "      <td>17.4</td>\n",
              "      <td>186</td>\n",
              "      <td>3800</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>Adelie</td>\n",
              "      <td>40.3</td>\n",
              "      <td>18.0</td>\n",
              "      <td>195</td>\n",
              "      <td>3250</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>Adelie</td>\n",
              "      <td>36.7</td>\n",
              "      <td>19.3</td>\n",
              "      <td>193</td>\n",
              "      <td>3450</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>Adelie</td>\n",
              "      <td>39.3</td>\n",
              "      <td>20.6</td>\n",
              "      <td>190</td>\n",
              "      <td>3650</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>...</th>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>328</th>\n",
              "      <td>Chinstrap</td>\n",
              "      <td>55.8</td>\n",
              "      <td>19.8</td>\n",
              "      <td>207</td>\n",
              "      <td>4000</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>329</th>\n",
              "      <td>Chinstrap</td>\n",
              "      <td>43.5</td>\n",
              "      <td>18.1</td>\n",
              "      <td>202</td>\n",
              "      <td>3400</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>330</th>\n",
              "      <td>Chinstrap</td>\n",
              "      <td>49.6</td>\n",
              "      <td>18.2</td>\n",
              "      <td>193</td>\n",
              "      <td>3775</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>331</th>\n",
              "      <td>Chinstrap</td>\n",
              "      <td>50.8</td>\n",
              "      <td>19.0</td>\n",
              "      <td>210</td>\n",
              "      <td>4100</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>332</th>\n",
              "      <td>Chinstrap</td>\n",
              "      <td>50.2</td>\n",
              "      <td>18.7</td>\n",
              "      <td>198</td>\n",
              "      <td>3775</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "<p>333 rows × 10 columns</p>\n",
              "</div>"
            ],
            "text/plain": [
              "       species  bill_length_mm  ...  island_Dream  island_Torgersen\n",
              "0       Adelie            39.1  ...             0                 1\n",
              "1       Adelie            39.5  ...             0                 1\n",
              "2       Adelie            40.3  ...             0                 1\n",
              "3       Adelie            36.7  ...             0                 1\n",
              "4       Adelie            39.3  ...             0                 1\n",
              "..         ...             ...  ...           ...               ...\n",
              "328  Chinstrap            55.8  ...             1                 0\n",
              "329  Chinstrap            43.5  ...             1                 0\n",
              "330  Chinstrap            49.6  ...             1                 0\n",
              "331  Chinstrap            50.8  ...             1                 0\n",
              "332  Chinstrap            50.2  ...             1                 0\n",
              "\n",
              "[333 rows x 10 columns]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 12
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "t9QO7q8TC-OL",
        "colab_type": "text"
      },
      "source": [
        "## Create the Classifier"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "J-MnsP-zQnyw",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "from sklearn.ensemble import RandomForestClassifier\n",
        "from sklearn import model_selection"
      ],
      "execution_count": 16,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Hn4oCdZVE2Is",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "clf = RandomForestClassifier()"
      ],
      "execution_count": 17,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "uIVOFCgQE-Sb",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "y = data.pop('species')"
      ],
      "execution_count": 18,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "mBiFY2g0Gjn-",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 225
        },
        "outputId": "2d5ae62c-4fe3-4f30-e34d-0a38a8874eb6"
      },
      "source": [
        "y"
      ],
      "execution_count": 19,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "0         Adelie\n",
              "1         Adelie\n",
              "2         Adelie\n",
              "3         Adelie\n",
              "4         Adelie\n",
              "         ...    \n",
              "328    Chinstrap\n",
              "329    Chinstrap\n",
              "330    Chinstrap\n",
              "331    Chinstrap\n",
              "332    Chinstrap\n",
              "Name: species, Length: 333, dtype: object"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 19
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "-C7dCqItFHDz",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "dummies = pd.get_dummies(y)\n",
        "y = pd.concat([y,dummies], axis=1)"
      ],
      "execution_count": 20,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "xPINcrlFHC0m",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "del y['species']"
      ],
      "execution_count": 21,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "4om6tNJFGqzS",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 424
        },
        "outputId": "bcce81ff-9a46-428e-83bb-51ad166076aa"
      },
      "source": [
        "y"
      ],
      "execution_count": 22,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Adelie</th>\n",
              "      <th>Chinstrap</th>\n",
              "      <th>Gentoo</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>...</th>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>328</th>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>329</th>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>330</th>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>331</th>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>332</th>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "<p>333 rows × 3 columns</p>\n",
              "</div>"
            ],
            "text/plain": [
              "     Adelie  Chinstrap  Gentoo\n",
              "0         1          0       0\n",
              "1         1          0       0\n",
              "2         1          0       0\n",
              "3         1          0       0\n",
              "4         1          0       0\n",
              "..      ...        ...     ...\n",
              "328       0          1       0\n",
              "329       0          1       0\n",
              "330       0          1       0\n",
              "331       0          1       0\n",
              "332       0          1       0\n",
              "\n",
              "[333 rows x 3 columns]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 22
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "k7t0kWGkFIXg",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "X = data"
      ],
      "execution_count": 23,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "DVLf62ERSMLJ",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "test_size = 0.33"
      ],
      "execution_count": 24,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "5fkaEHyhSd5k",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "X_train, X_test, Y_train, Y_test = model_selection.train_test_split(X, y, test_size=test_size, random_state=7)"
      ],
      "execution_count": 25,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "C8v0K_lQFNjb",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 156
        },
        "outputId": "455ffb12-22f5-4cec-8a20-ae156559362d"
      },
      "source": [
        "clf.fit(X_train, Y_train)"
      ],
      "execution_count": 26,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "RandomForestClassifier(bootstrap=True, ccp_alpha=0.0, class_weight=None,\n",
              "                       criterion='gini', max_depth=None, max_features='auto',\n",
              "                       max_leaf_nodes=None, max_samples=None,\n",
              "                       min_impurity_decrease=0.0, min_impurity_split=None,\n",
              "                       min_samples_leaf=1, min_samples_split=2,\n",
              "                       min_weight_fraction_leaf=0.0, n_estimators=100,\n",
              "                       n_jobs=None, oob_score=False, random_state=None,\n",
              "                       verbose=0, warm_start=False)"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 26
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "bFYiWGIrSr6L",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "929beb5c-7d61-4040-ed86-5c38c4ff1357"
      },
      "source": [
        "clf.score(X_test, Y_test)"
      ],
      "execution_count": 27,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "0.990909090909091"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 27
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "N0Zt50cRFskY",
        "colab_type": "text"
      },
      "source": [
        "## Manual test of the model"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Afti5yTtHoXA",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "1748aa59-c7a0-43d3-a388-e13ae735c88f"
      },
      "source": [
        "clf.predict(X[:1])"
      ],
      "execution_count": 28,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([[1, 0, 0]], dtype=uint8)"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 28
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "vtuQZv34IHmv",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 81
        },
        "outputId": "f5605866-06e6-425c-af14-4b96aa4ef248"
      },
      "source": [
        "y[:1]"
      ],
      "execution_count": 29,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Adelie</th>\n",
              "      <th>Chinstrap</th>\n",
              "      <th>Gentoo</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "   Adelie  Chinstrap  Gentoo\n",
              "0       1          0       0"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 29
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "qe8Zw-OGID4m",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "17b7f1c8-6e2e-4e93-cdbc-3ebdaf1eba4a"
      },
      "source": [
        "clf.predict(X[-1:])"
      ],
      "execution_count": 30,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([[0, 1, 0]], dtype=uint8)"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 30
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "F4r5ei4XPRfm",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "6ae61b32-0f6e-42bc-8699-16890170c16b"
      },
      "source": [
        "clf.predict_proba(X[-1:])"
      ],
      "execution_count": 72,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "[array([[1., 0.]]), array([[0., 1.]]), array([[1., 0.]])]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 72
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "vtxrltytIho4",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 81
        },
        "outputId": "c1e16621-86c9-473d-ab85-88a6dbeafbfb"
      },
      "source": [
        "y[-1:]"
      ],
      "execution_count": 32,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Adelie</th>\n",
              "      <th>Chinstrap</th>\n",
              "      <th>Gentoo</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>332</th>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "     Adelie  Chinstrap  Gentoo\n",
              "332       0          1       0"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 32
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "GbSlh9lH_Tr0",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "4855bb53-7db4-4ac0-d8d9-424e25e50644"
      },
      "source": [
        "clf.predict(X[146:147])"
      ],
      "execution_count": 33,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([[0, 0, 1]], dtype=uint8)"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 33
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "LvE2LfBm_g6b",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 81
        },
        "outputId": "f84fac76-0b19-4d94-d3a3-49dc080d0445"
      },
      "source": [
        "y[146:147]"
      ],
      "execution_count": 35,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Adelie</th>\n",
              "      <th>Chinstrap</th>\n",
              "      <th>Gentoo</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>146</th>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "     Adelie  Chinstrap  Gentoo\n",
              "146       0          0       1"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 35
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "25MAdOnDAmAR",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "cf86d8b0-fadd-45d8-b698-2f8ad14af009"
      },
      "source": [
        "clf.predict([[44.7600, 13.7400, 211.4000, 4500, 1, 0, 1, 0, 0]])"
      ],
      "execution_count": 46,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([[0, 0, 1]], dtype=uint8)"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 46
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "za9nFTsCJAnq",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "import pickle"
      ],
      "execution_count": 36,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "aJbdCbwSI6Z3",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "filename = 'penguins_clf.pkl'\n",
        "pickle.dump(clf, open(filename, 'wb'))"
      ],
      "execution_count": 37,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "8zPcDch08tgL",
        "colab_type": "text"
      },
      "source": [
        "## Create the streamlit App"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "A4hEQUGOB6Ad",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "eb2d6981-b041-43e7-a7a3-31388890cc5d"
      },
      "source": [
        "%%writefile app.py\n",
        "\n",
        "import streamlit as st\n",
        "import pandas as pd\n",
        "import numpy as np\n",
        "import pickle\n",
        "from sklearn.ensemble import RandomForestClassifier\n",
        "\n",
        "st.write(\"\"\"\n",
        "\n",
        "![palmerpenguins](https://miro.medium.com/max/1200/1*xJ6_zgmEEfI2BT0sRXP5cw.png)\n",
        "# Penguin Prediction App\n",
        "\n",
        "This app predicts the **Palmer Penguin** species!\n",
        "\n",
        "Data obtained from the [palmerpenguins library](https://github.com/allisonhorst/palmerpenguins) in R by Allison Horst.\n",
        "\"\"\")\n",
        "\n",
        "st.sidebar.header('User Input Features')\n",
        "\n",
        "st.sidebar.markdown(\"\"\"\n",
        "[Example CSV input file](https://raw.githubusercontent.com/dataprofessor/data/master/penguins_example.csv)\n",
        "\"\"\")\n",
        "\n",
        "# Collects user input features into dataframe\n",
        "uploaded_file = st.sidebar.file_uploader(\"Upload your input CSV file\", type=[\"csv\"])\n",
        "if uploaded_file is not None:\n",
        "    input_df = pd.read_csv(uploaded_file)\n",
        "else:\n",
        "    def user_input_features():\n",
        "        island = st.sidebar.selectbox('Island',('Biscoe','Dream','Torgersen'))\n",
        "        sex = st.sidebar.selectbox('Sex',('male','female'))\n",
        "        bill_length_mm = st.sidebar.slider('Bill length (mm)', 32.1,59.6,43.9)\n",
        "        bill_depth_mm = st.sidebar.slider('Bill depth (mm)', 13.1,21.5,17.2)\n",
        "        flipper_length_mm = st.sidebar.slider('Flipper length (mm)', 172.0,231.0,201.0)\n",
        "        body_mass_g = st.sidebar.slider('Body mass (g)', 2700.0,6300.0,4207.0)\n",
        "        data = {'island': island,\n",
        "                'bill_length_mm': bill_length_mm,\n",
        "                'bill_depth_mm': bill_depth_mm,\n",
        "                'flipper_length_mm': flipper_length_mm,\n",
        "                'body_mass_g': body_mass_g,\n",
        "                'sex': sex}\n",
        "        features = pd.DataFrame(data, index=[0])\n",
        "        return features\n",
        "        print(features)\n",
        "    input_df = user_input_features()\n",
        "\n",
        "# Combines user input features with entire penguins dataset\n",
        "# This will be useful for the encoding phase\n",
        "penguins_raw = pd.read_csv('penguins_cleaned.csv')\n",
        "penguins = penguins_raw.drop(columns=['species'])\n",
        "df = pd.concat([input_df,penguins],axis=0)\n",
        "\n",
        "# Encoding of ordinal features\n",
        "# https://www.kaggle.com/pratik1120/penguin-dataset-eda-classification-and-clustering\n",
        "encode = ['sex','island']\n",
        "for col in encode:\n",
        "    dummy = pd.get_dummies(df[col], prefix=col)\n",
        "    df = pd.concat([df,dummy], axis=1)\n",
        "    del df[col]\n",
        "df = df[:1] # Selects only the first row (the user input data)\n",
        "\n",
        "# Displays the user input features\n",
        "st.subheader('User Input features')\n",
        "\n",
        "if uploaded_file is not None:\n",
        "    st.write(df)\n",
        "else:\n",
        "    st.write('Awaiting CSV file to be uploaded. Currently using example input parameters (shown below).')\n",
        "    st.write(df)\n",
        "\n",
        "# Reads in saved classification model\n",
        "load_clf = pickle.load(open('penguins_clf.pkl', 'rb'))\n",
        "\n",
        "# Apply model to make predictions\n",
        "prediction = load_clf.predict(df)\n",
        "prediction_proba = load_clf.predict_proba(df)\n",
        "\n",
        "\n",
        "st.subheader('Prediction')\n",
        "penguins_species = np.array(['Adelie','Chinstrap','Gentoo'])\n",
        "#st.write(prediction)\n",
        "st.write(penguins_species[np.argmax(prediction)])\n",
        "\n",
        "st.subheader('Prediction Probability')\n",
        "st.write(prediction_proba)"
      ],
      "execution_count": 66,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Overwriting app.py\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "m5_vFfIfJuxg",
        "colab_type": "text"
      },
      "source": [
        "## Install ngrok"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ED588fJ5IgW6",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 208
        },
        "outputId": "018868f9-748b-4594-f19e-4e8259edda0d"
      },
      "source": [
        "!wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip"
      ],
      "execution_count": 39,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "--2020-07-08 10:35:53--  https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip\n",
            "Resolving bin.equinox.io (bin.equinox.io)... 52.86.203.217, 52.207.47.153, 52.203.87.192, ...\n",
            "Connecting to bin.equinox.io (bin.equinox.io)|52.86.203.217|:443... connected.\n",
            "HTTP request sent, awaiting response... 200 OK\n",
            "Length: 13773305 (13M) [application/octet-stream]\n",
            "Saving to: ‘ngrok-stable-linux-amd64.zip’\n",
            "\n",
            "\r          ngrok-sta   0%[                    ]       0  --.-KB/s               \rngrok-stable-linux- 100%[===================>]  13.13M  65.9MB/s    in 0.2s    \n",
            "\n",
            "2020-07-08 10:35:53 (65.9 MB/s) - ‘ngrok-stable-linux-amd64.zip’ saved [13773305/13773305]\n",
            "\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "jAzg3Zr-KiuJ",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 52
        },
        "outputId": "223298e1-ec1b-48db-bf3e-9ea6ac3663ec"
      },
      "source": [
        "!unzip ngrok-stable-linux-amd64.zip"
      ],
      "execution_count": 40,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Archive:  ngrok-stable-linux-amd64.zip\n",
            "  inflating: ngrok                   \n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "1q4aqJGyGFYh",
        "colab_type": "text"
      },
      "source": [
        "Execute the following cells **everytime you stop the streamlit app and modify it**"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "DyQgvi2FFL1o",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "get_ipython().system_raw('./ngrok http 8501 &')"
      ],
      "execution_count": 68,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "vwxs-tWICysZ",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "dc5d4c56-c2f1-41cc-dbc7-9bb4d3bc902c"
      },
      "source": [
        "!curl -s http://localhost:4040/api/tunnels | python3 -c \\\n",
        "    'import sys, json; print(\"Execute the next cell and the go to the following URL: \" +json.load(sys.stdin)[\"tunnels\"][0][\"public_url\"])'"
      ],
      "execution_count": 69,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Execute the next cell and the go to the following URL: https://8eb372b6d901.ngrok.io\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "kQX0943EJ8Yk",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 139
        },
        "outputId": "f85865d5-4d3f-44ef-fde8-edf15b6553dc"
      },
      "source": [
        "!streamlit run app.py"
      ],
      "execution_count": 70,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "\u001b[0m\n",
            "\u001b[34m\u001b[1m  You can now view your Streamlit app in your browser.\u001b[0m\n",
            "\u001b[0m\n",
            "\u001b[34m  Network URL: \u001b[0m\u001b[1mhttp://172.28.0.2:8501\u001b[0m\n",
            "\u001b[34m  External URL: \u001b[0m\u001b[1mhttp://34.74.0.62:8501\u001b[0m\n",
            "\u001b[0m\n",
            "\u001b[34m  Stopping...\u001b[0m\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "RZ1KlR6bKspB",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        ""
      ],
      "execution_count": null,
      "outputs": []
    }
  ]
}