{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":41880,"databundleVersionId":5677426,"sourceType":"competition"}],"dockerImageVersionId":30646,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"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)\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\n%config Completer.use_jedi = False\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":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-02-12T09:10:26.669554Z","iopub.execute_input":"2024-02-12T09:10:26.670337Z","iopub.status.idle":"2024-02-12T09:10:26.679611Z","shell.execute_reply.started":"2024-02-12T09:10:26.670301Z","shell.execute_reply":"2024-02-12T09:10:26.678683Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import torch\nimport torch.nn as nn\nimport torch.optim as optim\nfrom torch.utils.data import Dataset\nfrom torch.utils.data import DataLoader\nfrom torch.nn import CrossEntropyLoss\nimport torch.nn.functional as F\nfrom tqdm import tqdm\nimport matplotlib.pyplot as plt\n\npath = '/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/'\ndevice = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\nFeatures = ['AccV', 'AccML', 'AccAP']\nTargets = ['StartHesitation','Turn','Walking']","metadata":{"execution":{"iopub.status.busy":"2024-02-12T09:10:26.681544Z","iopub.execute_input":"2024-02-12T09:10:26.681966Z","iopub.status.idle":"2024-02-12T09:10:26.699532Z","shell.execute_reply.started":"2024-02-12T09:10:26.681935Z","shell.execute_reply":"2024-02-12T09:10:26.698658Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv('/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/train/tdcsfog/0330ea6680.csv')\ndf.head(5)","metadata":{"execution":{"iopub.status.busy":"2024-02-12T09:10:26.700444Z","iopub.execute_input":"2024-02-12T09:10:26.700706Z","iopub.status.idle":"2024-02-12T09:10:26.750002Z","shell.execute_reply.started":"2024-02-12T09:10:26.700684Z","shell.execute_reply":"2024-02-12T09:10:26.749053Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.tail(5)","metadata":{"execution":{"iopub.status.busy":"2024-02-12T09:10:26.752029Z","iopub.execute_input":"2024-02-12T09:10:26.752290Z","iopub.status.idle":"2024-02-12T09:10:26.763920Z","shell.execute_reply.started":"2024-02-12T09:10:26.752269Z","shell.execute_reply":"2024-02-12T09:10:26.763017Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10,5))\nplt.plot(df['Time'],df['AccV'])\nplt.show","metadata":{"execution":{"iopub.status.busy":"2024-02-12T09:10:26.765073Z","iopub.execute_input":"2024-02-12T09:10:26.765380Z","iopub.status.idle":"2024-02-12T09:10:27.013067Z","shell.execute_reply.started":"2024-02-12T09:10:26.765351Z","shell.execute_reply":"2024-02-12T09:10:27.012165Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10,5))\nplt.plot(df['Time'],df['AccML'])\nplt.show","metadata":{"execution":{"iopub.status.busy":"2024-02-12T09:10:27.014215Z","iopub.execute_input":"2024-02-12T09:10:27.014485Z","iopub.status.idle":"2024-02-12T09:10:27.206768Z","shell.execute_reply.started":"2024-02-12T09:10:27.014461Z","shell.execute_reply":"2024-02-12T09:10:27.205852Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10,5))\nplt.plot(df['Time'],df['AccAP'])\nplt.show","metadata":{"execution":{"iopub.status.busy":"2024-02-12T09:10:27.207973Z","iopub.execute_input":"2024-02-12T09:10:27.208264Z","iopub.status.idle":"2024-02-12T09:10:27.409023Z","shell.execute_reply.started":"2024-02-12T09:10:27.208238Z","shell.execute_reply":"2024-02-12T09:10:27.407942Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.describe()","metadata":{"execution":{"iopub.status.busy":"2024-02-12T09:10:27.410436Z","iopub.execute_input":"2024-02-12T09:10:27.410885Z","iopub.status.idle":"2024-02-12T09:10:27.441673Z","shell.execute_reply.started":"2024-02-12T09:10:27.410850Z","shell.execute_reply":"2024-02-12T09:10:27.440758Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tdcsfog_path = '/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/train/tdcsfog'\n\ntdcsfog_list = []\n\nfor file_name in os.listdir(tdcsfog_path):\n    if file_name.endswith('.csv'):\n        file_path = os.path.join(tdcsfog_path, file_name)\n        file = pd.read_csv(file_path)\n        file.Time = file.Time\n        tdcsfog_list.append(file)\n\ntdcsfog = pd.concat(tdcsfog_list, axis = 0)\n\ntdcsfog","metadata":{"execution":{"iopub.status.busy":"2024-02-12T09:10:27.442666Z","iopub.execute_input":"2024-02-12T09:10:27.442930Z","iopub.status.idle":"2024-02-12T09:10:43.766592Z","shell.execute_reply.started":"2024-02-12T09:10:27.442908Z","shell.execute_reply":"2024-02-12T09:10:43.765716Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# reduce memory usage\n# reference : https://www.kaggle.com/code/arjanso/reducing-dataframe-memory-size-by-65 @ARJANGROEN\ndef reduce_memory_usage(df):\n    \n    start_mem = df.memory_usage().sum() / 1024**2\n    print('Memory usage of dataframe is {:.2f} MB'.format(start_mem))\n    \n    for col in df.columns:\n        col_type = df[col].dtype.name\n        if ((col_type != 'datetime64[ns]') & (col_type != 'category')):\n            if (col_type != 'object'):\n                c_min = df[col].min()\n                c_max = df[col].max()\n\n                if str(col_type)[:3] == 'int':\n                    if c_min > np.iinfo(np.int8).min and c_max < np.iinfo(np.int8).max:\n                        df[col] = df[col].astype(np.int8)\n                    elif c_min > np.iinfo(np.int16).min and c_max < np.iinfo(np.int16).max:\n                        df[col] = df[col].astype(np.int16)\n                    elif c_min > np.iinfo(np.int32).min and c_max < np.iinfo(np.int32).max:\n                        df[col] = df[col].astype(np.int32)\n                    elif c_min > np.iinfo(np.int64).min and c_max < np.iinfo(np.int64).max:\n                        df[col] = df[col].astype(np.int64)\n\n                else:\n                    if c_min > np.finfo(np.float16).min and c_max < np.finfo(np.float16).max:\n                        df[col] = df[col].astype(np.float16)\n                    elif c_min > np.finfo(np.float32).min and c_max < np.finfo(np.float32).max:\n                        df[col] = df[col].astype(np.float32)\n                    else:\n                        pass\n            else:\n                df[col] = df[col].astype('category')\n    mem_usg = df.memory_usage().sum() / 1024**2 \n    print(\"Memory usage became: \",mem_usg,\" MB\")\n    \n    return df","metadata":{"execution":{"iopub.status.busy":"2024-02-12T09:10:43.770588Z","iopub.execute_input":"2024-02-12T09:10:43.770944Z","iopub.status.idle":"2024-02-12T09:10:43.784335Z","shell.execute_reply.started":"2024-02-12T09:10:43.770917Z","shell.execute_reply":"2024-02-12T09:10:43.783333Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tdcsfog = reduce_memory_usage(tdcsfog)","metadata":{"execution":{"iopub.status.busy":"2024-02-12T09:10:43.785633Z","iopub.execute_input":"2024-02-12T09:10:43.785991Z","iopub.status.idle":"2024-02-12T09:10:44.079668Z","shell.execute_reply.started":"2024-02-12T09:10:43.785965Z","shell.execute_reply":"2024-02-12T09:10:44.078629Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (12,6))\n\ntdcsfog['Time'] = tdcsfog['Time'].astype('float64')\ntdcsfog_means = tdcsfog.groupby('Time').mean().reset_index()\n\n\nplt.plot(tdcsfog_means['Time'], tdcsfog_means['StartHesitation'], label = 'StartHesitation')\nplt.plot(tdcsfog_means['Time'], tdcsfog_means['Turn'], label = 'Turn')\nplt.plot(tdcsfog_means['Time'], tdcsfog_means['Walking'], label = 'Walking')\nplt.legend()\nplt.xlabel('Time')\nplt.ylabel('Mean Value')\nplt.title('Mean Values of StartHesitation, Turn, and Walking over Time')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-02-12T09:10:44.081031Z","iopub.execute_input":"2024-02-12T09:10:44.081699Z","iopub.status.idle":"2024-02-12T09:10:45.354124Z","shell.execute_reply.started":"2024-02-12T09:10:44.081671Z","shell.execute_reply":"2024-02-12T09:10:45.353198Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df2 = tdcsfog.copy()\ndf2['start']=df2['Time'].eq(0)\ndf2['id']=df2['start'].cumsum()","metadata":{"execution":{"iopub.status.busy":"2024-02-12T09:10:45.355447Z","iopub.execute_input":"2024-02-12T09:10:45.356316Z","iopub.status.idle":"2024-02-12T09:10:45.508183Z","shell.execute_reply.started":"2024-02-12T09:10:45.356280Z","shell.execute_reply":"2024-02-12T09:10:45.507362Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"subject_time_ranges = df2.groupby('id')['Time'].max()\nbins = np.arange(0,60000,1000)\ntime_range_categories = pd.cut(subject_time_ranges, bins)\ntime_range_counts = time_range_categories.value_counts().sort_index()","metadata":{"execution":{"iopub.status.busy":"2024-02-12T09:10:45.509354Z","iopub.execute_input":"2024-02-12T09:10:45.509690Z","iopub.status.idle":"2024-02-12T09:10:45.647628Z","shell.execute_reply.started":"2024-02-12T09:10:45.509659Z","shell.execute_reply":"2024-02-12T09:10:45.646717Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"min(df2.groupby('id')['Time'].max())","metadata":{"execution":{"iopub.status.busy":"2024-02-12T09:10:45.648633Z","iopub.execute_input":"2024-02-12T09:10:45.648898Z","iopub.status.idle":"2024-02-12T09:10:45.769656Z","shell.execute_reply.started":"2024-02-12T09:10:45.648875Z","shell.execute_reply":"2024-02-12T09:10:45.768771Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10, 6))\ntime_range_counts.plot(kind='bar')\nplt.title('Subject')\nplt.xlabel('time')\nplt.ylabel('Subject')\nplt.xticks(rotation=45, fontsize=6)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-02-12T09:10:45.770674Z","iopub.execute_input":"2024-02-12T09:10:45.770983Z","iopub.status.idle":"2024-02-12T09:10:46.477199Z","shell.execute_reply.started":"2024-02-12T09:10:45.770958Z","shell.execute_reply":"2024-02-12T09:10:46.476295Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def read_data(dataset,datatype,ID = None):\n    metadata = pd.read_csv(path+dataset+'_metadata.csv')\n    data_root = path+datatype+'/'+dataset\n    \n    if ID is not None:\n        files = [file for file in files if ID in file]\n        \n    df_res = pd.DataFrame()\n    for root, dirs, files in os.walk(data_root):\n        for name in tqdm(files):\n            f = os.path.join(root, name)\n            query_datatype = pd.read_csv(f)\n            query_datatype['file'] = name.replace('.csv', '')\n            df_res = pd.concat([df_res,query_datatype])\n            \n    df_res = metadata.merge(df_res, how='inner', left_on = 'Id', right_on = 'file')\n    df_res = df_res.drop(['file'], axis = 1)\n    df_res = reduce_memory_usage(df_res)\n    return df_res","metadata":{"execution":{"iopub.status.busy":"2024-02-12T09:10:46.478434Z","iopub.execute_input":"2024-02-12T09:10:46.478851Z","iopub.status.idle":"2024-02-12T09:10:46.488123Z","shell.execute_reply.started":"2024-02-12T09:10:46.478816Z","shell.execute_reply":"2024-02-12T09:10:46.487207Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import LabelEncoder\nclass FOG_dataset(Dataset):\n    def encode_target(self, data, targets_list):\n        conditions = []\n        for target in targets_list:\n            conditions.append((data[target]==1))\n            \n        event = np.select(conditions, targets_list, default='Normal')\n        le = LabelEncoder()\n        return le.fit_transform(event)\n    \n    def get_features_target(self, data, features_list, datatype):\n        if datatype == 'train':\n            features, target = data[features_list], data['target']\n            return features, target\n        else:\n            features = data[features_list]\n            return features\n    \n    def __init__(self, dataset, datatype, features_list, targets_list, lookback):\n        self.datatype = datatype\n        self.data = read_data(dataset = dataset, datatype = datatype)\n        self.features = features_list\n        self.targets = targets_list\n        self.data[\"Id_encoded\"], _ = pd.factorize(self.data[\"Id\"])\n        self.lookback = lookback\n        \n        if datatype == 'train':\n            self.data = self.data[:10000]\n            self.data['target'] = self.encode_target(self.data, self.targets)\n            \n    def __len__(self):\n        return len(self.data)\n    \n    def __getitem__(self, idx):\n        if self.datatype == \"train\":            \n            features, targets = self.get_features_target(self.data,\n                                               self.features,\n                                               self.datatype\n                                              )\n            \n            if idx < self.lookback :\n                features = features[0: self.lookback]\n                targets = targets[self.lookback]\n            \n            else:\n                features = features[idx - self.lookback: idx]\n                targets = targets[idx]\n                \n            features = torch.tensor(features.to_numpy(), dtype=torch.float32)\n            targets = torch.tensor(targets, dtype=torch.float32)\n            \n            return features, targets\n        else:\n            features = self.get_features_target(self.data,\n                                               self.features,\n                                               self.datatype\n                                              )\n            \n            if idx < self.lookback :\n                features = features[0: self.lookback]\n            \n            else:\n                features = features[idx - self.lookback: idx]\n                \n            features = torch.tensor(features.to_numpy(), dtype=torch.float32)\n            \n            return features\n\n        ","metadata":{"execution":{"iopub.status.busy":"2024-02-12T09:10:46.489309Z","iopub.execute_input":"2024-02-12T09:10:46.489612Z","iopub.status.idle":"2024-02-12T09:10:46.909277Z","shell.execute_reply.started":"2024-02-12T09:10:46.489588Z","shell.execute_reply":"2024-02-12T09:10:46.908299Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset_train = FOG_dataset(\n    dataset = \"tdcsfog\",\n    datatype = \"train\",\n    features_list = Features,\n    targets_list = Targets,\n    lookback = 5\n)","metadata":{"execution":{"iopub.status.busy":"2024-02-12T09:10:46.910338Z","iopub.execute_input":"2024-02-12T09:10:46.910756Z","iopub.status.idle":"2024-02-12T09:12:51.037960Z","shell.execute_reply.started":"2024-02-12T09:10:46.910710Z","shell.execute_reply":"2024-02-12T09:12:51.037017Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset_test = FOG_dataset(\n    dataset = \"tdcsfog\",\n    datatype = \"test\",\n    features_list = Features,\n    targets_list = Targets,\n    lookback = 5\n)\n","metadata":{"execution":{"iopub.status.busy":"2024-02-12T09:12:51.039193Z","iopub.execute_input":"2024-02-12T09:12:51.039551Z","iopub.status.idle":"2024-02-12T09:12:51.114553Z","shell.execute_reply.started":"2024-02-12T09:12:51.039518Z","shell.execute_reply":"2024-02-12T09:12:51.113746Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataloader_train = DataLoader(dataset_train, batch_size = 8, shuffle = False)\ndataloader_test = DataLoader(dataset_test, batch_size = 1000, shuffle = False)\n\ncount = 0\n\nfor batch in dataloader_train:\n    features, target = batch\n    features = features.to(device)\n    target = target.to(device)\n    print(\"FEATURES EXAMPLES\")\n    print(features.shape)\n    print(features)\n    print(\"TARGET EXAMPLES\")\n    print(target)\n    print(\"\\n\")\n    if count > 1:  \n        break\n    count += 1\n","metadata":{"execution":{"iopub.status.busy":"2024-02-12T09:12:51.115700Z","iopub.execute_input":"2024-02-12T09:12:51.116050Z","iopub.status.idle":"2024-02-12T09:12:51.627426Z","shell.execute_reply.started":"2024-02-12T09:12:51.116019Z","shell.execute_reply":"2024-02-12T09:12:51.626447Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class LSTM(nn.Module):\n    def __init__(self, input_size, hidden_size, num_layers, num_classes):\n        super().__init__()\n        self.hidden_size = hidden_size\n        self.num_layers = num_layers\n        self.lstm = nn.LSTM(input_size, hidden_size, num_layers, batch_first=True)\n        self.fc1 = nn.Linear(hidden_size, num_classes)\n    def forward(self, x):\n\n        hidden_state = torch.zeros((self.num_layers, x.size(0), self.hidden_size), dtype=torch.float32,device=x.device)\n        cell_state = torch.zeros((self.num_layers, x.size(0), self.hidden_size), dtype=torch.float32,device=x.device)\n\n        out, _ = self.lstm(x, (hidden_state, cell_state))\n        out = out[:, -1,:]\n        out = self.fc1(out)\n        return out","metadata":{"execution":{"iopub.status.busy":"2024-02-12T09:12:51.628484Z","iopub.execute_input":"2024-02-12T09:12:51.628775Z","iopub.status.idle":"2024-02-12T09:12:51.636447Z","shell.execute_reply.started":"2024-02-12T09:12:51.628750Z","shell.execute_reply":"2024-02-12T09:12:51.635547Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def train(model, dataloader, loss_fn, optimizer,device):\n    model.train()\n    total_loss = 0\n    for epoch in range(N_EPOCHS):\n        mean_loss = []\n        for (features_, targets_) in tqdm(dataloader):\n            features_ = features_.to(device)\n            targets_ = targets_.to(device)\n            optimizer.zero_grad()\n            preds = model(features_)\n            loss = loss_fn(preds, targets_.long())\n            mean_loss.append(loss.item())\n            loss.backward()\n            optimizer.step()\n        \n        print(\"Average Loss : \", np.mean(mean_loss))\n    \n    return model\n\ndef predict(model, dataloader): \n    model.eval()\n    predictions = np.empty(len(dataset_test))\n    count = 0\n    for features_ in tqdm(dataloader):\n        features_ = features_.to(device)\n        preds = model(features_)\n        preds = torch.argmax(preds, dim = 1)\n        preds = preds.cpu().numpy()\n        predictions[count : count + len(preds)] = preds\n        count += len(preds)\n            \n    return predictions","metadata":{"execution":{"iopub.status.busy":"2024-02-12T09:45:33.866102Z","iopub.execute_input":"2024-02-12T09:45:33.866474Z","iopub.status.idle":"2024-02-12T09:45:33.875828Z","shell.execute_reply.started":"2024-02-12T09:45:33.866442Z","shell.execute_reply":"2024-02-12T09:45:33.874890Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"INPUT_SIZE = 3\nHIDDEN_SIZE = 100\nNUM_LAYERS = 1\nNUM_CLASSES = 4\nN_EPOCHS = 50\nPARAMS = {\n    \"input_size\" : INPUT_SIZE,\n    \"hidden_size\" : HIDDEN_SIZE,\n    \"num_layers\" : NUM_LAYERS,\n    \"num_classes\" : NUM_CLASSES\n}\nmodel = LSTM(**PARAMS).to(device)\n\nloss_fn = CrossEntropyLoss()\n\noptimizer = optim.Adam(model.parameters(), lr=0.001)\nprint(PARAMS)","metadata":{"execution":{"iopub.status.busy":"2024-02-12T09:12:51.652142Z","iopub.execute_input":"2024-02-12T09:12:51.652495Z","iopub.status.idle":"2024-02-12T09:12:54.132691Z","shell.execute_reply.started":"2024-02-12T09:12:51.652465Z","shell.execute_reply":"2024-02-12T09:12:54.131779Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = train(\n    model, \n    dataloader_train,\n    loss_fn,\n    optimizer,\n    device\n)","metadata":{"execution":{"iopub.status.busy":"2024-02-12T09:12:54.133879Z","iopub.execute_input":"2024-02-12T09:12:54.134340Z","iopub.status.idle":"2024-02-12T09:21:28.761574Z","shell.execute_reply.started":"2024-02-12T09:12:54.134313Z","shell.execute_reply":"2024-02-12T09:21:28.760624Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"preds_tdcsfog = predict(model, dataloader_test)","metadata":{"execution":{"iopub.status.busy":"2024-02-12T09:45:37.217634Z","iopub.execute_input":"2024-02-12T09:45:37.218515Z","iopub.status.idle":"2024-02-12T09:45:40.183497Z","shell.execute_reply.started":"2024-02-12T09:45:37.218481Z","shell.execute_reply":"2024-02-12T09:45:40.182565Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"preds_tdcsfog","metadata":{"execution":{"iopub.status.busy":"2024-02-12T09:45:43.226228Z","iopub.execute_input":"2024-02-12T09:45:43.226568Z","iopub.status.idle":"2024-02-12T09:45:43.234796Z","shell.execute_reply.started":"2024-02-12T09:45:43.226543Z","shell.execute_reply":"2024-02-12T09:45:43.233397Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_tdcsfog = read_data(dataset = \"tdcsfog\", datatype = \"test\")\ntest_defog = read_data(dataset = \"defog\", datatype = \"test\")\n\nlen_test_tdcsfog = len(test_tdcsfog)\nlen_test_defog = len(test_defog)","metadata":{"execution":{"iopub.status.busy":"2024-02-12T09:45:45.164867Z","iopub.execute_input":"2024-02-12T09:45:45.165232Z","iopub.status.idle":"2024-02-12T09:45:45.881674Z","shell.execute_reply.started":"2024-02-12T09:45:45.165205Z","shell.execute_reply":"2024-02-12T09:45:45.880777Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_tdcsfog[\"y_pred\"] = preds_tdcsfog\ntest_defog[\"y_pred\"] = np.zeros(len_test_defog)","metadata":{"execution":{"iopub.status.busy":"2024-02-12T09:45:47.240229Z","iopub.execute_input":"2024-02-12T09:45:47.240958Z","iopub.status.idle":"2024-02-12T09:45:47.246496Z","shell.execute_reply.started":"2024-02-12T09:45:47.240927Z","shell.execute_reply":"2024-02-12T09:45:47.245593Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_fmt = pd.read_csv(\"/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/sample_submission.csv\")","metadata":{"execution":{"iopub.status.busy":"2024-02-12T09:45:48.601296Z","iopub.execute_input":"2024-02-12T09:45:48.602383Z","iopub.status.idle":"2024-02-12T09:45:48.866414Z","shell.execute_reply.started":"2024-02-12T09:45:48.602334Z","shell.execute_reply":"2024-02-12T09:45:48.865624Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_fmt.info()","metadata":{"execution":{"iopub.status.busy":"2024-02-12T09:45:50.002259Z","iopub.execute_input":"2024-02-12T09:45:50.003067Z","iopub.status.idle":"2024-02-12T09:45:50.043080Z","shell.execute_reply.started":"2024-02-12T09:45:50.003037Z","shell.execute_reply":"2024-02-12T09:45:50.042188Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub = pd.DataFrame()\nfor data in [test_tdcsfog, test_defog]:\n    temp = data.copy()\n    temp[\"Id\"] = temp.apply(lambda x : str(x.Id) + \"_\" + str(x.Time), axis = 1)\n    temp['StartHesitation'] = np.where(temp['y_pred']==1, 1, 0)\n    temp['Turn'] = np.where(temp['y_pred']==2, 1, 0)\n    temp['Walking'] = np.where(temp['y_pred']==3, 1, 0)\n    temp = temp[[\"Id\"] + Targets]\n    sub = pd.concat([sub, temp])","metadata":{"execution":{"iopub.status.busy":"2024-02-12T09:45:51.806287Z","iopub.execute_input":"2024-02-12T09:45:51.806916Z","iopub.status.idle":"2024-02-12T09:45:59.024475Z","shell.execute_reply.started":"2024-02-12T09:45:51.806886Z","shell.execute_reply":"2024-02-12T09:45:59.023686Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub.head()","metadata":{"execution":{"iopub.status.busy":"2024-02-12T09:46:00.706707Z","iopub.execute_input":"2024-02-12T09:46:00.707368Z","iopub.status.idle":"2024-02-12T09:46:00.716937Z","shell.execute_reply.started":"2024-02-12T09:46:00.707336Z","shell.execute_reply":"2024-02-12T09:46:00.716022Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_fmt.head()","metadata":{"execution":{"iopub.status.busy":"2024-02-12T09:46:02.503626Z","iopub.execute_input":"2024-02-12T09:46:02.504006Z","iopub.status.idle":"2024-02-12T09:46:02.513573Z","shell.execute_reply.started":"2024-02-12T09:46:02.503976Z","shell.execute_reply":"2024-02-12T09:46:02.512573Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub.to_csv(\"/kaggle/working/submission.csv\", index = False)","metadata":{"execution":{"iopub.status.busy":"2024-02-12T09:46:04.473226Z","iopub.execute_input":"2024-02-12T09:46:04.473585Z","iopub.status.idle":"2024-02-12T09:46:05.097929Z","shell.execute_reply.started":"2024-02-12T09:46:04.473555Z","shell.execute_reply":"2024-02-12T09:46:05.097111Z"},"trusted":true},"execution_count":null,"outputs":[]}]}