{"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":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n# import tensorflow as tf\nfrom tensorflow import keras\n\nimport matplotlib.pyplot as plt\nfrom tensorflow.keras.models import load_model\nfrom tensorflow.keras.preprocessing.sequence import pad_sequences\nimport gc\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-04-28T04:11:17.400968Z","iopub.execute_input":"2023-04-28T04:11:17.401659Z","iopub.status.idle":"2023-04-28T04:11:28.690956Z","shell.execute_reply.started":"2023-04-28T04:11:17.401619Z","shell.execute_reply":"2023-04-28T04:11:28.689693Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# feature engineer","metadata":{}},{"cell_type":"code","source":"# GP1 = '0-4'\n# GP2 = '5-12'\n# GP3 = '13-22'\n\n# cut_len = {GP1:169,GP2:376,GP3:572}\n# grp=[GP1,GP2,GP3]\ndef test_engineer(df):\n#     df = df.loc[:,['session_id','elapsed_time','level_group']]\n    df = df.loc[:, [\"elapsed_time\"]]\n    df.elapsed_time /= 1000 #轉為秒\n    event_duration = df.elapsed_time.diff().fillna(0).clip(0,3600).astype(\"float32\")#最大道3600秒也就是一小時\n    df['event_duration'] = event_duration.astype(\"float32\")\n    df.drop('elapsed_time', axis = 1, inplace =True)\n\n    tmp = []\n    tmp.append(df)\n    tmp_df = pad_sequences(tmp, padding='post', maxlen = 500,dtype='float16')\n\n    return tmp_df.reshape(1,500)\n","metadata":{"execution":{"iopub.status.busy":"2023-04-28T04:11:28.693245Z","iopub.execute_input":"2023-04-28T04:11:28.694405Z","iopub.status.idle":"2023-04-28T04:11:28.703860Z","shell.execute_reply.started":"2023-04-28T04:11:28.694359Z","shell.execute_reply":"2023-04-28T04:11:28.702599Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import jo_wilder\nenv = jo_wilder.make_env()\niter_test = env.iter_test()\n\nlimits = {'0-4':(1,4), '5-12':(4,14), '13-22':(14,19)}\nbest_threshold = 0.64\n\nfor (test, sample_submission) in iter_test: # test 每次只有一個level和session_id\n    df = test_engineer(test)\n    level = test.level_group.values[0]\n    a,b = limits[level]\n    \n    for Q in range(a,b):\n        model = load_model(f'/kaggle/input/conv1d-student-performance-on-game/{level}_{Q}/checkpoint')\n        pred_value = model.predict(df)\n        \n        mask = sample_submission.session_id.str.contains(f'q{Q}')\n        sample_submission.loc[mask,'correct'] = ( pred_value > best_threshold ).astype(\"int\")\n\n    env.predict(sample_submission)","metadata":{"execution":{"iopub.status.busy":"2023-04-28T04:11:28.728470Z","iopub.execute_input":"2023-04-28T04:11:28.729522Z","iopub.status.idle":"2023-04-28T04:12:02.082307Z","shell.execute_reply.started":"2023-04-28T04:11:28.729459Z","shell.execute_reply":"2023-04-28T04:12:02.081024Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"! head submission.csv","metadata":{"execution":{"iopub.status.busy":"2023-04-28T04:12:26.329983Z","iopub.execute_input":"2023-04-28T04:12:26.330660Z","iopub.status.idle":"2023-04-28T04:12:27.440470Z","shell.execute_reply.started":"2023-04-28T04:12:26.330617Z","shell.execute_reply":"2023-04-28T04:12:27.439046Z"},"trusted":true},"execution_count":null,"outputs":[]}]}