|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": { |
| 6 | + "id": "zzD4-HxqXBmt" |
| 7 | + }, |
| 8 | + "source": [ |
| 9 | + "# **Progress Bar in Jupyter Notebook**\n", |
| 10 | + "\n", |
| 11 | + "Chanin Nantasenamat\n", |
| 12 | + "\n", |
| 13 | + "**Data Professor YouTube channel**, http://youtube.com/dataprofessor" |
| 14 | + ] |
| 15 | + }, |
| 16 | + { |
| 17 | + "cell_type": "markdown", |
| 18 | + "metadata": { |
| 19 | + "id": "An7XU557Y5ci" |
| 20 | + }, |
| 21 | + "source": [ |
| 22 | + "# **Progress Bar with the tqdm library**" |
| 23 | + ] |
| 24 | + }, |
| 25 | + { |
| 26 | + "cell_type": "code", |
| 27 | + "execution_count": null, |
| 28 | + "metadata": { |
| 29 | + "id": "3yc04janmetd" |
| 30 | + }, |
| 31 | + "outputs": [], |
| 32 | + "source": [ |
| 33 | + "# ! pip install tqdm" |
| 34 | + ] |
| 35 | + }, |
| 36 | + { |
| 37 | + "cell_type": "code", |
| 38 | + "execution_count": 1, |
| 39 | + "metadata": { |
| 40 | + "id": "gxa8jup1DNjt" |
| 41 | + }, |
| 42 | + "outputs": [], |
| 43 | + "source": [ |
| 44 | + "from tqdm.notebook import tqdm\n", |
| 45 | + "from time import sleep" |
| 46 | + ] |
| 47 | + }, |
| 48 | + { |
| 49 | + "cell_type": "code", |
| 50 | + "execution_count": 2, |
| 51 | + "metadata": { |
| 52 | + "id": "009bdoXCE74q" |
| 53 | + }, |
| 54 | + "outputs": [ |
| 55 | + { |
| 56 | + "data": { |
| 57 | + "application/vnd.jupyter.widget-view+json": { |
| 58 | + "model_id": "93cc2d7933af4faf96fda14e55f24e23", |
| 59 | + "version_major": 2, |
| 60 | + "version_minor": 0 |
| 61 | + }, |
| 62 | + "text/plain": [ |
| 63 | + " 0%| | 0/100 [00:00<?, ?it/s]" |
| 64 | + ] |
| 65 | + }, |
| 66 | + "metadata": {}, |
| 67 | + "output_type": "display_data" |
| 68 | + } |
| 69 | + ], |
| 70 | + "source": [ |
| 71 | + "number_list = list(range(100))\n", |
| 72 | + "for x in tqdm(number_list):\n", |
| 73 | + " sleep(0.05)\n", |
| 74 | + "#print('Completed!')" |
| 75 | + ] |
| 76 | + }, |
| 77 | + { |
| 78 | + "cell_type": "markdown", |
| 79 | + "metadata": { |
| 80 | + "id": "4tFGw2QFMz6N" |
| 81 | + }, |
| 82 | + "source": [ |
| 83 | + "# **Model Building**" |
| 84 | + ] |
| 85 | + }, |
| 86 | + { |
| 87 | + "cell_type": "markdown", |
| 88 | + "metadata": { |
| 89 | + "id": "zKKr9EoSVbOV" |
| 90 | + }, |
| 91 | + "source": [ |
| 92 | + "### Reading in the Delaney Solubility Dataset" |
| 93 | + ] |
| 94 | + }, |
| 95 | + { |
| 96 | + "cell_type": "code", |
| 97 | + "execution_count": 3, |
| 98 | + "metadata": { |
| 99 | + "id": "FHR0FBHEMyyL" |
| 100 | + }, |
| 101 | + "outputs": [], |
| 102 | + "source": [ |
| 103 | + "import pandas as pd\n", |
| 104 | + "\n", |
| 105 | + "dataset = pd.read_csv('https://raw.githubusercontent.com/dataprofessor/data/master/delaney_solubility_with_descriptors.csv')\n", |
| 106 | + "\n", |
| 107 | + "X = dataset.drop(['logS'], axis=1)\n", |
| 108 | + "Y = dataset.iloc[:,-1]\n" |
| 109 | + ] |
| 110 | + }, |
| 111 | + { |
| 112 | + "cell_type": "markdown", |
| 113 | + "metadata": { |
| 114 | + "id": "BqqRRTtUVi7v" |
| 115 | + }, |
| 116 | + "source": [ |
| 117 | + "### Model Building with Progress Bar" |
| 118 | + ] |
| 119 | + }, |
| 120 | + { |
| 121 | + "cell_type": "code", |
| 122 | + "execution_count": 4, |
| 123 | + "metadata": { |
| 124 | + "id": "cpa2tS3kInAx", |
| 125 | + "scrolled": true |
| 126 | + }, |
| 127 | + "outputs": [ |
| 128 | + { |
| 129 | + "data": { |
| 130 | + "application/vnd.jupyter.widget-view+json": { |
| 131 | + "model_id": "a1b762495ff545468e8b801795c6b708", |
| 132 | + "version_major": 2, |
| 133 | + "version_minor": 0 |
| 134 | + }, |
| 135 | + "text/plain": [ |
| 136 | + " 0%| | 0/10 [00:00<?, ?it/s]" |
| 137 | + ] |
| 138 | + }, |
| 139 | + "metadata": {}, |
| 140 | + "output_type": "display_data" |
| 141 | + }, |
| 142 | + { |
| 143 | + "name": "stdout", |
| 144 | + "output_type": "stream", |
| 145 | + "text": [ |
| 146 | + "Tree: 100, R2: 0.9796508266364179, MSE: 0.08936295274735467\n", |
| 147 | + "Tree: 200, R2: 0.9805478792326812, MSE: 0.08542356575902461\n", |
| 148 | + "Tree: 300, R2: 0.9801470956638436, MSE: 0.08718359809468906\n", |
| 149 | + "Tree: 400, R2: 0.9803760482277171, MSE: 0.08617815788435489\n", |
| 150 | + "Tree: 500, R2: 0.9804686074892891, MSE: 0.08577168589797951\n", |
| 151 | + "Tree: 600, R2: 0.9804079256830844, MSE: 0.08603816873163578\n", |
| 152 | + "Tree: 700, R2: 0.9802975717717071, MSE: 0.0865227855360484\n", |
| 153 | + "Tree: 800, R2: 0.9803651322114956, MSE: 0.08622609533244484\n", |
| 154 | + "Tree: 900, R2: 0.98037907466393, MSE: 0.08616486735547396\n", |
| 155 | + "Tree: 1000, R2: 0.9804349669126423, MSE: 0.08591941775949379\n" |
| 156 | + ] |
| 157 | + } |
| 158 | + ], |
| 159 | + "source": [ |
| 160 | + "from sklearn.ensemble import RandomForestRegressor\n", |
| 161 | + "from sklearn.metrics import mean_squared_error, r2_score\n", |
| 162 | + "\n", |
| 163 | + "parameter_n_estimators = [100,200,300,400,500,600,700,800,900,1000]\n", |
| 164 | + "\n", |
| 165 | + "for i in tqdm(parameter_n_estimators):\n", |
| 166 | + " model = RandomForestRegressor(n_estimators=i)\n", |
| 167 | + " model.fit(X,Y)\n", |
| 168 | + " Y_pred = model.predict(X)\n", |
| 169 | + " r2 = r2_score(Y, Y_pred)\n", |
| 170 | + " mse = mean_squared_error(Y, Y_pred)\n", |
| 171 | + " print('Tree: %s, R2: %s, MSE: %s' % (i, r2, mse))" |
| 172 | + ] |
| 173 | + }, |
| 174 | + { |
| 175 | + "cell_type": "code", |
| 176 | + "execution_count": null, |
| 177 | + "metadata": {}, |
| 178 | + "outputs": [], |
| 179 | + "source": [] |
| 180 | + } |
| 181 | + ], |
| 182 | + "metadata": { |
| 183 | + "colab": { |
| 184 | + "collapsed_sections": [], |
| 185 | + "name": "Model-building-with-progress-bar.ipynb", |
| 186 | + "provenance": [] |
| 187 | + }, |
| 188 | + "kernelspec": { |
| 189 | + "display_name": "Python 3", |
| 190 | + "language": "python", |
| 191 | + "name": "python3" |
| 192 | + }, |
| 193 | + "language_info": { |
| 194 | + "codemirror_mode": { |
| 195 | + "name": "ipython", |
| 196 | + "version": 3 |
| 197 | + }, |
| 198 | + "file_extension": ".py", |
| 199 | + "mimetype": "text/x-python", |
| 200 | + "name": "python", |
| 201 | + "nbconvert_exporter": "python", |
| 202 | + "pygments_lexer": "ipython3", |
| 203 | + "version": "3.7.9" |
| 204 | + } |
| 205 | + }, |
| 206 | + "nbformat": 4, |
| 207 | + "nbformat_minor": 1 |
| 208 | +} |
0 commit comments