{"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":"code","source":"# Data Analysis & Visualization\nimport os\nimport numpy as np \nimport pandas as pd\nimport seaborn as sns\nimport matplotlib.pyplot as plt\n\nimport pandas as pd\nimport numpy as np\nimport torch\nimport torch.nn as nn\nimport glob\nimport gc\nfrom pathlib import Path\nfrom sklearn.preprocessing import StandardScaler\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import accuracy_score","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-04-20T23:48:45.014266Z","iopub.execute_input":"2023-04-20T23:48:45.015077Z","iopub.status.idle":"2023-04-20T23:48:48.404882Z","shell.execute_reply.started":"2023-04-20T23:48:45.015037Z","shell.execute_reply":"2023-04-20T23:48:48.403373Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"FEATURES = [\"AccV\", \"AccML\", \"AccAP\"]\nTARGETS = [\"StartHesitation\", \"Turn\", \"Walking\"]","metadata":{"execution":{"iopub.status.busy":"2023-04-20T23:48:48.408430Z","iopub.execute_input":"2023-04-20T23:48:48.409649Z","iopub.status.idle":"2023-04-20T23:48:48.415378Z","shell.execute_reply.started":"2023-04-20T23:48:48.409593Z","shell.execute_reply":"2023-04-20T23:48:48.414434Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Read in the train and test data\n# train_df = pd.read_csv(\"/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/train/defog/0c55be4384.csv\")\n# test_df = pd.read_csv(\"/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/test/defog/02ab235146.csv\")\n# train_df.head()","metadata":{"execution":{"iopub.status.busy":"2023-04-20T23:48:48.416848Z","iopub.execute_input":"2023-04-20T23:48:48.417798Z","iopub.status.idle":"2023-04-20T23:48:48.434064Z","shell.execute_reply.started":"2023-04-20T23:48:48.417754Z","shell.execute_reply":"2023-04-20T23:48:48.432702Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#test_df.head()","metadata":{"execution":{"iopub.status.busy":"2023-04-20T23:48:48.435959Z","iopub.execute_input":"2023-04-20T23:48:48.436643Z","iopub.status.idle":"2023-04-20T23:48:48.446126Z","shell.execute_reply.started":"2023-04-20T23:48:48.436588Z","shell.execute_reply":"2023-04-20T23:48:48.445070Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#path=\"../input/tlvmc-parkinsons-freezing-gait-prediction/\"\n# path=\"/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/\"\n\n# train_defog = glob.glob(path+'train/**/**')\n# train_tdcsfog = glob.glob(path+'test/**/**')\n\npath=\"../input/tlvmc-parkinsons-freezing-gait-prediction/\"\n\ntrain_defog = glob.glob(path+'train/**/**')\ntrain_tdcsfog = glob.glob(path+'test/**/**')\n\n","metadata":{"execution":{"iopub.status.busy":"2023-04-20T23:48:48.449024Z","iopub.execute_input":"2023-04-20T23:48:48.449396Z","iopub.status.idle":"2023-04-20T23:48:48.538738Z","shell.execute_reply.started":"2023-04-20T23:48:48.449361Z","shell.execute_reply":"2023-04-20T23:48:48.537077Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# func read data \ndef reader(f):\n    df = pd.read_csv(f)\n    df['Id'] = f.split('/')[-1].split('.')[0]\n    return df\n# read train data\ntrain_defog = pd.concat([reader(f) for f in train_defog]).fillna(0); print(train_defog.shape)\ncols = [c for c in train_defog.columns if c not in ['Id', 'StartHesitation', 'Turn' , 'Walking', 'Valid', 'Task','Event']] # except categorical and target fetaure","metadata":{"execution":{"iopub.status.busy":"2023-04-20T23:48:48.540270Z","iopub.execute_input":"2023-04-20T23:48:48.540658Z","iopub.status.idle":"2023-04-20T23:50:21.183604Z","shell.execute_reply.started":"2023-04-20T23:48:48.540620Z","shell.execute_reply":"2023-04-20T23:50:21.181451Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_defog.head()","metadata":{"execution":{"iopub.status.busy":"2023-04-20T23:50:21.187344Z","iopub.execute_input":"2023-04-20T23:50:21.189208Z","iopub.status.idle":"2023-04-20T23:50:21.251994Z","shell.execute_reply.started":"2023-04-20T23:50:21.189155Z","shell.execute_reply":"2023-04-20T23:50:21.250480Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_tdcsfog = pd.concat([reader(f) for f in train_tdcsfog]).fillna(0); print(train_tdcsfog.shape)","metadata":{"execution":{"iopub.status.busy":"2023-04-20T23:50:21.253343Z","iopub.execute_input":"2023-04-20T23:50:21.253810Z","iopub.status.idle":"2023-04-20T23:50:21.820978Z","shell.execute_reply.started":"2023-04-20T23:50:21.253776Z","shell.execute_reply":"2023-04-20T23:50:21.819661Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_tdcsfog","metadata":{"execution":{"iopub.status.busy":"2023-04-20T23:50:21.822738Z","iopub.execute_input":"2023-04-20T23:50:21.823083Z","iopub.status.idle":"2023-04-20T23:50:21.840820Z","shell.execute_reply.started":"2023-04-20T23:50:21.823050Z","shell.execute_reply":"2023-04-20T23:50:21.839690Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train=pd.concat([train_defog,train_tdcsfog])","metadata":{"execution":{"iopub.status.busy":"2023-04-20T23:50:21.842419Z","iopub.execute_input":"2023-04-20T23:50:21.843119Z","iopub.status.idle":"2023-04-20T23:50:27.724031Z","shell.execute_reply.started":"2023-04-20T23:50:21.843081Z","shell.execute_reply":"2023-04-20T23:50:27.722787Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"new_train = df_train.fillna(0)","metadata":{"execution":{"iopub.status.busy":"2023-04-20T23:50:27.725419Z","iopub.execute_input":"2023-04-20T23:50:27.725787Z","iopub.status.idle":"2023-04-20T23:50:48.609194Z","shell.execute_reply.started":"2023-04-20T23:50:27.725753Z","shell.execute_reply":"2023-04-20T23:50:48.608043Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"new_train","metadata":{"execution":{"iopub.status.busy":"2023-04-20T23:50:48.611653Z","iopub.execute_input":"2023-04-20T23:50:48.612633Z","iopub.status.idle":"2023-04-20T23:50:48.638042Z","shell.execute_reply.started":"2023-04-20T23:50:48.612585Z","shell.execute_reply":"2023-04-20T23:50:48.636618Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# X = new_train.iloc[:, 1:-1].values\n# y = new_train.iloc[:, -1].values\n\n# X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)","metadata":{"execution":{"iopub.status.busy":"2023-04-20T23:50:48.640053Z","iopub.execute_input":"2023-04-20T23:50:48.640654Z","iopub.status.idle":"2023-04-20T23:50:48.647121Z","shell.execute_reply.started":"2023-04-20T23:50:48.640606Z","shell.execute_reply":"2023-04-20T23:50:48.646159Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#sc = StandardScaler()\n# X_train = sc.fit_transform(X_train)\n# X_test = sc.transform(X_test)","metadata":{"execution":{"iopub.status.busy":"2023-04-20T23:50:48.652666Z","iopub.execute_input":"2023-04-20T23:50:48.653726Z","iopub.status.idle":"2023-04-20T23:50:48.659276Z","shell.execute_reply.started":"2023-04-20T23:50:48.653670Z","shell.execute_reply":"2023-04-20T23:50:48.657700Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# class Net(nn.Module):\n#     def __init__(self, input_size, hidden_size, num_classes):\n#         super(Net, self).__init__()\n#         self.fc1 = nn.Linear(input_size, hidden_size) \n#         self.relu = nn.ReLU()\n#         self.fc2 = nn.Linear(hidden_size, num_classes)  \n    \n#     def forward(self, x):\n#         out = self.fc1(x)\n#         out = self.relu(out)\n#         out = self.fc2(out)\n#         return out","metadata":{"execution":{"iopub.status.busy":"2023-04-20T23:50:48.660988Z","iopub.execute_input":"2023-04-20T23:50:48.661343Z","iopub.status.idle":"2023-04-20T23:50:48.674465Z","shell.execute_reply.started":"2023-04-20T23:50:48.661308Z","shell.execute_reply":"2023-04-20T23:50:48.673296Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# input_size = X_train.shape[1]\n# hidden_size = 10\n# num_classes = 2\n# net = Net(input_size, hidden_size, num_classes)\n\n# criterion = nn.CrossEntropyLoss()\n# optimizer = torch.optim.Adam(net.parameters(), lr=0.001)\n\n# num_epochs = 100\n# for epoch in range(num_epochs):\n#     inputs = torch.from_numpy(X_train).float()\n#     targets = torch.from_numpy(y_train).long()\n\n#     optimizer.zero_grad()\n#     outputs = net(inputs)\n#     loss = criterion(outputs, targets)\n#     loss.backward()\n#     optimizer.step()\n\n#     if (epoch+1) % 10 == 0:\n#         print('Epoch [{}/{}], Loss: {:.4f}'.format(epoch+1, num_epochs, loss.item()))","metadata":{"execution":{"iopub.status.busy":"2023-04-20T23:50:48.676499Z","iopub.execute_input":"2023-04-20T23:50:48.677002Z","iopub.status.idle":"2023-04-20T23:50:48.685038Z","shell.execute_reply.started":"2023-04-20T23:50:48.676945Z","shell.execute_reply":"2023-04-20T23:50:48.684005Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# inputs = torch.from_numpy(X_test).float()\n# outputs = net(inputs)\n# _, predicted = torch.max(outputs.data, 1)\n\n# print('Accuracy:', accuracy_score(y_test, predicted))","metadata":{"execution":{"iopub.status.busy":"2023-04-20T23:50:48.686876Z","iopub.execute_input":"2023-04-20T23:50:48.687306Z","iopub.status.idle":"2023-04-20T23:50:48.695663Z","shell.execute_reply.started":"2023-04-20T23:50:48.687263Z","shell.execute_reply":"2023-04-20T23:50:48.694463Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cols = ['Id','StartHesitation','Turn','Walking']\ntest = df_train[cols]","metadata":{"execution":{"iopub.status.busy":"2023-04-20T23:50:48.697687Z","iopub.execute_input":"2023-04-20T23:50:48.698141Z","iopub.status.idle":"2023-04-20T23:50:49.440966Z","shell.execute_reply.started":"2023-04-20T23:50:48.698096Z","shell.execute_reply":"2023-04-20T23:50:49.439617Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub = pd.read_csv(path+'sample_submission.csv')\nsubmission = pd.merge(sub[['Id']], test, how='left', on='Id').fillna(0.0)\nsubmission[['Id','StartHesitation', 'Turn' , 'Walking']].to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2023-04-20T23:50:49.442488Z","iopub.execute_input":"2023-04-20T23:50:49.442889Z","iopub.status.idle":"2023-04-20T23:50:54.282480Z","shell.execute_reply.started":"2023-04-20T23:50:49.442852Z","shell.execute_reply":"2023-04-20T23:50:54.281162Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission","metadata":{"execution":{"iopub.status.busy":"2023-04-20T23:50:54.283916Z","iopub.execute_input":"2023-04-20T23:50:54.284275Z","iopub.status.idle":"2023-04-20T23:50:54.301793Z","shell.execute_reply.started":"2023-04-20T23:50:54.284240Z","shell.execute_reply":"2023-04-20T23:50:54.300855Z"},"trusted":true},"execution_count":null,"outputs":[]}]}