Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
Progress bar in Jupyter notebook for tracking the progress as your machine learning model is training
  • Loading branch information
dataprofessor authored Jan 9, 2021
1 parent 4b3d32b commit 4caaa03
Showing 1 changed file with 208 additions and 0 deletions.
208 changes: 208 additions & 0 deletions python/model_is_training_progress_bar.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "zzD4-HxqXBmt"
},
"source": [
"# **Progress Bar in Jupyter Notebook**\n",
"\n",
"Chanin Nantasenamat\n",
"\n",
"**Data Professor YouTube channel**, http://youtube.com/dataprofessor"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "An7XU557Y5ci"
},
"source": [
"# **Progress Bar with the tqdm library**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "3yc04janmetd"
},
"outputs": [],
"source": [
"# ! pip install tqdm"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"id": "gxa8jup1DNjt"
},
"outputs": [],
"source": [
"from tqdm.notebook import tqdm\n",
"from time import sleep"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"id": "009bdoXCE74q"
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "93cc2d7933af4faf96fda14e55f24e23",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/100 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"number_list = list(range(100))\n",
"for x in tqdm(number_list):\n",
" sleep(0.05)\n",
"#print('Completed!')"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "4tFGw2QFMz6N"
},
"source": [
"# **Model Building**"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "zKKr9EoSVbOV"
},
"source": [
"### Reading in the Delaney Solubility Dataset"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"id": "FHR0FBHEMyyL"
},
"outputs": [],
"source": [
"import pandas as pd\n",
"\n",
"dataset = pd.read_csv('https://raw.githubusercontent.com/dataprofessor/data/master/delaney_solubility_with_descriptors.csv')\n",
"\n",
"X = dataset.drop(['logS'], axis=1)\n",
"Y = dataset.iloc[:,-1]\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "BqqRRTtUVi7v"
},
"source": [
"### Model Building with Progress Bar"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"id": "cpa2tS3kInAx",
"scrolled": true
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "a1b762495ff545468e8b801795c6b708",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/10 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Tree: 100, R2: 0.9796508266364179, MSE: 0.08936295274735467\n",
"Tree: 200, R2: 0.9805478792326812, MSE: 0.08542356575902461\n",
"Tree: 300, R2: 0.9801470956638436, MSE: 0.08718359809468906\n",
"Tree: 400, R2: 0.9803760482277171, MSE: 0.08617815788435489\n",
"Tree: 500, R2: 0.9804686074892891, MSE: 0.08577168589797951\n",
"Tree: 600, R2: 0.9804079256830844, MSE: 0.08603816873163578\n",
"Tree: 700, R2: 0.9802975717717071, MSE: 0.0865227855360484\n",
"Tree: 800, R2: 0.9803651322114956, MSE: 0.08622609533244484\n",
"Tree: 900, R2: 0.98037907466393, MSE: 0.08616486735547396\n",
"Tree: 1000, R2: 0.9804349669126423, MSE: 0.08591941775949379\n"
]
}
],
"source": [
"from sklearn.ensemble import RandomForestRegressor\n",
"from sklearn.metrics import mean_squared_error, r2_score\n",
"\n",
"parameter_n_estimators = [100,200,300,400,500,600,700,800,900,1000]\n",
"\n",
"for i in tqdm(parameter_n_estimators):\n",
" model = RandomForestRegressor(n_estimators=i)\n",
" model.fit(X,Y)\n",
" Y_pred = model.predict(X)\n",
" r2 = r2_score(Y, Y_pred)\n",
" mse = mean_squared_error(Y, Y_pred)\n",
" print('Tree: %s, R2: %s, MSE: %s' % (i, r2, mse))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"colab": {
"collapsed_sections": [],
"name": "Model-building-with-progress-bar.ipynb",
"provenance": []
},
"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.9"
}
},
"nbformat": 4,
"nbformat_minor": 1
}

0 comments on commit 4caaa03

Please sign in to comment.