{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.14","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":82611,"databundleVersionId":9553358,"sourceType":"competition"}],"dockerImageVersionId":30775,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Table of Contents\n* [Basic EDA](#eda)\n* [Target vs Features](#target_vs_features)\n* [Time Series Plots](#ts)\n* [Model](#model)","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport time\n\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\nimport os\n\n# machine learning tools\nimport h2o\nfrom h2o.estimators import H2OGeneralizedLinearEstimator, H2ORandomForestEstimator, H2OGradientBoostingEstimator\nfrom h2o.automl import H2OAutoML\n\n# show files\n!ls -l '/kaggle/input/brist1d'","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-10-01T18:38:51.137612Z","iopub.execute_input":"2024-10-01T18:38:51.138934Z","iopub.status.idle":"2024-10-01T18:38:54.047031Z","shell.execute_reply.started":"2024-10-01T18:38:51.138868Z","shell.execute_reply":"2024-10-01T18:38:54.045675Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# configs\npd.set_option('display.max_columns', None) # we want to display all columns in this notebook\npd.set_option('display.max_rows', 100) # increase rows to be displayed\npd.set_option('display.max_colwidth', None) # show full cell contents\n\n# random seed\nmy_random_seed = 111\n\n# aesthetics\ndefault_color_1 = 'darkblue'\ndefault_color_2 = 'darkgreen'\ndefault_color_3 = 'darkred'\n\nimport warnings\nwarnings.filterwarnings('ignore')","metadata":{"execution":{"iopub.status.busy":"2024-10-01T18:38:54.049477Z","iopub.execute_input":"2024-10-01T18:38:54.050249Z","iopub.status.idle":"2024-10-01T18:38:54.057678Z","shell.execute_reply.started":"2024-10-01T18:38:54.050206Z","shell.execute_reply":"2024-10-01T18:38:54.056530Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# load data\nt1 = time.time()\ndf_train = pd.read_csv('/kaggle/input/brist1d/train.csv', low_memory=False)\ndf_test = pd.read_csv('/kaggle/input/brist1d/test.csv', low_memory=False)\ndf_sub = pd.read_csv('/kaggle/input/brist1d/sample_submission.csv', low_memory=False)\nt2 = time.time()\nprint('Elapsed time [s]:', np.round(t2-t1,4))","metadata":{"execution":{"iopub.status.busy":"2024-10-01T18:38:54.059896Z","iopub.execute_input":"2024-10-01T18:38:54.060399Z","iopub.status.idle":"2024-10-01T18:39:16.292587Z","shell.execute_reply.started":"2024-10-01T18:38:54.060319Z","shell.execute_reply":"2024-10-01T18:39:16.291383Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id='eda'></a>\n# EDA","metadata":{}},{"cell_type":"code","source":"# date conversion\ndf_train.time = pd.to_datetime(df_train.time, format='%H:%M:%S')\ndf_test.time = pd.to_datetime(df_test.time, format='%H:%M:%S')","metadata":{"execution":{"iopub.status.busy":"2024-10-01T18:39:16.295888Z","iopub.execute_input":"2024-10-01T18:39:16.296258Z","iopub.status.idle":"2024-10-01T18:39:16.346642Z","shell.execute_reply.started":"2024-10-01T18:39:16.296219Z","shell.execute_reply":"2024-10-01T18:39:16.345512Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# show structure of data\ndf_train.info(show_counts=True, verbose=True)","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2024-10-01T18:39:16.347995Z","iopub.execute_input":"2024-10-01T18:39:16.348462Z","iopub.status.idle":"2024-10-01T18:39:16.915594Z","shell.execute_reply.started":"2024-10-01T18:39:16.348412Z","shell.execute_reply":"2024-10-01T18:39:16.914440Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### 💡 We can see that there are a lot of missing values!","metadata":{}},{"cell_type":"code","source":"# show structure of data\ndf_test.info(show_counts=True, verbose=True)","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2024-10-01T18:39:16.917026Z","iopub.execute_input":"2024-10-01T18:39:16.917508Z","iopub.status.idle":"2024-10-01T18:39:17.106565Z","shell.execute_reply.started":"2024-10-01T18:39:16.917455Z","shell.execute_reply":"2024-10-01T18:39:17.105480Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# time range - training\ndf_train.time.describe()","metadata":{"execution":{"iopub.status.busy":"2024-10-01T18:39:17.107823Z","iopub.execute_input":"2024-10-01T18:39:17.108164Z","iopub.status.idle":"2024-10-01T18:39:17.127709Z","shell.execute_reply.started":"2024-10-01T18:39:17.108129Z","shell.execute_reply":"2024-10-01T18:39:17.126669Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# time range - test\ndf_test.time.describe()","metadata":{"execution":{"iopub.status.busy":"2024-10-01T18:39:17.128908Z","iopub.execute_input":"2024-10-01T18:39:17.129231Z","iopub.status.idle":"2024-10-01T18:39:17.141810Z","shell.execute_reply.started":"2024-10-01T18:39:17.129197Z","shell.execute_reply":"2024-10-01T18:39:17.140855Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# patient ids - training\ncount_train = df_train.p_num.value_counts().sort_index()\ncount_train","metadata":{"execution":{"iopub.status.busy":"2024-10-01T18:39:17.143130Z","iopub.execute_input":"2024-10-01T18:39:17.143566Z","iopub.status.idle":"2024-10-01T18:39:17.168595Z","shell.execute_reply.started":"2024-10-01T18:39:17.143517Z","shell.execute_reply":"2024-10-01T18:39:17.167314Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# patient ids - test\ncount_test = df_test.p_num.value_counts().sort_index()\ncount_test","metadata":{"execution":{"iopub.status.busy":"2024-10-01T18:39:17.172972Z","iopub.execute_input":"2024-10-01T18:39:17.173399Z","iopub.status.idle":"2024-10-01T18:39:17.185525Z","shell.execute_reply.started":"2024-10-01T18:39:17.173336Z","shell.execute_reply":"2024-10-01T18:39:17.184232Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# check which points in time are available in the test set\ndf_test.time.value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-10-01T18:39:17.187057Z","iopub.execute_input":"2024-10-01T18:39:17.187485Z","iopub.status.idle":"2024-10-01T18:39:17.203909Z","shell.execute_reply.started":"2024-10-01T18:39:17.187445Z","shell.execute_reply":"2024-10-01T18:39:17.202589Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### 💡 We have 288 different points in time in the test set. This means that every possible point in time is also available in the test set, because we have 12 values per hour - having 5 minute intervals - and this adds up to 24 x 12 = 288 different values.","metadata":{}},{"cell_type":"code","source":"# extract hour\ndf_train['hour'] = df_train.time.apply(lambda x : x.hour)\ndf_test['hour'] = df_test.time.apply(lambda x : x.hour)\n\n# and show plot\nplt.figure(figsize=(12,4))\ndf_train.hour.value_counts().sort_index().plot(kind='bar', color=default_color_1)\nplt.title('Distribution of hour - Training')\nplt.grid()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-10-01T18:39:17.205648Z","iopub.execute_input":"2024-10-01T18:39:17.206041Z","iopub.status.idle":"2024-10-01T18:39:18.014876Z","shell.execute_reply.started":"2024-10-01T18:39:17.205991Z","shell.execute_reply":"2024-10-01T18:39:18.013449Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# convert time into minutes (start 0:00)\ndf_train['time_min'] = df_train.hour * 60 + df_train.time.apply(lambda x : x.minute)\ndf_test['time_min'] = df_test.hour * 60 + df_test.time.apply(lambda x : x.minute)","metadata":{"execution":{"iopub.status.busy":"2024-10-01T18:39:18.016552Z","iopub.execute_input":"2024-10-01T18:39:18.016944Z","iopub.status.idle":"2024-10-01T18:39:18.524878Z","shell.execute_reply.started":"2024-10-01T18:39:18.016903Z","shell.execute_reply":"2024-10-01T18:39:18.523783Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# define target and predictors\ntarget = 'bg+1:00'\n\npredictors = df_test.columns.tolist()\npredictors.remove('id')\npredictors.remove('time')\npredictors.remove('time_min')","metadata":{"execution":{"iopub.status.busy":"2024-10-01T18:39:18.526226Z","iopub.execute_input":"2024-10-01T18:39:18.526605Z","iopub.status.idle":"2024-10-01T18:39:18.532886Z","shell.execute_reply.started":"2024-10-01T18:39:18.526567Z","shell.execute_reply":"2024-10-01T18:39:18.531510Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# plot target distribution\nplt.figure(figsize=(12,4))\ndf_train[target].plot(kind='hist', bins=50,\n                      color=default_color_3)\nplt.title(target)\nplt.grid()\nplt.show()\n# basic stats\nprint(df_train[target].describe())","metadata":{"execution":{"iopub.status.busy":"2024-10-01T18:39:18.534308Z","iopub.execute_input":"2024-10-01T18:39:18.534765Z","iopub.status.idle":"2024-10-01T18:39:18.859004Z","shell.execute_reply.started":"2024-10-01T18:39:18.534716Z","shell.execute_reply":"2024-10-01T18:39:18.857834Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id='target_vs_features'></a>\n# Target vs Features","metadata":{}},{"cell_type":"code","source":"# plot target distribution by hour\nplt.figure(figsize=(14,6))\nsns.violinplot(data=df_train, x='hour', y=target)\nplt.title('Target by hour')\nplt.grid()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-10-01T18:39:18.860508Z","iopub.execute_input":"2024-10-01T18:39:18.860889Z","iopub.status.idle":"2024-10-01T18:39:20.176073Z","shell.execute_reply.started":"2024-10-01T18:39:18.860851Z","shell.execute_reply":"2024-10-01T18:39:20.174738Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### 💡 We see a dependency between time and the target values.","metadata":{}},{"cell_type":"code","source":"# plot target distribution by patient\nplt.figure(figsize=(12,5))\nsns.violinplot(data=df_train, x='p_num', y=target)\nplt.title('Target by patient')\nplt.grid()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-10-01T18:39:20.177729Z","iopub.execute_input":"2024-10-01T18:39:20.178178Z","iopub.status.idle":"2024-10-01T18:39:21.769804Z","shell.execute_reply.started":"2024-10-01T18:39:20.178128Z","shell.execute_reply":"2024-10-01T18:39:21.768667Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### 💡 We can also observe that the target distributions differ significantly by patient.","metadata":{}},{"cell_type":"code","source":"# pick only a subset of numerical features\nsome_features = ['bg-0:00', 'bg-1:00', 'bg-2:00',\n                 'insulin-0:00', 'insulin-1:00', 'insulin-2:00',\n                 'carbs-0:00', 'carbs-1:00', 'carbs-2:00',\n                 'hr-0:00', 'hr-1:00', 'hr-2:00',\n                 'cals-0:00', 'cals-1:00', 'cals-2:00',\n                 'steps-0:00', 'steps-1:00', 'steps-2:00']","metadata":{"execution":{"iopub.status.busy":"2024-10-01T18:39:21.771254Z","iopub.execute_input":"2024-10-01T18:39:21.771664Z","iopub.status.idle":"2024-10-01T18:39:21.776900Z","shell.execute_reply.started":"2024-10-01T18:39:21.771626Z","shell.execute_reply":"2024-10-01T18:39:21.775704Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# scatter plots of target vs selected features\nfor f in some_features:\n    plt.scatter(df_train[f], df_train[target], color=default_color_3,\n                alpha=0.1, s=2)\n    plt.title('Target vs ' + f)\n    plt.grid()\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2024-10-01T18:46:43.588272Z","iopub.execute_input":"2024-10-01T18:46:43.588760Z","iopub.status.idle":"2024-10-01T18:46:49.605443Z","shell.execute_reply.started":"2024-10-01T18:46:43.588711Z","shell.execute_reply":"2024-10-01T18:46:49.604081Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id='ts'></a>\n# Time Series Plots","metadata":{}},{"cell_type":"code","source":"# plot target as time series\nfor x in count_train.index:\n    df_sel = df_train[df_train.p_num==x]\n    plt.figure(figsize=(14,4))\n    plt.scatter(df_sel.time_min, df_sel[target], color=default_color_3, \n                alpha=0.2, s=5)\n    plt.title(x)\n    plt.grid()\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2024-10-01T18:45:53.407232Z","iopub.execute_input":"2024-10-01T18:45:53.407721Z","iopub.status.idle":"2024-10-01T18:45:57.054619Z","shell.execute_reply.started":"2024-10-01T18:45:53.407678Z","shell.execute_reply":"2024-10-01T18:45:57.053460Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# plot target as time series - zoom (beginning)\nfor x in count_train.index:\n    df_sel = df_train[df_train.p_num==x].reset_index(drop=True)\n    df_sel = df_sel[0:250]\n    plt.figure(figsize=(14,4))\n    plt.scatter(df_sel.time_min, df_sel[target], color=default_color_3, \n                alpha=1, s=5)\n    plt.title(x + ' - Zoom')\n    plt.grid()\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2024-10-01T18:46:28.282929Z","iopub.execute_input":"2024-10-01T18:46:28.283491Z","iopub.status.idle":"2024-10-01T18:46:32.062070Z","shell.execute_reply.started":"2024-10-01T18:46:28.283342Z","shell.execute_reply":"2024-10-01T18:46:32.060748Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id='model'></a>\n# Model","metadata":{}},{"cell_type":"code","source":"# start H2O\nh2o.init(max_mem_size='20G', nthreads=4)","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2024-10-01T18:39:39.185971Z","iopub.execute_input":"2024-10-01T18:39:39.186404Z","iopub.status.idle":"2024-10-01T18:39:47.791759Z","shell.execute_reply.started":"2024-10-01T18:39:39.186346Z","shell.execute_reply":"2024-10-01T18:39:47.790262Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# prepare data for upload (combine train/test to avoid type mismatches)\ny = df_train[target]\ndf_train['fold'] = 'train'\ndf_test['fold'] = 'test'\ndf_train[target] = y\ndf_test[target] = 0\n# combine train & test in one data frame\ndf = pd.concat([df_train, df_test])\n\n# upload data in H2O environment\nt1 = time.time()\ndf_hex = h2o.H2OFrame(df)\nt2 = time.time()\nprint('Elapsed time [s]:', np.round(t2-t1,4))","metadata":{"execution":{"iopub.status.busy":"2024-10-01T18:39:47.794330Z","iopub.execute_input":"2024-10-01T18:39:47.795916Z","iopub.status.idle":"2024-10-01T18:41:25.859672Z","shell.execute_reply.started":"2024-10-01T18:39:47.795859Z","shell.execute_reply":"2024-10-01T18:41:25.858526Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# split again\ntrain_hex = df_hex[df_hex['fold']=='train']\ntest_hex = df_hex[df_hex['fold']=='test']","metadata":{"execution":{"iopub.status.busy":"2024-10-01T18:41:25.861129Z","iopub.execute_input":"2024-10-01T18:41:25.861502Z","iopub.status.idle":"2024-10-01T18:41:25.867802Z","shell.execute_reply.started":"2024-10-01T18:41:25.861463Z","shell.execute_reply":"2024-10-01T18:41:25.866401Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# setup AutoML\nmax_time_sec = 5*60\nfit_auto = H2OAutoML(max_runtime_secs=max_time_sec,\n                     sort_metric='RMSE',\n                     # exclude_algos=['DRF', 'StackedEnsemble'],\n                     include_algos=['GLM'], # just trying linear models for a first baseline\n                     seed=my_random_seed)","metadata":{"execution":{"iopub.status.busy":"2024-10-01T18:41:25.869200Z","iopub.execute_input":"2024-10-01T18:41:25.869582Z","iopub.status.idle":"2024-10-01T18:41:25.932653Z","shell.execute_reply.started":"2024-10-01T18:41:25.869543Z","shell.execute_reply":"2024-10-01T18:41:25.931486Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# and train model\nt1 = time.time()\nfit_auto.train(predictors, target, training_frame = train_hex)\nt2 = time.time()\nprint('Elapsed time [s]:', np.round(t2-t1,4))","metadata":{"execution":{"iopub.status.busy":"2024-10-01T18:41:25.934686Z","iopub.execute_input":"2024-10-01T18:41:25.935157Z","iopub.status.idle":"2024-10-01T18:45:03.430905Z","shell.execute_reply.started":"2024-10-01T18:41:25.935106Z","shell.execute_reply":"2024-10-01T18:45:03.426983Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# leaderboard\nlb = fit_auto.leaderboard\nlb.head(rows=lb.nrows) # show full leaderboard","metadata":{"execution":{"iopub.status.busy":"2024-10-01T18:45:03.432704Z","iopub.status.idle":"2024-10-01T18:45:03.433217Z","shell.execute_reply.started":"2024-10-01T18:45:03.432978Z","shell.execute_reply":"2024-10-01T18:45:03.433003Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# select best model\nfit_1 = fit_auto.leader","metadata":{"execution":{"iopub.status.busy":"2024-10-01T18:45:03.434614Z","iopub.status.idle":"2024-10-01T18:45:03.435109Z","shell.execute_reply.started":"2024-10-01T18:45:03.434880Z","shell.execute_reply":"2024-10-01T18:45:03.434903Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# show details\nfit_1","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2024-10-01T18:45:03.436796Z","iopub.status.idle":"2024-10-01T18:45:03.437219Z","shell.execute_reply.started":"2024-10-01T18:45:03.437024Z","shell.execute_reply":"2024-10-01T18:45:03.437044Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# variable importance\n# fit_1.varimp_plot(30);","metadata":{"execution":{"iopub.status.busy":"2024-10-01T18:45:03.438525Z","iopub.status.idle":"2024-10-01T18:45:03.438978Z","shell.execute_reply.started":"2024-10-01T18:45:03.438765Z","shell.execute_reply":"2024-10-01T18:45:03.438788Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# predict on train set\npred_train = fit_1.predict(train_hex)\npred_train = pred_train.as_data_frame(use_multi_thread=True)\n# and plot results\nplt.figure(figsize=(10,4))\nplt.hist(pred_train, bins=50, color=default_color_1)\nplt.title('Predictions on Training Data')\nplt.grid()\nplt.show()\n# basic stats\nprint(pred_train.describe())","metadata":{"execution":{"iopub.status.busy":"2024-10-01T18:45:03.440335Z","iopub.status.idle":"2024-10-01T18:45:03.440802Z","shell.execute_reply.started":"2024-10-01T18:45:03.440592Z","shell.execute_reply":"2024-10-01T18:45:03.440615Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# add prediction and residuals to data frame\ndf_train['prediction'] = pred_train\ndf_train['residual'] = df_train['prediction'] - df_train[target]","metadata":{"execution":{"iopub.status.busy":"2024-10-01T18:45:03.441934Z","iopub.status.idle":"2024-10-01T18:45:03.442312Z","shell.execute_reply.started":"2024-10-01T18:45:03.442131Z","shell.execute_reply":"2024-10-01T18:45:03.442150Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# plot predictions vs actuals\np=sns.jointplot(data=df_train, x=target, y='prediction',\n                color=default_color_1,\n                joint_kws={'alpha' : 0.2, 's' : 2})\np.fig.suptitle('Prediction vs Actual - Training Data')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-10-01T18:45:03.443572Z","iopub.status.idle":"2024-10-01T18:45:03.444006Z","shell.execute_reply.started":"2024-10-01T18:45:03.443810Z","shell.execute_reply":"2024-10-01T18:45:03.443833Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# plot residuals\nplt.figure(figsize=(14,3))\nplt.scatter(df_train.index, df_train.residual, color=default_color_1, \n            alpha=0.25, s=1)\nplt.title('Residuals - Training')\nplt.grid()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-10-01T18:45:03.445448Z","iopub.status.idle":"2024-10-01T18:45:03.445837Z","shell.execute_reply.started":"2024-10-01T18:45:03.445656Z","shell.execute_reply":"2024-10-01T18:45:03.445675Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# plot residuals vs feature\nf = 'bg-0:00'\nplt.figure(figsize=(14,3))\nplt.scatter(df_train[f], df_train.residual, color=default_color_1, \n            alpha=0.25, s=1)\nplt.xlabel(f)\nplt.ylabel('residual')\nplt.title('Residuals - Training')\nplt.grid()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-10-01T18:45:03.447497Z","iopub.status.idle":"2024-10-01T18:45:03.447939Z","shell.execute_reply.started":"2024-10-01T18:45:03.447747Z","shell.execute_reply":"2024-10-01T18:45:03.447768Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# plot residuals vs feature\nf = 'hr-0:00'\nplt.figure(figsize=(14,3))\nplt.scatter(df_train[f], df_train.residual, color=default_color_1, \n            alpha=0.25, s=1)\nplt.xlabel(f)\nplt.ylabel('residual')\nplt.title('Residuals - Training')\nplt.grid()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-10-01T18:45:03.449420Z","iopub.status.idle":"2024-10-01T18:45:03.449812Z","shell.execute_reply.started":"2024-10-01T18:45:03.449625Z","shell.execute_reply":"2024-10-01T18:45:03.449645Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# predict on test set\npred_test = fit_1.predict(test_hex)\npred_test = pred_test.as_data_frame(use_multi_thread=True)\n# and plot results\nplt.figure(figsize=(10,4))\nplt.hist(pred_test, bins=25, color=default_color_2)\nplt.title('Predictions on Test Set - Leader')\nplt.grid()\nplt.show()\n# basic stats\nprint(pred_test.describe())","metadata":{"execution":{"iopub.status.busy":"2024-10-01T18:45:03.452317Z","iopub.status.idle":"2024-10-01T18:45:03.452789Z","shell.execute_reply.started":"2024-10-01T18:45:03.452569Z","shell.execute_reply":"2024-10-01T18:45:03.452591Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# submission\ndf_sub[target] = pred_test\ndf_sub.head(10)","metadata":{"execution":{"iopub.status.busy":"2024-10-01T18:45:03.455871Z","iopub.status.idle":"2024-10-01T18:45:03.456346Z","shell.execute_reply.started":"2024-10-01T18:45:03.456120Z","shell.execute_reply":"2024-10-01T18:45:03.456143Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# save submission file\ndf_sub.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2024-10-01T18:45:03.457542Z","iopub.status.idle":"2024-10-01T18:45:03.457934Z","shell.execute_reply.started":"2024-10-01T18:45:03.457745Z","shell.execute_reply":"2024-10-01T18:45:03.457765Z"},"trusted":true},"execution_count":null,"outputs":[]}]}