{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceId":53666,"databundleVersionId":6589269,"sourceType":"competition"},{"sourceId":6507308,"sourceType":"datasetVersion","datasetId":3706667}],"dockerImageVersionId":30558,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport polars as pl\nimport gc\nfrom tqdm.auto import tqdm \nimport joblib\nfrom datetime import timedelta, date\n\n\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:39:54.087827Z","iopub.execute_input":"2023-11-30T15:39:54.088552Z","iopub.status.idle":"2023-11-30T15:39:54.594085Z","shell.execute_reply.started":"2023-11-30T15:39:54.088514Z","shell.execute_reply":"2023-11-30T15:39:54.593091Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# def feature_extraction(df, istrain = True, step_rolling = 5):\n#     ids = df['series_id'].unique(maintain_order = True)\n    \n#     if (istrain):\n#         df = df.with_columns(\n#             awake = df[\"awake\"].cast(pl.Int8)\n#         )\n\n    \n#     df = df.with_columns(        \n#         year = (df[\"timestamp\"].str.slice(0,4).cast(pl.Int16) - 2000).cast(pl.UInt8),\n#         month = df[\"timestamp\"].str.slice(5,2).cast(pl.Int8),\n#         day = df[\"timestamp\"].str.slice(8,2).cast(pl.Int8),\n#         hour = df[\"timestamp\"].str.slice(11,2).cast(pl.Int8),\n#         minute = df[\"timestamp\"].str.slice(14,2).cast(pl.Int8),\n# #         second = df[\"timestamp\"].str.slice(17,2).cast(pl.Int8),\n#         time_zone = df[\"timestamp\"].str.slice(-5,3).cast(pl.Int32),\n        \n#         enmo =  (pl.col('enmo')*1000).cast(pl.UInt16),\n        \n#         weekday = train[\"timestamp\"].str.slice(0,10).str.to_date().dt.weekday()\n        \n#     )\n    \n#     signal_awake = dict(zip(range(1440), np.sin(np.linspace(0, np.pi, 1440) + 0.208 * np.pi) ** 24))\n#     signal_onset = dict(zip(range(1440), np.sin(np.linspace(0, np.pi, 1440) + 0.555 * np.pi) ** 24))\n#     df = df.with_columns(\n#         (pl.col(\"hour\").cast(pl.Int32)*60 + pl.col(\"minute\").cast(pl.Int32))\n#         .apply(signal_onset.get, return_dtype=pl.Float32)\n#         .alias(\"signal_onset\")\n#     )    \n#     df = df.with_columns(\n#         (pl.col(\"hour\").cast(pl.Int32)*60 + pl.col(\"minute\").cast(pl.Int32))\n#         .apply(signal_awake.get, return_dtype=pl.Float32)\n#         .alias(\"signal_awake\")\n#     )\n\n#     df = df.with_columns(lids = np.maximum(0., tmp['enmo'] - 0.02))\n#     df = df.with_columns(\n#         lids = pl.col('lids').rolling_sum(121, center=True, min_periods=1)\n#     )\n#     df = df.with_columns(lids = 100 / (pl.col('lids') + 1))\n#     df = df.with_columns(\n#         lids = pl.col('lids').rolling_mean(361, center=True, min_periods=1).cast(pl.Float32)\n#     )\n#     gc.collect()\n#     return df\n\n# train = feature_extraction(train)\n# train\n# # list(train['signal_onset'][:10])","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:39:54.5956Z","iopub.execute_input":"2023-11-30T15:39:54.59602Z","iopub.status.idle":"2023-11-30T15:39:54.602228Z","shell.execute_reply.started":"2023-11-30T15:39:54.595992Z","shell.execute_reply":"2023-11-30T15:39:54.601137Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def feature_extraction(df, istrain = True, step_rolling = 5):    \n    ids = df['series_id'].unique(maintain_order = True)\n    \n    if (istrain):\n        df = df.with_columns(\n            awake = df[\"awake\"].cast(pl.Int8)\n        )\n\n    df = df.with_columns(\n        lids = np.maximum(0., df['enmo'] - 0.02),\n        year = (df[\"timestamp\"].str.slice(0,4).cast(pl.Int16) - 2000).cast(pl.UInt8),\n        month = df[\"timestamp\"].str.slice(5,2).cast(pl.Int8),\n        day = df[\"timestamp\"].str.slice(8,2).cast(pl.Int8),\n        hour = df[\"timestamp\"].str.slice(11,2).cast(pl.Int8),\n        minute = df[\"timestamp\"].str.slice(14,2).cast(pl.Int8),\n        second = df[\"timestamp\"].str.slice(17,2).cast(pl.Int8),\n        time_zone = df[\"timestamp\"].str.slice(-5,3).cast(pl.Int32),\n        weekday = df[\"timestamp\"].str.slice(0,10).str.to_date().dt.weekday(),\n\n        enmo =  (pl.col('enmo')*1000).cast(pl.UInt16),\n        )\n    \n    signal_awake = dict(zip(range(1440), np.sin(np.linspace(0, np.pi, 1440) + 0.208 * np.pi) ** 24))\n    signal_onset = dict(zip(range(1440), np.sin(np.linspace(0, np.pi, 1440) + 0.555 * np.pi) ** 24))\n    df = df.with_columns(\n        (pl.col(\"hour\").cast(pl.Int32)*60 + pl.col(\"minute\").cast(pl.Int32))\n        .apply(signal_onset.get, return_dtype=pl.Float32)\n        .alias(\"signal_onset\"),\n        (pl.col(\"hour\").cast(pl.Int32)*60 + pl.col(\"minute\").cast(pl.Int32))\n        .apply(signal_awake.get, return_dtype=pl.Float32)\n        .alias(\"signal_awake\"),\n        df[\"hour\"].cast(pl.Int32)*60 + df[\"minute\"].cast(pl.Int32).alias('hour_minute')\n    )\n    \n    features, feature_cols = [], []\n\n    for mins in [1, 3, 5, 30, 60*2, 60*8] :\n        for var in ['enmo', 'anglez'] :\n            features += [\n                pl.col(var).rolling_mean(12 * mins, center=True, min_periods=1).abs().cast(pl.UInt16).alias(f'{var}_{mins}m_mean'),\n                pl.col(var).rolling_max(12 * mins, center=True, min_periods=1).abs().cast(pl.UInt16).alias(f'{var}_{mins}m_max'),\n                pl.col(var).rolling_std(12 * mins, center=True, min_periods=1).abs().cast(pl.UInt16).alias(f'{var}_{mins}m_std')\n            ]\n            feature_cols += [ \n                f'{var}_{mins}m_mean', f'{var}_{mins}m_max', f'{var}_{mins}m_std'\n            ]\n            # Getting first variations\n            features += [\n                (pl.col(var).diff().abs().rolling_mean(12 * mins, center=True, min_periods=1)*10).abs().cast(pl.UInt32).alias(f'{var}_1v_{mins}m_mean'),\n                (pl.col(var).diff().abs().rolling_max(12 * mins, center=True, min_periods=1)*10).abs().cast(pl.UInt32).alias(f'{var}_1v_{mins}m_max'),\n                (pl.col(var).diff().abs().rolling_std(12 * mins, center=True, min_periods=1)*10).abs().cast(pl.UInt32).alias(f'{var}_1v_{mins}m_std')\n            ]\n            feature_cols += [ \n                f'{var}_1v_{mins}m_mean', f'{var}_1v_{mins}m_max', f'{var}_1v_{mins}m_std'\n            ]\n    # id_cols = ['series_id', 'step', 'timestamp']\n\n    dict_ids2data = {}    \n    for i in tqdm(range(len(ids))):\n    # for i in range(2):\n        print (i,': ', ids[i])\n        dict_ids2data[ids[i]] = df.filter(pl.col(\"series_id\") == ids[i])\n        dict_ids2data[ids[i]] = dict_ids2data[ids[i]].with_columns(\n            features,\n            lids = pl.col('lids').rolling_sum(121, center=True, min_periods=1)\n        )\n                \n        dict_ids2data[ids[i]] = dict_ids2data[ids[i]].with_columns(\n            (100 / (pl.col('lids') + 1)).alias('lids'),\n            pl.col(\"anglez\").rolling_mean(window_size = step_rolling, center = True).cast(pl.Float32).alias(f'anglez_{step_rolling*5}s_smooth'),\n            pl.col(\"enmo\").rolling_mean(window_size = step_rolling, center = True).cast(pl.Float32).alias(f'enmo_{step_rolling*5}s_smooth')\n        )\n        \n        dict_ids2data[ids[i]] = dict_ids2data[ids[i]].fill_null(strategy=\"forward\").fill_null(strategy=\"backward\")\n        \n        dict_ids2data[ids[i]] = dict_ids2data[ids[i]].with_columns(\n            lids = pl.col('lids').rolling_mean(361, center=True, min_periods=1).cast(pl.Float32),\n            anglez_lag_5s = dict_ids2data[ids[i]]['anglez'].shift(periods=1),\n            anglez_lag_10s = dict_ids2data[ids[i]]['anglez'].shift(periods=2),\n            anglez_lag_15s = dict_ids2data[ids[i]]['anglez'].shift(periods=3),\n            anglez_lag_30s = dict_ids2data[ids[i]]['anglez'].shift(periods=6),\n            anglez_lag_60s = dict_ids2data[ids[i]]['anglez'].shift(periods=12),\n            anglez_smooth_lag_30s = dict_ids2data[ids[i]][f'anglez_{step_rolling*5}s_smooth'].cast(pl.Float32).shift(periods=6),\n            anglez_smooth_lag_60s = dict_ids2data[ids[i]][f'anglez_{step_rolling*5}s_smooth'].cast(pl.Float32).shift(periods=12),\n\n            enmo_lag_5s = dict_ids2data[ids[i]]['enmo'].shift(periods=1),\n            enmo_lag_10s = dict_ids2data[ids[i]]['enmo'].shift(periods=2),\n            enmo_lag_15s = dict_ids2data[ids[i]]['enmo'].shift(periods=3),\n            enmo_lag_30s = dict_ids2data[ids[i]]['enmo'].shift(periods=6),\n            enmo_lag_60s = dict_ids2data[ids[i]]['enmo'].shift(periods=12),\n            enmo_smooth_lag_30s = dict_ids2data[ids[i]][f'enmo_{step_rolling*5}s_smooth'].cast(pl.Float32).shift(periods=6),\n            enmo_smooth_lag_60s = dict_ids2data[ids[i]][f'enmo_{step_rolling*5}s_smooth'].cast(pl.Float32).shift(periods=12)\n        )\n        \n        dict_ids2data[ids[i]] = dict_ids2data[ids[i]].fill_null(strategy=\"forward\").fill_null(strategy=\"backward\")\n\n        \n    df = pl.concat([i for i in dict_ids2data.values()], rechunk=True)\n\n    del dict_ids2data\n    gc.collect()\n\n    return df\n\n","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:39:54.603474Z","iopub.execute_input":"2023-11-30T15:39:54.603875Z","iopub.status.idle":"2023-11-30T15:39:54.635555Z","shell.execute_reply.started":"2023-11-30T15:39:54.60385Z","shell.execute_reply":"2023-11-30T15:39:54.634528Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\ntrain = pl.read_parquet('/kaggle/input/zzzs-lightweight-training-dataset-target/Zzzs_train.parquet')\ntrain.head()","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:39:54.637696Z","iopub.execute_input":"2023-11-30T15:39:54.637993Z","iopub.status.idle":"2023-11-30T15:39:55.534369Z","shell.execute_reply.started":"2023-11-30T15:39:54.637968Z","shell.execute_reply":"2023-11-30T15:39:55.533459Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_fe = feature_extraction(train)\n\ntrain_fe","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:39:55.535447Z","iopub.execute_input":"2023-11-30T15:39:55.535737Z","iopub.status.idle":"2023-11-30T15:40:33.822242Z","shell.execute_reply.started":"2023-11-30T15:39:55.535712Z","shell.execute_reply":"2023-11-30T15:40:33.82131Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"c_types = train_fe.dtypes\nc_name = train_fe.columns\n\nprint(len(c_name))\nprint('\\n'.join([\"{}\\t-\\t{}\".format(str(a_), str(b_)) for a_, b_ in zip(c_name, c_types)]))","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:40:33.823611Z","iopub.execute_input":"2023-11-30T15:40:33.823981Z","iopub.status.idle":"2023-11-30T15:40:33.83025Z","shell.execute_reply.started":"2023-11-30T15:40:33.823946Z","shell.execute_reply":"2023-11-30T15:40:33.829278Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\ntest_raw = pl.read_parquet('/kaggle/input/child-mind-institute-detect-sleep-states/test_series.parquet')\ntest_raw.head()","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:40:33.831561Z","iopub.execute_input":"2023-11-30T15:40:33.831925Z","iopub.status.idle":"2023-11-30T15:40:33.847734Z","shell.execute_reply.started":"2023-11-30T15:40:33.8319Z","shell.execute_reply":"2023-11-30T15:40:33.846776Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_fe = feature_extraction(test_raw, False)\n\ntest_fe","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:40:33.848883Z","iopub.execute_input":"2023-11-30T15:40:33.849186Z","iopub.status.idle":"2023-11-30T15:40:34.003732Z","shell.execute_reply.started":"2023-11-30T15:40:33.849161Z","shell.execute_reply":"2023-11-30T15:40:34.002795Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gc.collect()","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:40:34.005042Z","iopub.execute_input":"2023-11-30T15:40:34.00532Z","iopub.status.idle":"2023-11-30T15:40:34.086398Z","shell.execute_reply.started":"2023-11-30T15:40:34.005297Z","shell.execute_reply":"2023-11-30T15:40:34.08534Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport pandas as pd\n\nplt.rcParams[\"figure.figsize\"] = [12.00, 5]\nplt.rcParams[\"figure.autolayout\"] = True\n\ndf = pd.DataFrame(dict(day=np.array(train_fe[\"day\"].take_every(12*60))))\n\nax = sns.countplot(x=\"day\", data=df)\n\nfor p in ax.patches:\n   ax.annotate('{:.1f}'.format(p.get_height()), (p.get_x()+0.25, p.get_height()+0.01))\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:40:34.090051Z","iopub.execute_input":"2023-11-30T15:40:34.090502Z","iopub.status.idle":"2023-11-30T15:40:35.185768Z","shell.execute_reply.started":"2023-11-30T15:40:34.090469Z","shell.execute_reply":"2023-11-30T15:40:35.184792Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport pandas as pd\n\nplt.rcParams[\"figure.figsize\"] = [12.00, 5]\nplt.rcParams[\"figure.autolayout\"] = True\n\ndf = pd.DataFrame(dict(month=np.array(train_fe[\"month\"].take_every(12*60*24))))\n\nax = sns.countplot(x=\"month\", data=df)\n\nfor p in ax.patches:\n   ax.annotate('{:.1f}'.format(p.get_height()), (p.get_x()+0.25, p.get_height()+0.01))\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:40:35.187203Z","iopub.execute_input":"2023-11-30T15:40:35.187615Z","iopub.status.idle":"2023-11-30T15:40:35.62586Z","shell.execute_reply.started":"2023-11-30T15:40:35.187551Z","shell.execute_reply":"2023-11-30T15:40:35.624855Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\ntest_fe.write_csv('test_series.csv')\ntest_fe.write_parquet('test_series.parquet')\ntrain_fe.write_parquet('train_series.parquet')","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:40:35.627088Z","iopub.execute_input":"2023-11-30T15:40:35.627398Z","iopub.status.idle":"2023-11-30T15:40:59.551461Z","shell.execute_reply.started":"2023-11-30T15:40:35.627371Z","shell.execute_reply":"2023-11-30T15:40:59.550456Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# data_dtype = {\n#         \"series_id\": \"category\",\n#         \"step\": \"uint32\",\n#         \"timestamp\": \"str\",\n#         \"anglez\": \"float32\",\n#         \"enmo\": \"float32\",\n#     }\n# data = pd.read_parquet('/kaggle/input/child-mind-institute-detect-sleep-states/test_series.parquet').astype(data_dtype, copy=False)","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:40:59.552979Z","iopub.execute_input":"2023-11-30T15:40:59.553367Z","iopub.status.idle":"2023-11-30T15:40:59.557984Z","shell.execute_reply.started":"2023-11-30T15:40:59.553331Z","shell.execute_reply":"2023-11-30T15:40:59.556981Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nfor dirname, _, filenames in os.walk('/kaggle/working'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:40:59.559161Z","iopub.execute_input":"2023-11-30T15:40:59.559469Z","iopub.status.idle":"2023-11-30T15:40:59.570438Z","shell.execute_reply.started":"2023-11-30T15:40:59.559444Z","shell.execute_reply":"2023-11-30T15:40:59.569475Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import polars as pl\nfrom tqdm.auto import tqdm \nimport gc\ngc.collect()","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:40:59.571725Z","iopub.execute_input":"2023-11-30T15:40:59.572013Z","iopub.status.idle":"2023-11-30T15:40:59.669741Z","shell.execute_reply.started":"2023-11-30T15:40:59.571989Z","shell.execute_reply":"2023-11-30T15:40:59.668761Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = pl.read_parquet('/kaggle/working/train_series.parquet')\ndata.head()","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:40:59.671061Z","iopub.execute_input":"2023-11-30T15:40:59.671415Z","iopub.status.idle":"2023-11-30T15:41:09.618611Z","shell.execute_reply.started":"2023-11-30T15:40:59.671387Z","shell.execute_reply":"2023-11-30T15:41:09.617637Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def split_train_test(df, n_train):\n    ids = df['series_id'].unique(maintain_order = True)\n    dict_ids2data = {}\n\n    # for i in range(2):\n    for i in tqdm(range(len(ids))):\n        print (i,': ', ids[i])\n        dict_ids2data[ids[i]] = df.filter(pl.col(\"series_id\") == ids[i])\n\n    train_ = pl.concat([i for i, i_id in zip(dict_ids2data.values(), range(len(ids))) if i_id <= n_train], rechunk=True)\n    test_ = pl.concat([i for i, i_id in zip(dict_ids2data.values(), range(len(ids))) if i_id > n_train], rechunk=True)\n\n    del dict_ids2data\n    gc.collect()\n    \n    return train_, test_\n\ndef split_Xy_train(df):\n    if ('step' in df.columns):\n        df = df.drop(\"step\")\n    if ('series_id' in df.columns):\n        df = df.drop(\"series_id\")\n    if ('timestamp' in df.columns):\n        df = df.drop(\"timestamp\")\n    return df.drop(\"awake\"), df['awake']\n\ntrain, test = split_train_test(data, 30)\n\nX_train, y_train = split_Xy_train(train)\n\n","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:41:09.620001Z","iopub.execute_input":"2023-11-30T15:41:09.620391Z","iopub.status.idle":"2023-11-30T15:41:17.883018Z","shell.execute_reply.started":"2023-11-30T15:41:09.620357Z","shell.execute_reply":"2023-11-30T15:41:17.882209Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gc.collect()","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:41:17.884344Z","iopub.execute_input":"2023-11-30T15:41:17.884857Z","iopub.status.idle":"2023-11-30T15:41:17.968079Z","shell.execute_reply.started":"2023-11-30T15:41:17.884821Z","shell.execute_reply":"2023-11-30T15:41:17.967101Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train.head()","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:41:17.969439Z","iopub.execute_input":"2023-11-30T15:41:17.969836Z","iopub.status.idle":"2023-11-30T15:41:17.987918Z","shell.execute_reply.started":"2023-11-30T15:41:17.969801Z","shell.execute_reply":"2023-11-30T15:41:17.986943Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train.head()","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:41:17.98903Z","iopub.execute_input":"2023-11-30T15:41:17.989371Z","iopub.status.idle":"2023-11-30T15:41:17.998398Z","shell.execute_reply.started":"2023-11-30T15:41:17.989335Z","shell.execute_reply":"2023-11-30T15:41:17.99741Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"type(X_train)","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:41:17.999748Z","iopub.execute_input":"2023-11-30T15:41:18.000462Z","iopub.status.idle":"2023-11-30T15:41:18.008058Z","shell.execute_reply.started":"2023-11-30T15:41:18.000427Z","shell.execute_reply":"2023-11-30T15:41:18.007096Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"important_features =[\"anglez_1v_480m_max\", \"day\", \"month\", \"signal_onset\", \"anglez_1v_480m_mean\", \"signal_awake\", \"anglez_1v_120m_max\", \"anglez_480m_max\", \"anglez_480m_mean\", \"anglez_480m_std\", \"enmo_1v_480m_max\", \"anglez_1v_480m_std\", \"anglez_120m_max\", \"enmo_480m_max\", \"anglez_1v_120m_mean\", \"weekday\", \"enmo_120m_max\", \"anglez_1v_120m_std\", \"enmo_1v_120m_max\", \"enmo_1v_480m_std\"]","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:41:18.009411Z","iopub.execute_input":"2023-11-30T15:41:18.009785Z","iopub.status.idle":"2023-11-30T15:41:18.017481Z","shell.execute_reply.started":"2023-11-30T15:41:18.009753Z","shell.execute_reply":"2023-11-30T15:41:18.01666Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(important_features)","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:41:18.018657Z","iopub.execute_input":"2023-11-30T15:41:18.018946Z","iopub.status.idle":"2023-11-30T15:41:18.028332Z","shell.execute_reply.started":"2023-11-30T15:41:18.018923Z","shell.execute_reply":"2023-11-30T15:41:18.027538Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:41:18.029471Z","iopub.execute_input":"2023-11-30T15:41:18.029995Z","iopub.status.idle":"2023-11-30T15:41:18.075423Z","shell.execute_reply.started":"2023-11-30T15:41:18.029968Z","shell.execute_reply":"2023-11-30T15:41:18.074473Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(X_train.columns)","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:41:18.077042Z","iopub.execute_input":"2023-11-30T15:41:18.077411Z","iopub.status.idle":"2023-11-30T15:41:18.082394Z","shell.execute_reply.started":"2023-11-30T15:41:18.077376Z","shell.execute_reply":"2023-11-30T15:41:18.081484Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train = X_train.select(important_features)\nX_train.head()","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:41:18.083664Z","iopub.execute_input":"2023-11-30T15:41:18.083943Z","iopub.status.idle":"2023-11-30T15:41:18.096522Z","shell.execute_reply.started":"2023-11-30T15:41:18.083919Z","shell.execute_reply":"2023-11-30T15:41:18.095645Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from catboost import CatBoostClassifier, Pool","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:41:18.09771Z","iopub.execute_input":"2023-11-30T15:41:18.098309Z","iopub.status.idle":"2023-11-30T15:41:18.194496Z","shell.execute_reply.started":"2023-11-30T15:41:18.098276Z","shell.execute_reply":"2023-11-30T15:41:18.193416Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_pool = Pool(X_train.to_pandas(), y_train.to_pandas())","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:41:18.199547Z","iopub.execute_input":"2023-11-30T15:41:18.199944Z","iopub.status.idle":"2023-11-30T15:41:18.642452Z","shell.execute_reply.started":"2023-11-30T15:41:18.199912Z","shell.execute_reply":"2023-11-30T15:41:18.641397Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = CatBoostClassifier(iterations=1000,\n                           task_type=\"GPU\",\n                           loss_function = \"Logloss\",\n                           learning_rate=0.01)","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:41:18.643699Z","iopub.execute_input":"2023-11-30T15:41:18.64401Z","iopub.status.idle":"2023-11-30T15:41:18.648771Z","shell.execute_reply.started":"2023-11-30T15:41:18.643985Z","shell.execute_reply":"2023-11-30T15:41:18.647828Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.fit(train_pool,\n          verbose=False)","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:41:18.649789Z","iopub.execute_input":"2023-11-30T15:41:18.650118Z"},"trusted":true},"execution_count":null,"outputs":[]}]}