{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "\n",
    "import warnings\n",
    "from math import pi\n",
    "import seaborn as sns\n",
    "import plotly.express as px\n",
    "import matplotlib\n",
    "import matplotlib.pyplot as plt\n",
    "from IPython.display import HTML,display\n",
    "\n",
    "sns.set(style=\"whitegrid\", font_scale=1.75)\n",
    "\n",
    "\n",
    "# prettify plots\n",
    "plt.rcParams['figure.figsize'] = [20.0, 5.0]\n",
    "    \n",
    "%matplotlib inline\n",
    "\n",
    "warnings.filterwarnings(\"ignore\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "deepnetts-linear-regression-validation.csv\n",
      "deepnetts-tribuo-4-lr-ensembles-average.csv\n",
      "deepnetts-tribuo-4-lr-ensembles-geomean.csv\n",
      "deepnetts-tribuo-4-lr-ensembles-harmonic-mean.csv\n",
      "deepnetts-tribuo-4-lr-ensembles-median.csv\n",
      "linear-for-deepnetts.csv\n",
      "linear-for-tribuo.csv\n",
      "tribuo-3-lr-ensembles-average.csv\n",
      "tribuo-3-lr-ensembles-geomean.csv\n",
      "tribuo-3-lr-ensembles-harmonic-mean.csv\n",
      "tribuo-3-lr-ensembles-median.csv\n",
      "tribuo-linear-regression-ada-validation.csv\n",
      "tribuo-linear-regression-cart-validation.csv\n",
      "tribuo-linear-regression-sgd-validation.csv\n",
      "tribuo-linear-regression-xgb-validation.csv\n"
     ]
    }
   ],
   "source": [
    "DATASETS_FOLDER=\"../datasets/\"\n",
    "!ls ../datasets/"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "column_names = ['X_input', 'y_prediction']\n",
    "deepnetts_lr_prediction = pd.read_csv(f'{DATASETS_FOLDER}/deepnetts-linear-regression-validation.csv')\n",
    "deepnetts_lr_prediction.columns = column_names\n",
    "\n",
    "tribuo_lr_sgd_validation = pd.read_csv(f'{DATASETS_FOLDER}/tribuo-linear-regression-sgd-validation.csv')\n",
    "tribuo_lr_sgd_validation.columns = column_names\n",
    "tribuo_lr_ada_validation = pd.read_csv(f'{DATASETS_FOLDER}/tribuo-linear-regression-ada-validation.csv')\n",
    "tribuo_lr_ada_validation.columns = column_names\n",
    "tribuo_lr_cart_validation = pd.read_csv(f'{DATASETS_FOLDER}/tribuo-linear-regression-cart-validation.csv')\n",
    "tribuo_lr_cart_validation.columns = column_names\n",
    "tribuo_lr_xgb_validation = pd.read_csv(f'{DATASETS_FOLDER}/tribuo-linear-regression-xgb-validation.csv')\n",
    "tribuo_lr_xgb_validation.columns = column_names"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Legend\n",
    "\n",
    "- **NN**: Neural Networks\n",
    "- **SGD**: Stochastic Gradient Descent\n",
    "- **LR**: Linear Regression\n",
    "- **ADA**: Adam Optimiser\n",
    "- **CART**: Classification And Regression Trees (Ensemble)\n",
    "- **XGB**: XGBoost"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Plotting all the input data (they should be the same)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x7f931e182d68>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 180604 characters]\n",
      "text/plain": [
       "<Figure size 1440x576 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.rcParams['figure.figsize'] = [20.0, 8.0]\n",
    "deepnetts_lr_prediction.X_input.plot()\n",
    "tribuo_lr_sgd_validation.X_input.plot()\n",
    "tribuo_lr_ada_validation.X_input.plot()\n",
    "tribuo_lr_cart_validation.X_input.plot()\n",
    "tribuo_lr_xgb_validation.X_input.plot()\n",
    "plt.legend(['deepnetts: Linear Regression/NN', \n",
    "            'tribuo: Linear Regression/SGD',\n",
    "            'tribuo: Linear Regression/ADA',\n",
    "            'tribuo: Linear Regression/CART',\n",
    "            'tribuo: Linear Regression/XGB'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Plotting DeepNetts LR/NN and tribuo: Linear Regression/SGD predictions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x7f931d98b358>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 148500 characters]\n",
      "text/plain": [
       "<Figure size 1440x720 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.rcParams['figure.figsize'] = [20.0, 10.0]\n",
    "deepnetts_lr_prediction.y_prediction.plot()\n",
    "tribuo_lr_sgd_validation.y_prediction.plot()\n",
    "plt.legend(['deepnetts: Linear Regression/NN', 'tribuo: Linear Regression/SGD'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Taking a closer look at the prediction results of 'tribuo: LR/SGD' (Tribuo's Linear Regression using the SGD algorithm)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x7f931e1421d0>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 143528 characters]\n",
      "text/plain": [
       "<Figure size 1440x720 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "tribuo_lr_sgd_validation.y_prediction.plot()\n",
    "plt.legend(['tribuo: Linear Regression/SGD'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x7f931d6c9e80>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 190340 characters]\n",
      "text/plain": [
       "<Figure size 1440x720 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.rcParams['figure.figsize'] = [20.0, 10.0]\n",
    "deepnetts_lr_prediction.y_prediction.plot()\n",
    "tribuo_lr_ada_validation.y_prediction.plot()\n",
    "plt.legend(['deepnetts: Linear Regression/NN', 'tribuo: Linear Regression/ADA'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x7f931d6ae7f0>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 221040 characters]\n",
      "text/plain": [
       "<Figure size 1440x720 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.rcParams['figure.figsize'] = [20.0, 10.0]\n",
    "deepnetts_lr_prediction.y_prediction.plot()\n",
    "tribuo_lr_cart_validation.y_prediction.plot()\n",
    "plt.legend(['deepnetts: Linear Regression/NN', 'tribuo: Linear Regression/CART'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x7f931dc3c7f0>"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 220608 characters]\n",
      "text/plain": [
       "<Figure size 1440x720 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.rcParams['figure.figsize'] = [20.0, 10.0]\n",
    "deepnetts_lr_prediction.y_prediction.plot()\n",
    "tribuo_lr_xgb_validation.y_prediction.plot()\n",
    "plt.legend(['deepnetts: Linear Regression/NN', 'tribuo: Linear Regression/XGBoost'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "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.7.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
