From 656bca896cafad26bf6916beff5102d410a271ef Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 11 Jun 2026 12:39:29 +0000 Subject: [PATCH] more checks on model improvements --- HospitalWaitTimeCalc.ipynb | 544 ++++++++++++++++++++++++++++++++++++- 1 file changed, 539 insertions(+), 5 deletions(-) diff --git a/HospitalWaitTimeCalc.ipynb b/HospitalWaitTimeCalc.ipynb index f733c21..00e5a8e 100644 --- a/HospitalWaitTimeCalc.ipynb +++ b/HospitalWaitTimeCalc.ipynb @@ -2360,11 +2360,6 @@ "print(\"RMSE:\", np.sqrt(mean_squared_error(y_test, y_pred)))" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [] - }, { "cell_type": "markdown", "metadata": {}, @@ -2456,6 +2451,545 @@ "plt.title(\"Feature Importance\")\n", "plt.show()\n" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Adjust the relevant hyperparameters of the algorithm to improve the outputs. - Rayyan Hodges" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [], + "source": [ + "import xgboost as xgb\n", + "\n", + "model = xgb.XGBRegressor(\n", + " objective='reg:squarederror',\n", + " n_estimators=400, # Double the model size\n", + " learning_rate=0.1,\n", + " max_depth=5,\n", + " subsample=0.8,\n", + " colsample_bytree=0.8,\n", + " random_state=42\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Retrain the adjusted ML model with the training data. - Rayyan Hodges" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
XGBRegressor(base_score=None, booster=None, callbacks=None,\n",
+       "             colsample_bylevel=None, colsample_bynode=None,\n",
+       "             colsample_bytree=0.8, device=None, early_stopping_rounds=None,\n",
+       "             enable_categorical=False, eval_metric=None, feature_types=None,\n",
+       "             feature_weights=None, gamma=None, grow_policy=None,\n",
+       "             importance_type=None, interaction_constraints=None,\n",
+       "             learning_rate=0.1, max_bin=None, max_cat_threshold=None,\n",
+       "             max_cat_to_onehot=None, max_delta_step=None, max_depth=5,\n",
+       "             max_leaves=None, min_child_weight=None, missing=nan,\n",
+       "             monotone_constraints=None, multi_strategy=None, n_estimators=400,\n",
+       "             n_jobs=None, num_parallel_tree=None, ...)
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
" + ], + "text/plain": [ + "XGBRegressor(base_score=None, booster=None, callbacks=None,\n", + " colsample_bylevel=None, colsample_bynode=None,\n", + " colsample_bytree=0.8, device=None, early_stopping_rounds=None,\n", + " enable_categorical=False, eval_metric=None, feature_types=None,\n", + " feature_weights=None, gamma=None, grow_policy=None,\n", + " importance_type=None, interaction_constraints=None,\n", + " learning_rate=0.1, max_bin=None, max_cat_threshold=None,\n", + " max_cat_to_onehot=None, max_delta_step=None, max_depth=5,\n", + " max_leaves=None, min_child_weight=None, missing=nan,\n", + " monotone_constraints=None, multi_strategy=None, n_estimators=400,\n", + " n_jobs=None, num_parallel_tree=None, ...)" + ] + }, + "execution_count": 42, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "model.fit(X_train, y_train)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Run the test data through the adjusted ML model. - Rayyan Hodges" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [], + "source": [ + "y_pred = model.predict(X_test)" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "MAE: 1.9761157658704487\n", + "RMSE: 2.8484900838444096\n" + ] + } + ], + "source": [ + "from sklearn.metrics import mean_absolute_error, mean_squared_error, r2_score\n", + "import numpy as np\n", + "\n", + "print(\"MAE:\", mean_absolute_error(y_test, y_pred))\n", + "print(\"RMSE:\", np.sqrt(mean_squared_error(y_test, y_pred)))" + ] } ], "metadata": {