{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "_cell_guid": "5aedd704-ad40-ebcb-b4ff-7c73edf5ec50"
      },
      "source": [
        ""
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "fd8f7acd-f931-aac7-0d7c-361934322000"
      },
      "outputs": [],
      "source": [
        "import numpy as np # linear algebra\n",
        "import seaborn as sns\n",
        "import matplotlib\n",
        "import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n",
        "from sklearn.decomposition import PCA, RandomizedPCA\n",
        "from sklearn.manifold import TSNE\n",
        "\n",
        "sns.set_style(\"darkgrid\", {\"axes.facecolor\": \".95\"})\n",
        "%config InlineBackend.figure_format = 'svg'"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "fb3ee38b-7bf2-d4b7-62ad-3b5b381a84b6"
      },
      "outputs": [],
      "source": [
        "data = pd.read_csv('../input/train.csv')"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "dc924c70-95ce-f3d6-4f34-9bd18d28cfe7"
      },
      "outputs": [],
      "source": [
        "data.head()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "0b4cada7-c7ba-9f64-a6bf-b599ae49c79b"
      },
      "outputs": [],
      "source": [
        "X = data.loc[:,\"pixel0\":\"pixel783\"]\n",
        "y = data.label\n",
        "print(\"ready\")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "ce023418-3b62-3f43-6aeb-15d50ed86e44"
      },
      "outputs": [],
      "source": [
        "data.shape\n",
        "print(\"ready\")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "8ea1916b-a270-1669-021f-de6288404be7"
      },
      "outputs": [],
      "source": [
        "pca = PCA(n_components = 99)\n",
        "X_pca = pca.fit_transform(data)\n",
        "print(\"ready\")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "9eaa6cf0-ee24-d927-6d83-330e65397d94"
      },
      "outputs": [],
      "source": [
        "tsne = TSNE()\n",
        "X_tsne = tsne.fit_transform(X_pca[:10000])\n",
        "print(\"ready\")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "a19b9a35-35f2-b0bd-9719-1b7b90441f39"
      },
      "outputs": [],
      "source": [
        "matplotlib.rcParams['figure.figsize'] = (10.0, 10.0)\n",
        "proj = pd.DataFrame(X_tsne)\n",
        "proj.columns = [\"comp_1\", \"comp_2\"]\n",
        "proj[\"labels\"] = y\n",
        "sns.lmplot(\"comp_1\", \"comp_2\", hue = \"labels\", data = proj.sample(5000) ,fit_reg=False)\n",
        "print(\"ready\")"
      ]
    }
  ],
  "metadata": {
    "_change_revision": 0,
    "_is_fork": false,
    "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.0"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}