{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.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"},{"sourceId":122144951,"sourceType":"kernelVersion"}],"dockerImageVersionId":31089,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nfrom sklearn.preprocessing import StandardScaler\nimport glob\nfrom torch import nn\nfrom sklearn import *\nimport gc\nimport pickle as p\nimport torch.functional as F\nfrom torch.utils.data import Dataset, DataLoader, TensorDataset\nimport torch\nimport torch.optim as optim\nfrom sklearn.metrics import classification_report","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"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\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n        break\nprint(\"Required Files obtained\")\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","trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def get_data(f):\n    df = pd.read_csv(f)\n    df['Id'] = f.split('/')[-1].split('.')[0]\n    df['data_type'] = f.split('/')[-2]\n    return df\ndef prepare_data():\n    #-----------------------------------\n    path=\"/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/\"\n    train_defog = glob.glob(path+'train/defog/**')\n    train_tdcsfog = glob.glob(path+'train/tdcsfog/**')\n    #-----------------------------------\n    df_train_defog = pd.concat([get_data(f) for f in train_defog])\n    df_train_tdcsfog = pd.concat([get_data(f) for f in train_tdcsfog])\n    #-----------------------------------\n    df_train=pd.concat([df_train_defog,df_train_tdcsfog])\n    #-----------------------------------\n    print(df_train_defog.shape)\n    print(df_train_tdcsfog.shape)\n    \n    print(df_train.shape)\n    #-----------------------------------\n    df_train.fillna(0,inplace=True)\n    print(df_train.isnull().sum().sum())\n    return df_train, df_train_defog, df_train_tdcsfog\ndef present_basic_info(*args):\n    print(df_train[df_train['data_type'] == 'defog'].head())\n    print(df_train[df_train['data_type'] == 'tdcsfog'].head())\n    print(df_train_defog.head())\n    print(df_train_tdcsfog.head())\n    df_train.head()\n\ndef create_datasets(df_train):\n    X_train, X_valid, y_train, y_valid = model_selection.train_test_split(df_train[features], df_train[Targets], test_size=.30, random_state=42)\n    print(f\"X_train : {X_train.shape}; X_valid : {X_valid.shape}\")\n    print(f\"y_train : {y_train.shape}; y_valid : {y_valid.shape}\")\n    return X_train, X_valid, y_train, y_valid\ndef give_Valid_Values(df_train_defog):\n    return df_train_defog[df_train_defog['Valid'] != False]","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_train, df_train_defog, df_train_tdcsfog = prepare_data()\npresent_basic_info(df_train, df_train_defog, df_train_tdcsfog)\nfeatures=['Time', 'AccV', 'AccML', 'AccAP']\nTargets=['StartHesitation', 'Turn' , 'Walking']","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"\nX_train, X_vald, y_train, y_valid = create_datasets(df_train)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-06T09:13:53.928181Z","iopub.execute_input":"2025-11-06T09:13:53.928912Z","iopub.status.idle":"2025-11-06T09:13:59.150653Z","shell.execute_reply.started":"2025-11-06T09:13:53.928881Z","shell.execute_reply":"2025-11-06T09:13:59.149138Z"}},"outputs":[{"name":"stdout","text":"X_train : (14411861, 4); X_valid : (6176513, 4)\ny_train : (14411861, 3); y_valid : (6176513, 3)\n","output_type":"stream"}],"execution_count":9},{"cell_type":"markdown","source":"<h1>Random Forest Model(as used in the reference notebook)</h1>","metadata":{}},{"cell_type":"code","source":"model_Reg = ensemble.RandomForestRegressor(n_estimators=100, max_depth=7, n_jobs=-1, random_state=42)\nmodel_Reg.fit(X_train, y_train)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-06T09:14:53.212781Z","iopub.execute_input":"2025-11-06T09:14:53.214925Z","iopub.status.idle":"2025-11-06T09:52:47.155227Z","shell.execute_reply.started":"2025-11-06T09:14:53.214871Z","shell.execute_reply":"2025-11-06T09:52:47.15277Z"}},"outputs":[{"execution_count":12,"output_type":"execute_result","data":{"text/plain":"RandomForestRegressor(max_depth=7, n_jobs=-1, random_state=42)","text/html":"<style>#sk-container-id-1 {color: black;background-color: white;}#sk-container-id-1 pre{padding: 0;}#sk-container-id-1 div.sk-toggleable {background-color: white;}#sk-container-id-1 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-1 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-1 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-1 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-1 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-1 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-1 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-1 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-1 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-1 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-1 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-1 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-1 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 div.sk-serial::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-1 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-1 div.sk-item {position: relative;z-index: 1;}#sk-container-id-1 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-1 div.sk-item::before, #sk-container-id-1 div.sk-parallel-item::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-1 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-1 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-1 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-1 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-1 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-1 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-1 div.sk-label-container {text-align: center;}#sk-container-id-1 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-1 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-1\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>RandomForestRegressor(max_depth=7, n_jobs=-1, random_state=42)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-1\" type=\"checkbox\" checked><label for=\"sk-estimator-id-1\" class=\"sk-toggleable__label sk-toggleable__label-arrow\">RandomForestRegressor</label><div class=\"sk-toggleable__content\"><pre>RandomForestRegressor(max_depth=7, n_jobs=-1, random_state=42)</pre></div></div></div></div></div>"},"metadata":{}}],"execution_count":12},{"cell_type":"code","source":"print(metrics.average_precision_score(y_valid, model_Reg.predict(X_valid).clip(0.0,1.0)))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-06T09:52:47.159964Z","iopub.execute_input":"2025-11-06T09:52:47.160457Z","iopub.status.idle":"2025-11-06T09:52:47.251118Z","shell.execute_reply.started":"2025-11-06T09:52:47.160423Z","shell.execute_reply":"2025-11-06T09:52:47.249093Z"}},"outputs":[{"traceback":["\u001b[0;31m---------------------------------------------------------------------------\u001b[0m","\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)","\u001b[0;32m/tmp/ipykernel_36/746985419.py\u001b[0m in \u001b[0;36m<cell line: 0>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmetrics\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0maverage_precision_score\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0my_valid\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmodel_Reg\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpredict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX_valid\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mclip\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m0.0\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m1.0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m","\u001b[0;31mNameError\u001b[0m: name 'X_valid' is not defined"],"ename":"NameError","evalue":"name 'X_valid' is not defined","output_type":"error"}],"execution_count":13},{"cell_type":"code","source":"model_Reg.score(X_valid, y_valid)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-06T09:52:47.251755Z","iopub.status.idle":"2025-11-06T09:52:47.252179Z","shell.execute_reply.started":"2025-11-06T09:52:47.251926Z","shell.execute_reply":"2025-11-06T09:52:47.251939Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model_Reg.score(X_train, y_train)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-06T09:52:47.253289Z","iopub.status.idle":"2025-11-06T09:52:47.253693Z","shell.execute_reply.started":"2025-11-06T09:52:47.253554Z","shell.execute_reply":"2025-11-06T09:52:47.253568Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"<h1> Dropping all false values</h1>","metadata":{}},{"cell_type":"code","source":"df_train_AllValid = give_Valid_Values(df_train_defog)\nfeatures=['Time', 'AccV', 'AccML', 'AccAP']\nTargets=['StartHesitation', 'Turn' , 'Walking']","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-06T09:52:47.254385Z","iopub.status.idle":"2025-11-06T09:52:47.254769Z","shell.execute_reply.started":"2025-11-06T09:52:47.254586Z","shell.execute_reply":"2025-11-06T09:52:47.254605Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"x_train, x_test, y_train, y_test = model_selection.train_test_split(df_train_AllValid[features], df_train_AllValid[Targets], test_size=.30, random_state=42)\nprint(f\"X_train : {x_train.shape}; X_valid : {x_test.shape}\")\nprint(f\"y_train : {y_train.shape}; y_valid : {y_test.shape}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-06T09:52:47.255904Z","iopub.status.idle":"2025-11-06T09:52:47.256291Z","shell.execute_reply.started":"2025-11-06T09:52:47.256116Z","shell.execute_reply":"2025-11-06T09:52:47.256133Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"x_train, x_test, y_train, y_test = model_selection.train_test_split(df_train_AllValid[features], df_train_AllValid[Targets], test_size=.30, random_state=42)\nprint(f\"X_train : {x_train.shape}; X_valid : {x_test.shape}\")\nprint(f\"y_train : {y_train.shape}; y_valid : {y_test.shape}\")\nmodel_Reg = ensemble.RandomForestRegressor(n_estimators=100, max_depth=7, random_state=42)\nmodel_Reg.fit(x_train, y_train)\nprint(f\"Precision : {metrics.average_precision_score(y_test, model_Reg.predict(x_test).clip(0.0,1.0))}\")\nprint(f\"Training Accuracy : {model_Reg.score(x_train, y_train)}\")\nprint(f\"Testing Accuracy : {model_Reg.score(x_test, y_test)}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-06T09:52:47.258078Z","iopub.status.idle":"2025-11-06T09:52:47.258546Z","shell.execute_reply.started":"2025-11-06T09:52:47.258298Z","shell.execute_reply":"2025-11-06T09:52:47.258318Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"<h1>Using LSTM</h1>","metadata":{}},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"class Model_LSTM(nn.Module):\n    def __init__(self, input_dim = 4, hidden_dim = 64, layer_dim = 2):\n        super(Model_LSTM, self).__init__()\n        self.input_dim = input_dim\n        self.hidden_dim = hidden_dim\n        self.layer_dim = layer_dim\n        self.lstm = nn.LSTM(\n            input_dim,\n            hidden_dim,\n            layer_dim,\n            batch_first = True\n        )\n        self.fc = nn.Linear(hidden_dim, 4)\n    def forward(self, x):\n        x = x.unsqueeze(1)\n        out, _ = self.lstm(x)\n        out = out[:,-1,:]\n        \n        out = self.fc(out)\n        return out\n#FocalLoss for imbalanced Dataset\nclass FocalLoss(nn.Module):\n    def __init__(self, alpha = None, gamma = 2, reduction = 'mean'):\n        super(FocalLoss, self).__init__()\n        self.alpha = alpha\n        self.gamma = gamma\n        self.reduction = reduction\n\n    def forward(self, inputs, targets):\n        ce_loss = nn.functional.cross_entropy(inputs, targets, weight = self.alpha, reduction='none')          \n        # Compute pt (model confidence on true class)\n        pt = torch.exp(-ce_loss)\n        \n        # Apply the focal adjustment\n        focal_loss = (1 - pt) ** self.gamma * ce_loss\n\n        # Apply reduction (mean, sum, or no reduction)\n        if self.reduction == 'mean':\n            return focal_loss.mean()\n        elif self.reduction == 'sum':\n            return focal_loss.sum()\n        else:\n            return focal_loss\n        \n    \ndef transform_target_labels(y_train, y_test):\n    vector = {0:0, 1:1, 2:2, 4:3}\n    y_train = y_train[\"StartHesitation\"] * 4 + y_train[\"Turn\"] * 2 + y_train[\"Walking\"]\n    y_test = y_test[\"StartHesitation\"] * 4 + y_test[\"Turn\"] * 2 + y_test[\"Walking\"]\n    y_train = np.vectorize(vector.get)(y_train)\n    y_test = np.vectorize(vector.get)(y_test)\n    y_train = torch.tensor(y_train, dtype=torch.long)   # must be long for CrossEntropyLoss\n    \n    y_test = torch.tensor(y_test, dtype=torch.long)\n    return y_train, y_test\n\ndef createDataLoaders(x_train, x_test, y_train, y_test):\n    x_train = torch.tensor(x_train, dtype=torch.float32)\n    x_test = torch.tensor(x_test, dtype=torch.float32)\n    y_train, y_test = transform_target_labels(y_train, y_test)\n    \n    trainData = TensorDataset(x_train, y_train)\n    testData = TensorDataset(x_test, y_test)\n\n    trainLoader = DataLoader(trainData, batch_size=64, shuffle=True)\n    testLoader = DataLoader(testData, batch_size=64, shuffle=True)\n    return trainLoader, testLoader\n\n\nfrom sklearn.metrics import classification_report\nimport torch.nn as nn\nimport torch.optim as optim\n\ndef train_model(model, TrainingSet, TestingSet, epoch=10, lr=0.01, device=\"cuda\"):\n    \n    class_counts = torch.tensor([2383254, 68987, 410776, 354], dtype=torch.float32)\n    class_weights = 1.0 / torch.sqrt(class_counts)\n    class_weights = class_weights / class_weights.sum() * len(class_counts)\n    loss_fn = FocalLoss(alpha=class_weights, gamma=1.5)\n    optimizer = optim.Adam(model.parameters(), lr)\n\n    for i in range(epoch):\n        model.train()\n        total_loss = 0\n        all_preds, all_labels = [], []\n\n        # Training\n        for batch, label in TrainingSet:\n            logits = model(batch)                  # [batch, 4]\n            loss = loss_fn(logits, label)\n\n            optimizer.zero_grad()\n            loss.backward()\n            optimizer.step()\n\n            total_loss += loss.item()\n            \n            preds = torch.argmax(logits, dim=1)\n            all_preds.extend(preds.cpu().numpy())\n            all_labels.extend(label.cpu().numpy())\n\n        print(\"-----------------------------\")\n        print(f\"Epoch : {i+1}/{epoch}\")\n        print(f\"Train Loss : {total_loss/len(TrainingSet):.4f}\")\n        print(\"Train Classification Report:\")\n        print(classification_report(all_labels, all_preds, target_names=[\"0\",\"1\",\"2\",\"4\"], zero_division=0))\n\n        # Evaluation\n        model.eval()\n        test_preds, test_labels = [], []\n        with torch.no_grad():\n            for batch, label in TestingSet:\n                logits = model(batch)\n\n                preds = torch.argmax(logits, dim=1)\n                test_preds.extend(preds.cpu().numpy())\n                test_labels.extend(label.cpu().numpy())\n\n        print(\"Test Classification Report:\")\n        print(classification_report(test_labels, test_preds, target_names=[\"0\",\"1\",\"2\",\"4\"]))\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-06T09:52:47.259804Z","iopub.status.idle":"2025-11-06T09:52:47.260135Z","shell.execute_reply.started":"2025-11-06T09:52:47.259963Z","shell.execute_reply":"2025-11-06T09:52:47.259975Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_train, y_test = transform_target_labels(y_train, y_test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-06T09:52:47.262092Z","iopub.status.idle":"2025-11-06T09:52:47.262501Z","shell.execute_reply.started":"2025-11-06T09:52:47.262324Z","shell.execute_reply":"2025-11-06T09:52:47.262344Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport numpy as np\n\n# Count frequencies for train and test\nlabels, counts_train = np.unique(y_train, return_counts=True)\n_, counts_test = np.unique(y_test, return_counts=True)\n\nx = np.arange(len(labels))  # label positions\nwidth = 0.35  # bar width\n\nplt.bar(x - width/2, counts_train, width, label='Train')\nplt.bar(x + width/2, counts_test, width, label='Test')\n\nplt.xticks(x, labels)\nplt.xlabel(\"Class Labels\")\nplt.ylabel(\"Count\")\nplt.title(\"Class Distribution (Train vs Test)\")\nplt.legend()\nplt.show()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-06T09:13:59.213874Z","iopub.status.idle":"2025-11-06T09:13:59.214236Z","shell.execute_reply.started":"2025-11-06T09:13:59.214101Z","shell.execute_reply":"2025-11-06T09:13:59.214115Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model = Model_LSTM()\ntrainData, testData = createDataLoaders(\n    x_train.to_numpy(),\n    x_test.to_numpy(),\n    y_train,\n    y_test\n)\ntrain_accuracy, test_accuracy, train_loss = train_model(\n    model,\n    trainData,\n    testData,\n    epoch = 1\n)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-06T09:13:59.215233Z","iopub.status.idle":"2025-11-06T09:13:59.215526Z","shell.execute_reply.started":"2025-11-06T09:13:59.215397Z","shell.execute_reply":"2025-11-06T09:13:59.21541Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"total_true = np.zeros((0))\ntotal_pred = np.zeros((0))\nidx = 0\nfor batch, label in trainData:\n    y_pred = model(batch)\n    mapped = torch.tensor([0, 1, 2, 4])\n    t_pred = torch.argmax(y_pred, dim=1)\n    print(t_pred)\n    #print(f\"Accuracy : {corrc/count}\")\n    break","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-06T09:13:59.217487Z","iopub.status.idle":"2025-11-06T09:13:59.218087Z","shell.execute_reply.started":"2025-11-06T09:13:59.217696Z","shell.execute_reply":"2025-11-06T09:13:59.217713Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_train[\"FinalLabel\"] = y_train[\"StartHesitation\"] * 4 + y_train[\"Turn\"] * 2 + y_train[\"Walking\"]\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-06T09:13:59.218844Z","iopub.status.idle":"2025-11-06T09:13:59.219175Z","shell.execute_reply.started":"2025-11-06T09:13:59.218993Z","shell.execute_reply":"2025-11-06T09:13:59.219005Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_train.groupby(\"Label Count\").agg(\n    count = pd.NamedAgg(column = \"Turn\", aggfunc = \"count\")\n)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-06T09:13:59.220168Z","iopub.status.idle":"2025-11-06T09:13:59.220482Z","shell.execute_reply.started":"2025-11-06T09:13:59.220301Z","shell.execute_reply":"2025-11-06T09:13:59.220311Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"29531 + 176053 + 146","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-06T09:13:59.222174Z","iopub.status.idle":"2025-11-06T09:13:59.223525Z","shell.execute_reply.started":"2025-11-06T09:13:59.22334Z","shell.execute_reply":"2025-11-06T09:13:59.223365Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"<h1>Further Simplification of the Dataset</h1>\n<p1>0 in this class label represents cases where no FOG event takes place</p1>\n<p2>The rest are events where some FOG event do in fact take place</p2>\n<p3>By combining the data into a simple 0 and 1 binary, the class imbalance can be potentiall dealt with. It must still be kept in mind that the 0s would still far outweight the 1s</p3>","metadata":{}},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}