{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "13377395",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import openml"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 142,
   "id": "b4a5f816",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/opt/conda/envs/tabular/lib/python3.9/site-packages/openml/datasets/functions.py:438: FutureWarning: Starting from Version 0.15 `download_data`, `download_qualities`, and `download_features_meta_data` will all be ``False`` instead of ``True`` by default to enable lazy loading. To disable this message until version 0.15 explicitly set `download_data`, `download_qualities`, and `download_features_meta_data` to a bool while calling `get_dataset`.\n",
      "  warnings.warn(\n"
     ]
    }
   ],
   "source": [
    "# 40536 454 43044 44157 44159 44161 44162 45060 45062 41162 44089 44090 44091 44122 44123 44124 44125 44126 5 40672 43986 45068 41275 461 31 1549 452 25 470 475 846 934 1043 1063 1067 1113 1169 1459 1462 1464 1466 1467 1471 1475 1479 1486 1487 1489 1492 1493 1494 1497 1504 1509 1510 1531 35 36 37 54 59 150 151 182 185 188 307 313 551 51 40900 40981 40985 41143 41145 41147 41150 41168 41169 41960 42345 42734 338 23 1476 45714 53 337 372 455 458 29 49 466 42665 12 14 16 18 22 32 48 1503 4153 40922 42931\"\n",
    "openml_id = 40499\n",
    "dataset = openml.datasets.get_dataset(openml_id)\n",
    "# dataset.features"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 143,
   "id": "4a3f73d5",
   "metadata": {},
   "outputs": [],
   "source": [
    "dt = dataset.get_data()[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 144,
   "id": "7245626e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['V1', 'V2', 'V3', 'V4', 'V5', 'V6', 'V7', 'V8', 'V9', 'V10', 'V11',\n",
       "       'V12', 'V13', 'V14', 'V15', 'V16', 'V17', 'V18', 'V19', 'V20', 'V21',\n",
       "       'V22', 'V23', 'V24', 'V25', 'V26', 'V27', 'V28', 'V29', 'V30', 'V31',\n",
       "       'V32', 'V33', 'V34', 'V35', 'V36', 'V37', 'V38', 'V39', 'V40', 'Class'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 144,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dt.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 173,
   "id": "1c303474",
   "metadata": {},
   "outputs": [],
   "source": [
    "q1, q2, q3 = dt[\"V38\"].quantile([0.25, 0.5, 0.75]).values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 253,
   "id": "da73bd97",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 12512 characters]",
      "text/plain": [
       "<Figure size 500x400 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(5, 4))\n",
    "plt.rc('axes', axisbelow=False)\n",
    "\n",
    "counts, bins = np.histogram(dt[\"V38\"].values, bins=49, density=True)\n",
    "\n",
    "colors = []\n",
    "for i in range(len(bins)-1):\n",
    "    if bins[i] <= q1:\n",
    "        colors.append('dodgerblue')\n",
    "    elif bins[i] <= q2:\n",
    "        colors.append('darkorange')\n",
    "    elif bins[i] <= q3:\n",
    "        colors.append('forestgreen')\n",
    "    else:\n",
    "        colors.append('firebrick')\n",
    "\n",
    "for i in range(len(counts)):\n",
    "    plt.bar(bins[i], counts[i], width=bins[i+1]-bins[i], alpha=0.8, color=colors[i])\n",
    "\n",
    "plt.xticks([q1, q2, q3], [\"Q1\", \"Q2\", \"Q3\"])\n",
    "plt.grid(axis=\"x\", linewidth=1.2, color=\"k\")\n",
    "plt.ylim(0, 2)\n",
    "plt.savefig(\"/home/SemiTab/figs/distribution.png\", dpi=300)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "raw",
   "id": "91c16fa8",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "7499f83c",
   "metadata": {},
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "tabular",
   "language": "python",
   "name": "tabular"
  },
  "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.8.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
