{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "_cell_guid": "26c5c7ea-23b0-f092-3abf-b33350d6995e"
      },
      "source": [
        "Running the EEG dataset, this is my first trial work as a data scientist, and my first submission on Kaggle"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "9cd77e68-31e1-2efb-41f6-4d28cf159aab"
      },
      "outputs": [],
      "source": [
        "from glob import glob\n",
        "import pandas as pd\n",
        "from sklearn.preprocessing import StandardScaler\n",
        "import os\n",
        "\n",
        "def parse_data(fname): #create a function for parsing train data\n",
        "    data = pd.read_csv(fname) #read data using pandas' read_csv function\n",
        "    event_data = fname.replace('_data', '_events') #you replace filename string '_data' with '_event' \n",
        "\t#so that you can automate reading same filename parsed for event\n",
        "    labels = pd.read_csv(event_data)\n",
        "    clean = data.drop(['id'], axis =1)\n",
        "    labels = labels.drop(['id'], axis = 1)\n",
        "    return clean, labels\n",
        "\n",
        "def parse_test_data(fname):\n",
        "    data = pd.read_csv(fname)\n",
        "    return data"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "4996d0cf-ed52-15af-4727-259656af8b55"
      },
      "outputs": [],
      "source": [
        "subjects = range(1, 13)\n",
        "\n",
        "idx_tot = []\n",
        "\n",
        "import numpy as np\n",
        "for subject in subjects:\n",
        "    raw = [] #raw data features\n",
        "    y_raw = [] #raw label data\n",
        "    read_datas = glob('../input/train/subj%d_series*_data.csv' % (subject))\n",
        "    for fname in read_datas:\n",
        "        data,label = parse_data(fname)\n",
        "        raw.append(data)\n",
        "        y_raw.append(label)\n",
        "        \n",
        "    X = pd.concat(raw)\n",
        "    y = pd.concat(y_raw)\n",
        "    \n",
        "    X_train = np.asarray(X.astype(float))\n",
        "    y = np.asarray(y.astype(float))"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "98a13aba-2859-ea43-962b-df0daefc9c81"
      },
      "outputs": [],
      "source": [
        "for subject in subjects:\n",
        "    import numpy as np\n",
        "    read_test = glob('../input/test/subj%d_series*_data.csv' % (subject))\n",
        "    test = [] #initiate a an empty list to put each row of the read test set data\n",
        "    idx = []  #What is this one doing? need to find out but it looks a lot like this is the index\n",
        "    for fname in read_test:\n",
        "        label = parse_test_data(fname) #parse test data using initialized function for parsing test_data\n",
        "        test.append(label)\n",
        "        idx.append(np.array(label['id'])) # this adds the array dtype of index column\n",
        "     \n",
        "    X_test = pd.concat(test) #concatenate the list gotten for the Test data\n",
        "    id = np.concatenate(idx) #concatenation done through numpy because idx is a numpy array object\n",
        "\t\n",
        "\t#We are appending id to 'idx_tot' empty list that was initiated in the begining, the WHY of this i am yet to get a\n",
        "\t#grasp on.\n",
        "    idx_tot.append(id)\n",
        "    X_test = X_test.drop(['id'], axis = 1)\n",
        "\t\n",
        "\t#Prepare the test data for the classifier\n",
        "    X_test = np.asarray(X_test.astype(float))"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "52d0dd24-d122-7c21-5ff3-6cb57ab1b515"
      },
      "outputs": [],
      "source": [
        "pred = np.empty((X_test.shape[0], 6))\n",
        "pred"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "00ac4367-1fe0-9222-fc01-ebb9f35bd778"
      },
      "outputs": [],
      "source": [
        "y"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "edddb407-aa5d-77d9-61ba-3ce8ca7cd986"
      },
      "outputs": [],
      "source": [
        "for i in range(6):\n",
        "    y_train = y[:, i]\n",
        "    print(y_train)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "eaacf271-6143-7649-cbe4-6fac651f5867"
      },
      "outputs": [],
      "source": ""
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "57edad57-ad32-89d9-4188-584274601f99"
      },
      "outputs": [],
      "source": [
        "sub1_events_file = '../input/train/subj1_series1_events.csv'\n",
        "sub1_data_file = '../input/train/subj1_series1_data.csv'\n",
        "\n",
        "sub1_events = pd.read_csv(sub1_events_file)\n",
        "sub1_data = pd.read_csv(sub1_data_file)\n",
        "\n",
        "sub1 = pd.concat([sub1_events, sub1_data], axis = 1)\n",
        "sub1[\"time\"] = range(0, len(sub1))\n",
        "\n",
        "sample_sub1 = sub1[sub1[\"time\"] < 5000]"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "7c8613a1-f616-d138-f220-b22b6996f00b"
      },
      "outputs": [],
      "source": [
        "new_subj = sub1_data_file.replace('_data', '_events')\n",
        "new_subj"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "ad5a8d1a-436f-eab5-fe84-2e5cfd6de11f"
      },
      "outputs": [],
      "source": [
        "train_subj5 = pd.read_csv(\"../input/train/subj5_series7_data.csv\")\n",
        "train_subj5.head()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "95371e2c-82e6-6a01-4ad9-15510e449b24"
      },
      "outputs": [],
      "source": [
        "train_event = pd.read_csv(\"../input/train/subj7_series1_events.csv\")\n",
        "train_data = pd.read_csv(\"../input/train/subj7_series1_data.csv\")\n",
        "train_event.head()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "32fa6d82-2543-027c-6157-ff1837f7c517"
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\n",
        "view_data1 = train_subj5[1500:3000]\n",
        "show_data1 = view_data1.plot(subplots = True, figsize = (10, 50))\n",
        "plt.show(show_data1)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "226d5492-4c90-b4e8-f752-ae869859357b"
      },
      "outputs": [],
      "source": [
        "view_data2 = train_subj5.loc[1500:3000, :]\n",
        "view_data2.plot(subplots = True, figsize = (10, 50))\n",
        "plt.show(view_data2)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "a70cbe70-6e02-e1d6-c0aa-b31018ae966b"
      },
      "outputs": [],
      "source": [
        "sample_submit = pd.read_csv(\"../input/sample_submission.csv\")\n",
        "sample_submit.head()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "a803ad2c-c60b-4e0b-afac-eff4b2d237c3"
      },
      "outputs": [],
      "source": [
        "os.listdir(\"../input/test\")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "018c2913-2028-2516-b376-b66edf768d10"
      },
      "outputs": [],
      "source": [
        "\"\"\"\n",
        "Acknowledgment to kagglers I learnt from, thanks\n",
        "\n",
        "Abby Shockley\n",
        "\"\"\""
      ]
    }
  ],
  "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.5.2"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}