{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"#####                                     यस्य कृत्यं न जानन्ति मन्त्रं वा मन्त्रितं परे।\n#####                                     कृतमेवास्य जानन्ति स वै पण्डित उच्यते ॥","metadata":{}},{"cell_type":"code","source":"import pandas as pd\n# import matplotlib.pyplot as plt\nimport numpy as np\nfrom datetime import datetime\n!pip install polars\nimport polars as pl\nimport random","metadata":{"ExecuteTime":{"end_time":"2023-10-13T02:42:38.335664300Z","start_time":"2023-10-13T02:42:35.514711400Z"},"execution":{"iopub.status.busy":"2023-10-22T22:26:23.143972Z","iopub.execute_input":"2023-10-22T22:26:23.144244Z","iopub.status.idle":"2023-10-22T22:26:34.769145Z","shell.execute_reply.started":"2023-10-22T22:26:23.144221Z","shell.execute_reply":"2023-10-22T22:26:34.767876Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_series = pl.scan_parquet(\"/kaggle/input/detect-sleep-states-memory-decrease/train_series.parquet\")\n","metadata":{"collapsed":false,"ExecuteTime":{"end_time":"2023-10-13T03:06:02.860166900Z","start_time":"2023-10-13T03:06:02.806646200Z"},"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2023-10-22T22:26:37.322532Z","iopub.execute_input":"2023-10-22T22:26:37.323415Z","iopub.status.idle":"2023-10-22T22:26:37.359887Z","shell.execute_reply.started":"2023-10-22T22:26:37.323370Z","shell.execute_reply":"2023-10-22T22:26:37.358743Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_series = train_series.with_columns(\n    pl.col(\"timestamp\").dt.hour().alias(\"hour\")\n)","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:26:38.030634Z","iopub.execute_input":"2023-10-22T22:26:38.031748Z","iopub.status.idle":"2023-10-22T22:26:38.053636Z","shell.execute_reply.started":"2023-10-22T22:26:38.031703Z","shell.execute_reply":"2023-10-22T22:26:38.052795Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(train_series.head(5).collect())","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:26:38.428244Z","iopub.execute_input":"2023-10-22T22:26:38.428762Z","iopub.status.idle":"2023-10-22T22:27:06.942204Z","shell.execute_reply.started":"2023-10-22T22:26:38.428727Z","shell.execute_reply":"2023-10-22T22:27:06.941194Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def classify_day_quarter(val):\n    \"\"\"\n    \n    :param row: \n    :return: will append  dayquarter column which contains time divided portion for a daya eg. D1 0-6,, D2 6-12, D3 12-18  D4 18-24  \n    \"\"\"\n    hour = val\n    if hour >= 0 and hour <= 6:\n        return 1\n    elif hour > 6 and hour <= 12:\n        return 2\n    elif hour > 12 and hour <= 18:\n        return 3\n\n    elif hour > 18 and hour <= 24:\n        return 4\n    \n    else:\n        return 4","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:27:06.943598Z","iopub.execute_input":"2023-10-22T22:27:06.943971Z","iopub.status.idle":"2023-10-22T22:27:06.948690Z","shell.execute_reply.started":"2023-10-22T22:27:06.943948Z","shell.execute_reply":"2023-10-22T22:27:06.948090Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_series = train_series.with_columns(pl.col(\"hour\").map_elements(classify_day_quarter).alias(\"hour_window\"))\n","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:27:06.949656Z","iopub.execute_input":"2023-10-22T22:27:06.950148Z","iopub.status.idle":"2023-10-22T22:27:06.971134Z","shell.execute_reply.started":"2023-10-22T22:27:06.950128Z","shell.execute_reply":"2023-10-22T22:27:06.969864Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_series_baseline = train_series.select(pl.col('id_map'),pl.col(\"step\"),pl.col(\"anglez\"),pl.col(\"enmo\"))","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:27:06.973697Z","iopub.execute_input":"2023-10-22T22:27:06.974191Z","iopub.status.idle":"2023-10-22T22:27:06.979525Z","shell.execute_reply.started":"2023-10-22T22:27:06.974164Z","shell.execute_reply":"2023-10-22T22:27:06.978502Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_series_baseline.collect().write_parquet(\"train_series_baseline_parquets\")","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:27:06.980582Z","iopub.execute_input":"2023-10-22T22:27:06.980867Z","iopub.status.idle":"2023-10-22T22:27:19.104954Z","shell.execute_reply.started":"2023-10-22T22:27:06.980842Z","shell.execute_reply":"2023-10-22T22:27:19.103986Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"series_map_id = pl.scan_parquet(\"/kaggle/input/detect-sleep-states-memory-decrease/train_id_map.parquet\")\n# series_map_id.collect().write_parquet(\"series_map_id\")","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:27:19.106034Z","iopub.execute_input":"2023-10-22T22:27:19.106259Z","iopub.status.idle":"2023-10-22T22:27:19.115237Z","shell.execute_reply.started":"2023-10-22T22:27:19.106238Z","shell.execute_reply":"2023-10-22T22:27:19.113943Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_events = pl.scan_parquet(\"/kaggle/input/detect-sleep-states-memory-decrease/train_events.parquet\")","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:27:19.117136Z","iopub.execute_input":"2023-10-22T22:27:19.117521Z","iopub.status.idle":"2023-10-22T22:27:19.129440Z","shell.execute_reply.started":"2023-10-22T22:27:19.117488Z","shell.execute_reply":"2023-10-22T22:27:19.128676Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(series_map_id.collect())","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:27:19.130379Z","iopub.execute_input":"2023-10-22T22:27:19.131113Z","iopub.status.idle":"2023-10-22T22:27:19.141174Z","shell.execute_reply.started":"2023-10-22T22:27:19.131088Z","shell.execute_reply":"2023-10-22T22:27:19.140383Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_events = train_events.select(pl.col(\"id_map\"),pl.col(\"step\"),pl.col(\"night\"),pl.col(\"event\"))","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:27:19.142624Z","iopub.execute_input":"2023-10-22T22:27:19.143007Z","iopub.status.idle":"2023-10-22T22:27:19.151071Z","shell.execute_reply.started":"2023-10-22T22:27:19.142974Z","shell.execute_reply":"2023-10-22T22:27:19.150139Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"joined_frame =  train_series.join(train_events,on = [\"id_map\",\"step\"],how = \"left\")","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:27:19.154500Z","iopub.execute_input":"2023-10-22T22:27:19.154789Z","iopub.status.idle":"2023-10-22T22:27:19.163366Z","shell.execute_reply.started":"2023-10-22T22:27:19.154764Z","shell.execute_reply":"2023-10-22T22:27:19.162378Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(joined_frame.head(5).collect())","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:27:19.164554Z","iopub.execute_input":"2023-10-22T22:27:19.164801Z","iopub.status.idle":"2023-10-22T22:28:10.285096Z","shell.execute_reply.started":"2023-10-22T22:27:19.164778Z","shell.execute_reply":"2023-10-22T22:28:10.284073Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"joined_frame = joined_frame.with_columns(pl.col(\"timestamp\").dt.day().alias(\"day\"))","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:28:10.286432Z","iopub.execute_input":"2023-10-22T22:28:10.286973Z","iopub.status.idle":"2023-10-22T22:28:10.292300Z","shell.execute_reply.started":"2023-10-22T22:28:10.286940Z","shell.execute_reply":"2023-10-22T22:28:10.291291Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(joined_frame.select(pl.col(\"event\").value_counts()).collect())","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:28:10.295519Z","iopub.execute_input":"2023-10-22T22:28:10.295937Z","iopub.status.idle":"2023-10-22T22:28:16.736629Z","shell.execute_reply.started":"2023-10-22T22:28:10.295900Z","shell.execute_reply":"2023-10-22T22:28:16.734977Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"clearly too much unbalaced ","metadata":{}},{"cell_type":"code","source":"test_series = pl.scan_parquet(\"/kaggle/input/child-mind-institute-detect-sleep-states/test_series.parquet\")\n","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:28:16.738442Z","iopub.execute_input":"2023-10-22T22:28:16.739144Z","iopub.status.idle":"2023-10-22T22:28:16.757550Z","shell.execute_reply.started":"2023-10-22T22:28:16.739102Z","shell.execute_reply":"2023-10-22T22:28:16.755138Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(test_series.head(5).collect())\n\n","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:28:16.760905Z","iopub.execute_input":"2023-10-22T22:28:16.762231Z","iopub.status.idle":"2023-10-22T22:28:16.779062Z","shell.execute_reply.started":"2023-10-22T22:28:16.762181Z","shell.execute_reply":"2023-10-22T22:28:16.776964Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ctritical_events = joined_frame.filter(pl.col(\"event\") != None ).collect()\n\n\n\n","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:28:16.781811Z","iopub.execute_input":"2023-10-22T22:28:16.782222Z","iopub.status.idle":"2023-10-22T22:29:23.273857Z","shell.execute_reply.started":"2023-10-22T22:28:16.782190Z","shell.execute_reply":"2023-10-22T22:29:23.272652Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_size = 5000\nnon_critical_events = joined_frame.filter(pl.col(\"event\") == None ).collect(streaming = True).sample(n=sample_size)","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:29:23.275745Z","iopub.execute_input":"2023-10-22T22:29:23.276273Z","iopub.status.idle":"2023-10-22T22:30:21.274178Z","shell.execute_reply.started":"2023-10-22T22:29:23.276243Z","shell.execute_reply":"2023-10-22T22:30:21.272742Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# non_critical_events[\"event\"] = [3]* len(non_critical_events[\"event\"])\n\nnon_critical_events = non_critical_events.with_columns(pl.col(\"event\").map_batches(lambda x:  3))\n","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:30:21.275763Z","iopub.execute_input":"2023-10-22T22:30:21.276075Z","iopub.status.idle":"2023-10-22T22:30:21.285134Z","shell.execute_reply.started":"2023-10-22T22:30:21.276048Z","shell.execute_reply":"2023-10-22T22:30:21.283776Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"non_critical_events = non_critical_events.sort(\"timestamp\")","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:30:21.286521Z","iopub.execute_input":"2023-10-22T22:30:21.286788Z","iopub.status.idle":"2023-10-22T22:30:21.305032Z","shell.execute_reply.started":"2023-10-22T22:30:21.286759Z","shell.execute_reply":"2023-10-22T22:30:21.303751Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"non_critical_events = non_critical_events.with_columns(pl.col(\"event\").cast(pl.UInt8).alias(\"event\"))","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:30:21.306124Z","iopub.execute_input":"2023-10-22T22:30:21.306401Z","iopub.status.idle":"2023-10-22T22:30:21.314888Z","shell.execute_reply.started":"2023-10-22T22:30:21.306379Z","shell.execute_reply":"2023-10-22T22:30:21.313864Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\ntrain_data = pl.concat(\n    [ctritical_events,\n    non_critical_events],\n    how = \"vertical\"\n)","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:30:21.316407Z","iopub.execute_input":"2023-10-22T22:30:21.316724Z","iopub.status.idle":"2023-10-22T22:30:21.330244Z","shell.execute_reply.started":"2023-10-22T22:30:21.316697Z","shell.execute_reply":"2023-10-22T22:30:21.329189Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:30:21.331553Z","iopub.execute_input":"2023-10-22T22:30:21.332785Z","iopub.status.idle":"2023-10-22T22:30:21.348546Z","shell.execute_reply.started":"2023-10-22T22:30:21.332751Z","shell.execute_reply":"2023-10-22T22:30:21.347402Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data = train_data.sort(\"timestamp\")","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:30:21.351287Z","iopub.execute_input":"2023-10-22T22:30:21.351596Z","iopub.status.idle":"2023-10-22T22:30:21.359883Z","shell.execute_reply.started":"2023-10-22T22:30:21.351574Z","shell.execute_reply":"2023-10-22T22:30:21.358464Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport seaborn as sns","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:30:21.361372Z","iopub.execute_input":"2023-10-22T22:30:21.361781Z","iopub.status.idle":"2023-10-22T22:30:22.052629Z","shell.execute_reply.started":"2023-10-22T22:30:21.361758Z","shell.execute_reply":"2023-10-22T22:30:22.051398Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set(style=\"whitegrid\")\n\n\nplt.figure(figsize=(14, 6))\nsns.lineplot(x='timestamp', y='enmo', data=train_data)\n\n\n\nplt.xlabel('Timestamp')\nplt.ylabel('enmo')\nplt.title('enmo vs timestamp')\n\n\nplt.xticks(rotation=45)\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:30:22.054359Z","iopub.execute_input":"2023-10-22T22:30:22.054631Z","iopub.status.idle":"2023-10-22T22:30:33.400455Z","shell.execute_reply.started":"2023-10-22T22:30:22.054609Z","shell.execute_reply":"2023-10-22T22:30:33.399299Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set(style=\"whitegrid\")\n\n\nplt.figure(figsize=(14, 6))\nsns.lineplot(x='timestamp', y='anglez', data=train_data)\n\n\nplt.xlabel('Timestamp')\nplt.ylabel('anglez')\nplt.title('anglez vs timestamp')\n\n\nplt.xticks(rotation=45)\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:30:33.405255Z","iopub.execute_input":"2023-10-22T22:30:33.405608Z","iopub.status.idle":"2023-10-22T22:30:45.011576Z","shell.execute_reply.started":"2023-10-22T22:30:33.405583Z","shell.execute_reply":"2023-10-22T22:30:45.008708Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:30:45.012980Z","iopub.execute_input":"2023-10-22T22:30:45.013274Z","iopub.status.idle":"2023-10-22T22:30:45.027681Z","shell.execute_reply.started":"2023-10-22T22:30:45.013250Z","shell.execute_reply":"2023-10-22T22:30:45.026397Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\n","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:30:45.028963Z","iopub.execute_input":"2023-10-22T22:30:45.029281Z","iopub.status.idle":"2023-10-22T22:30:53.492603Z","shell.execute_reply.started":"2023-10-22T22:30:45.029250Z","shell.execute_reply":"2023-10-22T22:30:53.491734Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model1_inp = tf.keras.Input(shape = (4),name = \"input\")\nx = tf.keras.layers.Dense(8,activation = \"tanh\")(model1_inp)\nx = tf.keras.layers.Dense(16,activation = \"tanh\")(x)\nx = tf.keras.layers.Dense(4,activation = \"tanh\")(x)\nmodel1_output = tf.keras.layers.Dense(3,activation = \"sigmoid\")(x)","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:30:53.493584Z","iopub.execute_input":"2023-10-22T22:30:53.494145Z","iopub.status.idle":"2023-10-22T22:30:53.664640Z","shell.execute_reply.started":"2023-10-22T22:30:53.494122Z","shell.execute_reply":"2023-10-22T22:30:53.663661Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model1 = tf.keras.Model(model1_inp,model1_output,name = \"model1_base\")","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:30:53.666016Z","iopub.execute_input":"2023-10-22T22:30:53.666313Z","iopub.status.idle":"2023-10-22T22:30:53.676410Z","shell.execute_reply.started":"2023-10-22T22:30:53.666288Z","shell.execute_reply":"2023-10-22T22:30:53.675534Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tf.keras.utils.plot_model(model1, \"model1.png\", show_shapes=True)","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:30:53.677610Z","iopub.execute_input":"2023-10-22T22:30:53.677859Z","iopub.status.idle":"2023-10-22T22:30:53.930779Z","shell.execute_reply.started":"2023-10-22T22:30:53.677837Z","shell.execute_reply":"2023-10-22T22:30:53.930087Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model1.compile(loss=tf.keras.losses.CategoricalCrossentropy(),\n                optimizer=tf.keras.optimizers.Adam(),\n                metrics=['accuracy'])\n","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:30:53.932019Z","iopub.execute_input":"2023-10-22T22:30:53.932326Z","iopub.status.idle":"2023-10-22T22:30:53.951673Z","shell.execute_reply.started":"2023-10-22T22:30:53.932303Z","shell.execute_reply":"2023-10-22T22:30:53.950325Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train = train_data.select(pl.col(\"anglez\"),pl.col(\"enmo\"),pl.col(\"hour\"),pl.col(\"hour_window\"))\ny_train = train_data.select(pl.col(\"event\"))\ny_train_onehot =  tf.one_hot(y_train, depth=3)","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:30:53.952932Z","iopub.execute_input":"2023-10-22T22:30:53.953746Z","iopub.status.idle":"2023-10-22T22:30:53.967294Z","shell.execute_reply.started":"2023-10-22T22:30:53.953719Z","shell.execute_reply":"2023-10-22T22:30:53.965994Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history1 = model1.fit(x_train.to_numpy(), np.array(y_train_onehot).reshape(-1,3), batch_size=32, epochs=3, validation_split=0.2)","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:30:53.969305Z","iopub.execute_input":"2023-10-22T22:30:53.969686Z","iopub.status.idle":"2023-10-22T22:30:57.315596Z","shell.execute_reply.started":"2023-10-22T22:30:53.969659Z","shell.execute_reply":"2023-10-22T22:30:57.314408Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:30:58.064492Z","iopub.execute_input":"2023-10-22T22:30:58.064772Z","iopub.status.idle":"2023-10-22T22:30:58.073208Z","shell.execute_reply.started":"2023-10-22T22:30:58.064750Z","shell.execute_reply":"2023-10-22T22:30:58.072058Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Let see results after normalizing data","metadata":{}},{"cell_type":"code","source":"model2_inp = tf.keras.Input(shape = (6),name = \"input\")\nx = tf.keras.layers.Dense(8,activation = \"tanh\")(model2_inp)\nx = tf.keras.layers.Dense(16,activation = \"tanh\")(x)\nx = tf.keras.layers.Dense(4,activation = \"tanh\")(x)\nmodel2_output = tf.keras.layers.Dense(3,activation = \"sigmoid\")(x)","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:30:58.074794Z","iopub.execute_input":"2023-10-22T22:30:58.075172Z","iopub.status.idle":"2023-10-22T22:30:58.134289Z","shell.execute_reply.started":"2023-10-22T22:30:58.075139Z","shell.execute_reply":"2023-10-22T22:30:58.132878Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model2 = tf.keras.Model(model2_inp,model2_output,name = \"model2_base\")","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:30:58.136222Z","iopub.execute_input":"2023-10-22T22:30:58.136572Z","iopub.status.idle":"2023-10-22T22:30:58.150661Z","shell.execute_reply.started":"2023-10-22T22:30:58.136547Z","shell.execute_reply":"2023-10-22T22:30:58.149321Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tf.keras.utils.plot_model(model2, \"model2.png\", show_shapes=True)","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:30:58.152326Z","iopub.execute_input":"2023-10-22T22:30:58.153126Z","iopub.status.idle":"2023-10-22T22:30:58.206831Z","shell.execute_reply.started":"2023-10-22T22:30:58.153091Z","shell.execute_reply":"2023-10-22T22:30:58.205684Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model2.compile(loss=tf.keras.losses.CategoricalCrossentropy(),\n                optimizer=tf.keras.optimizers.Adam(),\n                metrics=['accuracy'])","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:30:58.208363Z","iopub.execute_input":"2023-10-22T22:30:58.208796Z","iopub.status.idle":"2023-10-22T22:30:58.220677Z","shell.execute_reply.started":"2023-10-22T22:30:58.208763Z","shell.execute_reply":"2023-10-22T22:30:58.219625Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train_model2 = train_data.select(pl.col(\"anglez\"),pl.col(\"enmo\"),pl.col(\"hour_window\"))\nhour_wind = x_train_model2[\"hour_window\"]\nhour_wind_onehot =  tf.one_hot(hour_wind, depth=4)\nhour_wind_onehot = np.array(hour_wind_onehot).reshape(-1,4)\nhour_wind_onehot\n","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:30:58.221870Z","iopub.execute_input":"2023-10-22T22:30:58.222169Z","iopub.status.idle":"2023-10-22T22:30:58.234292Z","shell.execute_reply.started":"2023-10-22T22:30:58.222144Z","shell.execute_reply":"2023-10-22T22:30:58.233389Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train_model2 = pl.concat(\n[\n    x_train,\n    pl.DataFrame(hour_wind_onehot)\n],\nhow = \"horizontal\")\nx_train_model2 = x_train_model2.drop([\"hour_window\",\"hour\"])","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:30:58.236423Z","iopub.execute_input":"2023-10-22T22:30:58.236780Z","iopub.status.idle":"2023-10-22T22:30:58.244283Z","shell.execute_reply.started":"2023-10-22T22:30:58.236750Z","shell.execute_reply":"2023-10-22T22:30:58.243215Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history2 = model2.fit(x_train_model2.to_numpy(), np.array(y_train_onehot).reshape(-1,3), batch_size=16, epochs=3, validation_split=0.3)","metadata":{"execution":{"iopub.status.busy":"2023-10-22T22:30:58.245818Z","iopub.execute_input":"2023-10-22T22:30:58.246214Z","iopub.status.idle":"2023-10-22T22:31:04.127188Z","shell.execute_reply.started":"2023-10-22T22:30:58.246183Z","shell.execute_reply":"2023-10-22T22:31:04.125648Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}