{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.10","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"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\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":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-09-09T05:14:57.696289Z","iopub.execute_input":"2023-09-09T05:14:57.696887Z","iopub.status.idle":"2023-09-09T05:14:57.714034Z","shell.execute_reply.started":"2023-09-09T05:14:57.696856Z","shell.execute_reply":"2023-09-09T05:14:57.713113Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv(\"/kaggle/input/gait-data-processing/train_set.csv\")\nval = pd.read_csv(\"/kaggle/input/gait-data-processing/labels_train_set.csv\")\ntest = np.load(\"/kaggle/input/gait-data-processing/test_set.npy\")","metadata":{"execution":{"iopub.status.busy":"2023-09-09T05:14:57.716390Z","iopub.execute_input":"2023-09-09T05:14:57.717045Z","iopub.status.idle":"2023-09-09T05:15:36.602992Z","shell.execute_reply.started":"2023-09-09T05:14:57.717011Z","shell.execute_reply":"2023-09-09T05:15:36.601983Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.shape","metadata":{"execution":{"iopub.status.busy":"2023-09-09T05:15:36.606702Z","iopub.execute_input":"2023-09-09T05:15:36.606995Z","iopub.status.idle":"2023-09-09T05:15:36.619007Z","shell.execute_reply.started":"2023-09-09T05:15:36.606969Z","shell.execute_reply":"2023-09-09T05:15:36.618056Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.shape","metadata":{"execution":{"iopub.status.busy":"2023-09-09T05:15:36.621029Z","iopub.execute_input":"2023-09-09T05:15:36.621400Z","iopub.status.idle":"2023-09-09T05:15:36.643059Z","shell.execute_reply.started":"2023-09-09T05:15:36.621365Z","shell.execute_reply":"2023-09-09T05:15:36.641951Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['angle'] = val['angle']\ndel train['ID']\ndel train['Subject']\ndel train['Session']\ndel train['Time:512Hz']","metadata":{"execution":{"iopub.status.busy":"2023-09-09T05:15:36.647383Z","iopub.execute_input":"2023-09-09T05:15:36.647698Z","iopub.status.idle":"2023-09-09T05:15:36.664157Z","shell.execute_reply.started":"2023-09-09T05:15:36.647671Z","shell.execute_reply":"2023-09-09T05:15:36.663115Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train","metadata":{"execution":{"iopub.status.busy":"2023-09-09T05:15:36.665762Z","iopub.execute_input":"2023-09-09T05:15:36.666463Z","iopub.status.idle":"2023-09-09T05:15:36.697145Z","shell.execute_reply.started":"2023-09-09T05:15:36.666426Z","shell.execute_reply":"2023-09-09T05:15:36.696042Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.columns = ['fp1','fp2','f3','f4','fc1','fc2','c4','c3','cz','cp2','cp1','p4','pz','p3','o2','o1','angle']","metadata":{"execution":{"iopub.status.busy":"2023-09-09T05:15:36.698857Z","iopub.execute_input":"2023-09-09T05:15:36.699295Z","iopub.status.idle":"2023-09-09T05:15:36.705257Z","shell.execute_reply.started":"2023-09-09T05:15:36.699255Z","shell.execute_reply":"2023-09-09T05:15:36.704070Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.corr()['angle']","metadata":{"execution":{"iopub.status.busy":"2023-09-09T05:15:36.706980Z","iopub.execute_input":"2023-09-09T05:15:36.707707Z","iopub.status.idle":"2023-09-09T05:15:39.381055Z","shell.execute_reply.started":"2023-09-09T05:15:36.707672Z","shell.execute_reply":"2023-09-09T05:15:39.380058Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\n\ny = train['angle']\ndel train['angle']\nX = train\n\ntrain_X, val_X, train_y, val_y = train_test_split(X, y)","metadata":{"execution":{"iopub.status.busy":"2023-09-09T05:15:39.382270Z","iopub.execute_input":"2023-09-09T05:15:39.382895Z","iopub.status.idle":"2023-09-09T05:15:40.896563Z","shell.execute_reply.started":"2023-09-09T05:15:39.382859Z","shell.execute_reply":"2023-09-09T05:15:40.895525Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pip install tensorflow-gpu","metadata":{"execution":{"iopub.status.busy":"2023-09-09T05:15:40.897917Z","iopub.execute_input":"2023-09-09T05:15:40.898371Z","iopub.status.idle":"2023-09-09T05:15:46.072790Z","shell.execute_reply.started":"2023-09-09T05:15:40.898336Z","shell.execute_reply":"2023-09-09T05:15:46.071452Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"## import numpy as np\nfrom sklearn.preprocessing import StandardScaler\nfrom sklearn.model_selection import train_test_split\nimport tensorflow as tf\nfrom tensorflow import keras\nfrom tensorflow.keras import layers, callbacks\n\n# Normalize the features using StandardScaler\nscaler = StandardScaler()\ntrain_X = scaler.fit_transform(train_X)\nval_X = scaler.transform(val_X)\n\n# Define the neural network architecture\nmodel = keras.Sequential([\n    layers.Dense(256, activation='relu', input_shape=(train_X.shape[1],)),\n    layers.Dropout(0.3),\n    layers.Dense(256, activation='relu'),\n    layers.Dropout(0.3),\n    layers.Dense(256, activation='relu'),\n    layers.Dropout(0.3),\n    layers.Dense(256, activation='relu'),\n    layers.Dropout(0.3),\n    layers.Dense(128, activation='relu'),\n    layers.Dropout(0.3),\n    layers.Dense(128, activation='relu'),\n    layers.Dropout(0.3),\n    layers.Dense(128, activation='relu'),\n    layers.Dropout(0.3),\n    layers.Dense(128, activation='relu'),\n    layers.Dropout(0.3),\n    layers.Dense(64, activation='relu'),\n    layers.Dropout(0.3),\n    layers.Dense(64, activation='relu'),\n    layers.Dropout(0.3),\n    layers.Dense(64, activation='relu'),\n    layers.Dropout(0.3),\n    layers.Dense(64, activation='relu'),\n    layers.Dropout(0.3),\n    layers.Dense(32, activation='relu'),\n    layers.Dropout(0.3),\n    layers.Dense(32, activation='relu'),\n    layers.Dropout(0.3),\n    layers.Dense(32, activation='relu'),\n    layers.Dropout(0.3),\n    layers.Dense(32, activation='relu'),\n    layers.Dropout(0.3),\n    layers.Dense(1)\n])\n\n# Define a learning rate schedule for the optimizer\nlr_schedule = tf.keras.optimizers.schedules.ExponentialDecay(\n    initial_learning_rate=0.001,\n    decay_steps=10000,\n    decay_rate=0.9\n)\n\n# Compile the model\nmodel.compile(optimizer = 'adam', loss = 'mean_squared_error')\n\nearly_stopping = callbacks.EarlyStopping(monitor='val_loss', patience = 10, restore_best_weights = True)\n\n\n# Assuming you have the GPU-compatible TensorFlow and your data\n# Convert data to TensorFlow tensors and place them on the GPU\ntrain_X_tensor = tf.convert_to_tensor(train_X, dtype=tf.float32)\nval_X_tensor = tf.convert_to_tensor(val_X, dtype=tf.float32)\ntrain_y_tensor = tf.convert_to_tensor(train_y, dtype=tf.float32)\nval_y_tensor = tf.convert_to_tensor(val_y, dtype=tf.float32)\n\n# Train the model\nmodel.fit(train_X_tensor, train_y_tensor, epochs = 1, batch_size = 5, validation_data=(val_X_tensor, val_y_tensor), callbacks = [early_stopping])\n\n# Evaluate the model\nval_loss = model.evaluate(val_X, val_y)\nprint(\"Validation RMSE:\", np.sqrt(val_loss))","metadata":{"execution":{"iopub.status.busy":"2023-09-09T05:15:46.074991Z","iopub.execute_input":"2023-09-09T05:15:46.075427Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred = []\n\nfor i in range(36070):\n    pred.append(model.predict(test[i].T).mean())","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ids = []\n\nfor x in range(len(test)):\n    ids.append(x)\n\noutput = pd.DataFrame({'id': ids, 'Angle': pred})\noutput.to_csv('submission.csv', index = False)\nprint('Your submission was successfully saved!')","metadata":{"trusted":true},"execution_count":null,"outputs":[]}],"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"}}