{"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":"# Notebook Overview <a name=\"notebook_overview\"></a>","metadata":{}},{"cell_type":"markdown","source":"In this notebook, we explore how the timing of each group of levels affects the players' final score. We analyse the correlation between the average passing time of the levels and see how this affects the final score. The basic hypothesis is that the faster a player completes groups of levels, the higher their final score will be.","metadata":{}},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport seaborn as sns\nimport matplotlib.pyplot as plt\nimport scipy.stats as stats\nimport plotly.express as px","metadata":{"execution":{"iopub.status.busy":"2023-04-13T10:29:11.685982Z","iopub.execute_input":"2023-04-13T10:29:11.687382Z","iopub.status.idle":"2023-04-13T10:29:11.692559Z","shell.execute_reply.started":"2023-04-13T10:29:11.687333Z","shell.execute_reply":"2023-04-13T10:29:11.691699Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Imports <a name=\"imports\"></a>","metadata":{}},{"cell_type":"markdown","source":"## Loading Students Logs <a name=\"loading_students_logs\"></a>","metadata":{}},{"cell_type":"code","source":"use_columns = ['session_id', \n               'index', \n               'elapsed_time', \n               'level_group','event_name']\ndtypes={'session_id':'category', \n'elapsed_time':np.int32,\n    'event_name':'category',\n    'name':'category',\n    'level':np.uint8,\n    'page':'category',\n    'room_coor_x':np.float32,\n    'room_coor_y':np.float32,\n    'screen_coor_x':np.float32,\n    'screen_coor_y':np.float32,\n    'hover_duration':np.float32,\n     'text':'category',\n     'fqid':'category',\n     'room_fqid':'category',\n     'text_fqid':'category',\n     'fullscreen':'category',\n     'hq':'category',\n     'music':'category',\n     'level_group':'category'}\ndf = pd.read_csv('/kaggle/input/predict-student-performance-from-game-play/train.csv', \n                 dtype=dtypes, usecols=use_columns)","metadata":{"execution":{"iopub.status.busy":"2023-04-13T10:29:11.694698Z","iopub.execute_input":"2023-04-13T10:29:11.695337Z","iopub.status.idle":"2023-04-13T10:30:38.053903Z","shell.execute_reply.started":"2023-04-13T10:29:11.695297Z","shell.execute_reply":"2023-04-13T10:30:38.052605Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Loading Data <a name=\"loading_data\"></a>","metadata":{}},{"cell_type":"markdown","source":"## Loading Students Answers <a name=\"loading_students_answers\"></a>","metadata":{}},{"cell_type":"code","source":"labels = pd.read_csv('/kaggle/input/predict-student-performance-from-game-play/train_labels.csv')\n\nlabels[['session_id', 'question']] = labels['session_id'].str.split('_', expand=True)\n\n# Needed for proper sorting\nlabels['question'] = labels['question'].str.slice(1)\nlabels['question'] = labels['question'].astype(str)\n\nlabels.head()","metadata":{"execution":{"iopub.status.busy":"2023-04-13T10:30:38.055247Z","iopub.execute_input":"2023-04-13T10:30:38.056151Z","iopub.status.idle":"2023-04-13T10:30:39.458719Z","shell.execute_reply.started":"2023-04-13T10:30:38.056109Z","shell.execute_reply":"2023-04-13T10:30:39.457868Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Evaluating Students Score <a name=\"evaluating_students_score\"></a>","metadata":{}},{"cell_type":"code","source":"pivoted_questions = labels.pivot(columns='question', values='correct', index='session_id')\nstudents_score = pivoted_questions.iloc[:, 0:18].sum(axis=1)\nstudents_score = students_score.rename('student_score')\nstudents_score.head()","metadata":{"execution":{"iopub.status.busy":"2023-04-13T10:30:39.460275Z","iopub.execute_input":"2023-04-13T10:30:39.460903Z","iopub.status.idle":"2023-04-13T10:30:39.722284Z","shell.execute_reply.started":"2023-04-13T10:30:39.460867Z","shell.execute_reply":"2023-04-13T10:30:39.721433Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Data Extraction <a name=\"data_extraction\"></a>","metadata":{}},{"cell_type":"code","source":"q_inf = df[[\"session_id\", \"elapsed_time\", 'level_group', 'event_name' ]].copy()\nq_inf.head()","metadata":{"execution":{"iopub.status.busy":"2023-04-13T10:30:39.725100Z","iopub.execute_input":"2023-04-13T10:30:39.725801Z","iopub.status.idle":"2023-04-13T10:30:39.945027Z","shell.execute_reply.started":"2023-04-13T10:30:39.725763Z","shell.execute_reply":"2023-04-13T10:30:39.944170Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Find how much time each user spends on each group of levels ","metadata":{}},{"cell_type":"code","source":"a = q_inf.groupby(['level_group','session_id'])['elapsed_time'].max()-q_inf.groupby(['level_group','session_id'])['elapsed_time'].min()\na.reset_index()","metadata":{"execution":{"iopub.status.busy":"2023-04-13T10:30:39.946607Z","iopub.execute_input":"2023-04-13T10:30:39.947270Z","iopub.status.idle":"2023-04-13T10:30:41.861595Z","shell.execute_reply.started":"2023-04-13T10:30:39.947234Z","shell.execute_reply":"2023-04-13T10:30:41.860436Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Split into three separate groups and look at each","metadata":{}},{"cell_type":"code","source":"a.groupby(['level_group']).mean()","metadata":{"execution":{"iopub.status.busy":"2023-04-13T10:30:41.863225Z","iopub.execute_input":"2023-04-13T10:30:41.863622Z","iopub.status.idle":"2023-04-13T10:30:41.874600Z","shell.execute_reply.started":"2023-04-13T10:30:41.863533Z","shell.execute_reply":"2023-04-13T10:30:41.873551Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"a_1 = a.reset_index()[a.reset_index()['level_group'] == '0-4']\na_1","metadata":{"execution":{"iopub.status.busy":"2023-04-13T10:30:41.875810Z","iopub.execute_input":"2023-04-13T10:30:41.876621Z","iopub.status.idle":"2023-04-13T10:30:41.898032Z","shell.execute_reply.started":"2023-04-13T10:30:41.876585Z","shell.execute_reply":"2023-04-13T10:30:41.896924Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"a_1['elapsed_time']=np.log(a_1['elapsed_time']+2)\nmean_value = a_1['elapsed_time'].mean()","metadata":{"execution":{"iopub.status.busy":"2023-04-13T10:31:42.623259Z","iopub.execute_input":"2023-04-13T10:31:42.624081Z","iopub.status.idle":"2023-04-13T10:31:42.630456Z","shell.execute_reply.started":"2023-04-13T10:31:42.624037Z","shell.execute_reply":"2023-04-13T10:31:42.629571Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.axvline(x = mean_value, color = 'r', linestyle = '--')\nsns.histplot(data = a_1, x = 'elapsed_time',kde = True)","metadata":{"execution":{"iopub.status.busy":"2023-04-13T10:31:47.820718Z","iopub.execute_input":"2023-04-13T10:31:47.821137Z","iopub.status.idle":"2023-04-13T10:31:48.825340Z","shell.execute_reply.started":"2023-04-13T10:31:47.821098Z","shell.execute_reply":"2023-04-13T10:31:48.822150Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"a_2 = a.reset_index()[a.reset_index()['level_group'] == '5-12']\na_2","metadata":{"execution":{"iopub.status.busy":"2023-04-13T10:30:42.847310Z","iopub.execute_input":"2023-04-13T10:30:42.847632Z","iopub.status.idle":"2023-04-13T10:30:42.869291Z","shell.execute_reply.started":"2023-04-13T10:30:42.847599Z","shell.execute_reply":"2023-04-13T10:30:42.868004Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"a_2['elapsed_time']=np.log(a_2['elapsed_time']+2)\nmean_value = a_2['elapsed_time'].mean()","metadata":{"execution":{"iopub.status.busy":"2023-04-13T10:30:42.870755Z","iopub.execute_input":"2023-04-13T10:30:42.871123Z","iopub.status.idle":"2023-04-13T10:30:42.878800Z","shell.execute_reply.started":"2023-04-13T10:30:42.871085Z","shell.execute_reply":"2023-04-13T10:30:42.877544Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.axvline(x = mean_value, color = 'r', linestyle = '--')\nsns.histplot(data = a_2, x = 'elapsed_time',kde = True)","metadata":{"execution":{"iopub.status.busy":"2023-04-13T10:30:42.880467Z","iopub.execute_input":"2023-04-13T10:30:42.881063Z","iopub.status.idle":"2023-04-13T10:30:43.832253Z","shell.execute_reply.started":"2023-04-13T10:30:42.880992Z","shell.execute_reply":"2023-04-13T10:30:43.830876Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"a_3 = a.reset_index()[a.reset_index()['level_group'] == '13-22']\na_3","metadata":{"execution":{"iopub.status.busy":"2023-04-13T10:30:43.837212Z","iopub.execute_input":"2023-04-13T10:30:43.837812Z","iopub.status.idle":"2023-04-13T10:30:43.865376Z","shell.execute_reply.started":"2023-04-13T10:30:43.837753Z","shell.execute_reply":"2023-04-13T10:30:43.864346Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"a_3['elapsed_time']=np.log(a_3['elapsed_time']+2)\nmean_value = a_3['elapsed_time'].mean()","metadata":{"execution":{"iopub.status.busy":"2023-04-13T10:30:43.866682Z","iopub.execute_input":"2023-04-13T10:30:43.867255Z","iopub.status.idle":"2023-04-13T10:30:43.873413Z","shell.execute_reply.started":"2023-04-13T10:30:43.867220Z","shell.execute_reply":"2023-04-13T10:30:43.872445Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.axvline(x = mean_value, color = 'r', linestyle = '--')\nsns.histplot(data = a_3, x = 'elapsed_time',kde = True)","metadata":{"execution":{"iopub.status.busy":"2023-04-13T10:30:43.874705Z","iopub.execute_input":"2023-04-13T10:30:43.875268Z","iopub.status.idle":"2023-04-13T10:30:44.808734Z","shell.execute_reply.started":"2023-04-13T10:30:43.875233Z","shell.execute_reply":"2023-04-13T10:30:44.806291Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Dependence of the final score on time","metadata":{}},{"cell_type":"code","source":"labels.groupby(['session_id']).sum()\nscore = labels.groupby(['session_id']).sum()","metadata":{"execution":{"iopub.status.busy":"2023-04-13T10:30:44.810329Z","iopub.execute_input":"2023-04-13T10:30:44.810871Z","iopub.status.idle":"2023-04-13T10:30:45.102721Z","shell.execute_reply.started":"2023-04-13T10:30:44.810830Z","shell.execute_reply":"2023-04-13T10:30:45.101349Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"a_2_join = pd.merge(a_2,score,on = 'session_id')\na_2_join","metadata":{"execution":{"iopub.status.busy":"2023-04-13T10:30:45.104290Z","iopub.execute_input":"2023-04-13T10:30:45.104613Z","iopub.status.idle":"2023-04-13T10:30:45.139798Z","shell.execute_reply.started":"2023-04-13T10:30:45.104583Z","shell.execute_reply":"2023-04-13T10:30:45.138945Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"a_1_join = pd.merge(a_1,score,on = 'session_id')\na_1_join","metadata":{"execution":{"iopub.status.busy":"2023-04-13T10:30:45.141214Z","iopub.execute_input":"2023-04-13T10:30:45.141749Z","iopub.status.idle":"2023-04-13T10:30:45.176334Z","shell.execute_reply.started":"2023-04-13T10:30:45.141714Z","shell.execute_reply":"2023-04-13T10:30:45.175428Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"a_3_join = pd.merge(a_3,score,on = 'session_id')\na_3_join","metadata":{"execution":{"iopub.status.busy":"2023-04-13T10:30:45.177377Z","iopub.execute_input":"2023-04-13T10:30:45.178379Z","iopub.status.idle":"2023-04-13T10:30:45.212627Z","shell.execute_reply.started":"2023-04-13T10:30:45.178343Z","shell.execute_reply":"2023-04-13T10:30:45.211446Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mean_time_score3 = a_3_join.groupby(['correct']).mean()\nmean_time_score3","metadata":{"execution":{"iopub.status.busy":"2023-04-13T10:30:45.213995Z","iopub.execute_input":"2023-04-13T10:30:45.214415Z","iopub.status.idle":"2023-04-13T10:30:45.228916Z","shell.execute_reply.started":"2023-04-13T10:30:45.214381Z","shell.execute_reply":"2023-04-13T10:30:45.227639Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 13-22","metadata":{}},{"cell_type":"code","source":"sns.lineplot (x = mean_time_score3.index, y = mean_time_score3.elapsed_time)","metadata":{"execution":{"iopub.status.busy":"2023-04-13T10:30:45.230544Z","iopub.execute_input":"2023-04-13T10:30:45.231197Z","iopub.status.idle":"2023-04-13T10:30:45.431499Z","shell.execute_reply.started":"2023-04-13T10:30:45.231156Z","shell.execute_reply":"2023-04-13T10:30:45.430473Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mean_time_score2 = a_2_join.groupby(['correct']).mean()\nmean_time_score2","metadata":{"execution":{"iopub.status.busy":"2023-04-13T10:30:45.432872Z","iopub.execute_input":"2023-04-13T10:30:45.433205Z","iopub.status.idle":"2023-04-13T10:30:45.448956Z","shell.execute_reply.started":"2023-04-13T10:30:45.433173Z","shell.execute_reply":"2023-04-13T10:30:45.448045Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 5-12","metadata":{}},{"cell_type":"code","source":"sns.lineplot (x = mean_time_score2.index, y = mean_time_score2.elapsed_time)","metadata":{"execution":{"iopub.status.busy":"2023-04-13T10:30:45.450294Z","iopub.execute_input":"2023-04-13T10:30:45.450822Z","iopub.status.idle":"2023-04-13T10:30:45.646775Z","shell.execute_reply.started":"2023-04-13T10:30:45.450787Z","shell.execute_reply":"2023-04-13T10:30:45.644085Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mean_time_score1 = a_1_join.groupby(['correct']).mean()\nmean_time_score1","metadata":{"execution":{"iopub.status.busy":"2023-04-13T10:30:45.647996Z","iopub.execute_input":"2023-04-13T10:30:45.648949Z","iopub.status.idle":"2023-04-13T10:30:45.663691Z","shell.execute_reply.started":"2023-04-13T10:30:45.648909Z","shell.execute_reply":"2023-04-13T10:30:45.662585Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 0-4","metadata":{}},{"cell_type":"code","source":"sns.lineplot (x = mean_time_score1.index, y = mean_time_score1.elapsed_time)","metadata":{"execution":{"iopub.status.busy":"2023-04-13T10:30:45.664739Z","iopub.execute_input":"2023-04-13T10:30:45.665725Z","iopub.status.idle":"2023-04-13T10:30:45.861073Z","shell.execute_reply.started":"2023-04-13T10:30:45.665690Z","shell.execute_reply":"2023-04-13T10:30:45.858085Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Summing up","metadata":{}},{"cell_type":"markdown","source":"Based on the research, it became clear that our hypothesis was confirmed. Indeed, the less a player spends on a group of levels, the higher his total score\nThank you for reading my EDA. If you have any questions, suggestions or ideas, please leave them in the comments, they will be very useful.","metadata":{}}]}