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": {