{"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":"markdown","source":"# Creating Sequential Dataset for LSTM type models","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nfrom tqdm.auto import tqdm","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-09-02T17:22:36.973959Z","iopub.execute_input":"2021-09-02T17:22:36.974395Z","iopub.status.idle":"2021-09-02T17:22:37.136102Z","shell.execute_reply.started":"2021-09-02T17:22:36.974300Z","shell.execute_reply":"2021-09-02T17:22:37.135291Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Reading the dataset and dropping the ['CATEGORY_1', 'CATEGORY_2'] because we found out that they are not important for sequential models.","metadata":{}},{"cell_type":"code","source":"train_df = pd.read_csv('../input/beyond-analysis/train.csv')\ntrain_df.drop(columns = ['CATEGORY_1', 'CATEGORY_2'], axis=0, inplace = True)\ntrain_df.head()","metadata":{"execution":{"iopub.status.busy":"2021-09-02T17:39:09.676979Z","iopub.execute_input":"2021-09-02T17:39:09.677349Z","iopub.status.idle":"2021-09-02T17:39:14.240021Z","shell.execute_reply.started":"2021-09-02T17:39:09.677315Z","shell.execute_reply":"2021-09-02T17:39:14.239070Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"All the unique users in the dataset.","metadata":{}},{"cell_type":"code","source":"users = train_df['UNIQUE_IDENTIFIER'].unique()","metadata":{"execution":{"iopub.status.busy":"2021-09-02T17:37:11.832159Z","iopub.execute_input":"2021-09-02T17:37:11.832837Z","iopub.status.idle":"2021-09-02T17:37:11.896942Z","shell.execute_reply.started":"2021-09-02T17:37:11.832781Z","shell.execute_reply":"2021-09-02T17:37:11.895913Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df[train_df['UNIQUE_IDENTIFIER'] == users[0]]","metadata":{"execution":{"iopub.status.busy":"2021-09-02T17:37:40.807618Z","iopub.execute_input":"2021-09-02T17:37:40.807956Z","iopub.status.idle":"2021-09-02T17:37:40.874050Z","shell.execute_reply.started":"2021-09-02T17:37:40.807929Z","shell.execute_reply":"2021-09-02T17:37:40.872983Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x = {}\ny = {}\n\nfor i in tqdm(users):\n    train_i = train_df[train_df['UNIQUE_IDENTIFIER'] == i]\n    x_i = train_i.loc[:,'STATUS_CHECK': 'PRACTICE_WINNINGS_NUMBER']\n    y_i = train_i.loc[:,'Y1': 'Y2']\n    x[i] = np.array(x_i)\n    y[i] = np.array(y_i)[0]","metadata":{"execution":{"iopub.status.busy":"2021-09-02T17:43:27.903097Z","iopub.execute_input":"2021-09-02T17:43:27.903507Z","iopub.status.idle":"2021-09-02T17:43:27.984031Z","shell.execute_reply.started":"2021-09-02T17:43:27.903470Z","shell.execute_reply":"2021-09-02T17:43:27.982937Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = {}\nY = {}\nfor k in tqdm(x.keys()):\n    X[str(k)] = x[k].tolist()\n    Y[str(k)] = y[k].tolist()","metadata":{"execution":{"iopub.status.busy":"2021-09-02T17:38:26.133446Z","iopub.status.idle":"2021-09-02T17:38:26.133924Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import json\nwith open('./' + 'x_train.json', 'w') as fp:\n    json.dump(X, fp)\nwith open('./' + 'y_train.json', 'w') as fp:\n    json.dump(Y, fp)","metadata":{"execution":{"iopub.status.busy":"2021-09-02T17:38:26.134674Z","iopub.status.idle":"2021-09-02T17:38:26.135180Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df = pd.read_csv('../input/beyond-analysis/test.csv')\ntest_df.drop(columns = ['CATEGORY_1', 'CATEGORY_2'], axis=0, inplace = True)\nusers_test = test_df['UNIQUE_IDENTIFIER'].unique()\ntest_df.head()\n\nx = {}\n\nfor i in tqdm(users_test):\n    test_i = test_df[test_df['UNIQUE_IDENTIFIER'] == i]\n    x_i = test_i.loc[:,'STATUS_CHECK': 'PRACTICE_WINNINGS_NUMBER']\n    x[i] = np.array(x_i)\n    \ntest_X = {}\nfor k in tqdm(x.keys()):\n    test_X[str(k)] = x[k].tolist()\n\nimport json\nwith open('./' + 'x_test.json', 'w') as fp:\n    json.dump(test_X, fp)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"https://www.kaggle.com/aayush9753/techniche-lstm-version-3-data","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}