{"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 investigate how the version of the game played affects their bottom line. We analyse the relationship between the version of the game and the final score. The main hypothesis is that we will see how players who play one version answer the questions better than others","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_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               ,'event_name','text']\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-16T07:49:09.193295Z","iopub.execute_input":"2023-04-16T07:49:09.193659Z","iopub.status.idle":"2023-04-16T07:50:45.550038Z","shell.execute_reply.started":"2023-04-16T07:49:09.193593Z","shell.execute_reply":"2023-04-16T07:50:45.548814Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Loading Data <a name=\"loading_data\"></a>","metadata":{}},{"cell_type":"markdown","source":"## Classification of versions <a name=\"Classification of versions\"></a>","metadata":{}},{"cell_type":"markdown","source":"We will find out which version the players played using the data below. Let's group the players by the dialogues we only hear in certain versions of the game \nThis laptop was used in work: https://www.kaggle.com/code/steubk/meetings-are-boring-the-notebook/notebook. Thank you to the author for a job well done!\n<img src=\"https://i.ibb.co/7n4jjyV/image.png\">","metadata":{}},{"cell_type":"markdown","source":"Divide the players and look at the number of players in parallel to make it all add up","metadata":{}},{"cell_type":"code","source":"Criterion_1 = df.loc[df['text'] == 'Meetings are BORING!']\nCriterion_1.session_id.nunique()","metadata":{"execution":{"iopub.status.busy":"2023-04-16T07:50:45.606341Z","iopub.execute_input":"2023-04-16T07:50:45.607318Z","iopub.status.idle":"2023-04-16T07:50:45.696204Z","shell.execute_reply.started":"2023-04-16T07:50:45.607262Z","shell.execute_reply":"2023-04-16T07:50:45.695162Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Criterion_2= df.loc[df['text'] == 'Ugh. Meetings are so boring.']\nCriterion_2.session_id.nunique()","metadata":{"execution":{"iopub.status.busy":"2023-04-16T07:50:45.697899Z","iopub.execute_input":"2023-04-16T07:50:45.698607Z","iopub.status.idle":"2023-04-16T07:50:45.726756Z","shell.execute_reply.started":"2023-04-16T07:50:45.698567Z","shell.execute_reply":"2023-04-16T07:50:45.725772Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Criterion_3 = df.loc[df['text'] == 'Can I come, Gramps?']\nCriterion_3.session_id.nunique()","metadata":{"execution":{"iopub.status.busy":"2023-04-16T07:50:45.728450Z","iopub.execute_input":"2023-04-16T07:50:45.729151Z","iopub.status.idle":"2023-04-16T07:50:45.756937Z","shell.execute_reply.started":"2023-04-16T07:50:45.729112Z","shell.execute_reply":"2023-04-16T07:50:45.755813Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Remaining = df[~((df['session_id'].isin(Criterion_1['session_id'])) | \n                 (df['session_id'].isin(Criterion_2['session_id'])) | \n                 (df['session_id'].isin(Criterion_3['session_id'])))]\nRemaining.session_id.nunique()","metadata":{"execution":{"iopub.status.busy":"2023-04-16T07:57:31.450986Z","iopub.execute_input":"2023-04-16T07:57:31.451423Z","iopub.status.idle":"2023-04-16T07:57:32.216804Z","shell.execute_reply.started":"2023-04-16T07:57:31.451388Z","shell.execute_reply":"2023-04-16T07:57:32.215768Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"At the end of the count it turned out that there were 9 users who did not have an initial dialogue. We let them go","metadata":{}},{"cell_type":"code","source":"Criterion_3_1 = df.loc[df['text'] == \"Yes! This old slip from 1916.\"]\nCriterion_3_1.session_id.nunique()","metadata":{"execution":{"iopub.status.busy":"2023-04-16T08:15:02.235417Z","iopub.execute_input":"2023-04-16T08:15:02.235858Z","iopub.status.idle":"2023-04-16T08:15:02.264378Z","shell.execute_reply.started":"2023-04-16T08:15:02.235821Z","shell.execute_reply":"2023-04-16T08:15:02.262944Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Criterion_3_2 = df.loc[df['text'] == \"Yes! This cool old slip from 1916.\"]\nCriterion_3_2.session_id.nunique()","metadata":{"execution":{"iopub.status.busy":"2023-04-16T08:15:49.413627Z","iopub.execute_input":"2023-04-16T08:15:49.414784Z","iopub.status.idle":"2023-04-16T08:15:49.442590Z","shell.execute_reply.started":"2023-04-16T08:15:49.414734Z","shell.execute_reply":"2023-04-16T08:15:49.441444Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"group_1 = Criterion_1\ngroup_2 = Criterion_2\ngroup_3 = Criterion_3[Criterion_3.session_id.isin(Criterion_3_1.session_id)]\ngroup_4 = Criterion_3[Criterion_3.session_id.isin(Criterion_3_2.session_id)]","metadata":{"execution":{"iopub.status.busy":"2023-04-16T08:19:54.906910Z","iopub.execute_input":"2023-04-16T08:19:54.907289Z","iopub.status.idle":"2023-04-16T08:19:54.923648Z","shell.execute_reply.started":"2023-04-16T08:19:54.907257Z","shell.execute_reply":"2023-04-16T08:19:54.922601Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"group_1.session_id.nunique()","metadata":{"execution":{"iopub.status.busy":"2023-04-16T08:20:26.074399Z","iopub.execute_input":"2023-04-16T08:20:26.074845Z","iopub.status.idle":"2023-04-16T08:20:26.081992Z","shell.execute_reply.started":"2023-04-16T08:20:26.074807Z","shell.execute_reply":"2023-04-16T08:20:26.080971Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"group_2.session_id.nunique()","metadata":{"execution":{"iopub.status.busy":"2023-04-16T08:20:53.289974Z","iopub.execute_input":"2023-04-16T08:20:53.290394Z","iopub.status.idle":"2023-04-16T08:20:53.299314Z","shell.execute_reply.started":"2023-04-16T08:20:53.290359Z","shell.execute_reply":"2023-04-16T08:20:53.298024Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"group_3.session_id.nunique()","metadata":{"execution":{"iopub.status.busy":"2023-04-16T08:20:55.640844Z","iopub.execute_input":"2023-04-16T08:20:55.641233Z","iopub.status.idle":"2023-04-16T08:20:55.648451Z","shell.execute_reply.started":"2023-04-16T08:20:55.641199Z","shell.execute_reply":"2023-04-16T08:20:55.647544Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"group_4.session_id.nunique()","metadata":{"execution":{"iopub.status.busy":"2023-04-16T08:20:58.385859Z","iopub.execute_input":"2023-04-16T08:20:58.386277Z","iopub.status.idle":"2023-04-16T08:20:58.393586Z","shell.execute_reply.started":"2023-04-16T08:20:58.386240Z","shell.execute_reply":"2023-04-16T08:20:58.392234Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"group_1.reset_index(drop = True)","metadata":{"execution":{"iopub.status.busy":"2023-04-16T08:36:30.244829Z","iopub.execute_input":"2023-04-16T08:36:30.245628Z","iopub.status.idle":"2023-04-16T08:36:30.264519Z","shell.execute_reply.started":"2023-04-16T08:36:30.245583Z","shell.execute_reply":"2023-04-16T08:36:30.263462Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"group_2.reset_index(drop = True)","metadata":{"execution":{"iopub.status.busy":"2023-04-16T08:36:57.732095Z","iopub.execute_input":"2023-04-16T08:36:57.732523Z","iopub.status.idle":"2023-04-16T08:36:57.752122Z","shell.execute_reply.started":"2023-04-16T08:36:57.732475Z","shell.execute_reply":"2023-04-16T08:36:57.751044Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"group_3.reset_index(drop = True)","metadata":{"execution":{"iopub.status.busy":"2023-04-16T08:37:00.358670Z","iopub.execute_input":"2023-04-16T08:37:00.359715Z","iopub.status.idle":"2023-04-16T08:37:00.375472Z","shell.execute_reply.started":"2023-04-16T08:37:00.359657Z","shell.execute_reply":"2023-04-16T08:37:00.374589Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"group_4.reset_index(drop = True)","metadata":{"execution":{"iopub.status.busy":"2023-04-16T08:37:04.662204Z","iopub.execute_input":"2023-04-16T08:37:04.663009Z","iopub.status.idle":"2023-04-16T08:37:04.681407Z","shell.execute_reply.started":"2023-04-16T08:37:04.662962Z","shell.execute_reply":"2023-04-16T08:37:04.680426Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sessions = [group_1.session_id.unique(), group_2.session_id.unique(), group_3.session_id.unique(), group_4.session_id.unique()]\n\ndef get_version(session_id):\n    if session_id in sessions[0]:\n        return 'normal'\n    elif session_id in sessions[1]:\n        return 'nohumor'\n    elif session_id in sessions[2]:\n        return 'dry'\n    elif session_id in sessions[3]:\n        return 'nosnark'\n    else:\n        return np.NaN       ","metadata":{"execution":{"iopub.status.busy":"2023-04-16T09:00:21.528413Z","iopub.execute_input":"2023-04-16T09:00:21.529268Z","iopub.status.idle":"2023-04-16T09:00:21.537673Z","shell.execute_reply.started":"2023-04-16T09:00:21.529219Z","shell.execute_reply":"2023-04-16T09:00:21.536460Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"versions = pd.DataFrame(index=df['session_id'].unique())\nversions.index.name = 'session_id'\nversions = versions.reset_index()\nversions['version'] = versions['session_id'].apply(lambda session_id: get_version(session_id))\nversions.head()","metadata":{"execution":{"iopub.status.busy":"2023-04-16T09:00:21.744435Z","iopub.execute_input":"2023-04-16T09:00:21.744873Z","iopub.status.idle":"2023-04-16T09:00:22.474009Z","shell.execute_reply.started":"2023-04-16T09:00:21.744835Z","shell.execute_reply":"2023-04-16T09:00:22.472959Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"versions['version'].value_counts(dropna=False)","metadata":{"execution":{"iopub.status.busy":"2023-04-16T09:01:00.265424Z","iopub.execute_input":"2023-04-16T09:01:00.265900Z","iopub.status.idle":"2023-04-16T09:01:00.277883Z","shell.execute_reply.started":"2023-04-16T09:01:00.265863Z","shell.execute_reply":"2023-04-16T09:01:00.276774Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Сomparison of the final score and the version of the game <a name=\"Сomparison of the final score and the version of the game\"></a>\n","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-16T09:02:08.364104Z","iopub.execute_input":"2023-04-16T09:02:08.364530Z","iopub.status.idle":"2023-04-16T09:02:10.470237Z","shell.execute_reply.started":"2023-04-16T09:02:08.364494Z","shell.execute_reply":"2023-04-16T09:02:10.469133Z"},"trusted":true},"execution_count":null,"outputs":[]},{"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-16T09:02:14.149671Z","iopub.execute_input":"2023-04-16T09:02:14.150473Z","iopub.status.idle":"2023-04-16T09:02:14.402316Z","shell.execute_reply.started":"2023-04-16T09:02:14.150433Z","shell.execute_reply":"2023-04-16T09:02:14.401253Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"versions = versions.set_index('session_id')","metadata":{"execution":{"iopub.status.busy":"2023-04-16T09:04:24.322922Z","iopub.execute_input":"2023-04-16T09:04:24.323342Z","iopub.status.idle":"2023-04-16T09:04:24.329830Z","shell.execute_reply.started":"2023-04-16T09:04:24.323302Z","shell.execute_reply":"2023-04-16T09:04:24.328731Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"versions['score'] = students_score\nversions","metadata":{"execution":{"iopub.status.busy":"2023-04-16T09:04:43.591105Z","iopub.execute_input":"2023-04-16T09:04:43.591512Z","iopub.status.idle":"2023-04-16T09:04:43.721197Z","shell.execute_reply.started":"2023-04-16T09:04:43.591477Z","shell.execute_reply":"2023-04-16T09:04:43.720122Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"versions.groupby('version')['score'].describe()","metadata":{"execution":{"iopub.status.busy":"2023-04-16T09:05:04.635321Z","iopub.execute_input":"2023-04-16T09:05:04.635771Z","iopub.status.idle":"2023-04-16T09:05:04.681734Z","shell.execute_reply.started":"2023-04-16T09:05:04.635734Z","shell.execute_reply":"2023-04-16T09:05:04.680682Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"versions","metadata":{"execution":{"iopub.status.busy":"2023-04-16T09:05:40.747136Z","iopub.execute_input":"2023-04-16T09:05:40.747587Z","iopub.status.idle":"2023-04-16T09:05:40.764846Z","shell.execute_reply.started":"2023-04-16T09:05:40.747547Z","shell.execute_reply":"2023-04-16T09:05:40.763676Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Renormalise the data ","metadata":{}},{"cell_type":"code","source":"sns.histplot(x = versions.score, binwidth = 1, hue = versions.version, stat='probability')","metadata":{"execution":{"iopub.status.busy":"2023-04-16T09:10:18.685888Z","iopub.execute_input":"2023-04-16T09:10:18.686295Z","iopub.status.idle":"2023-04-16T09:10:19.238363Z","shell.execute_reply.started":"2023-04-16T09:10:18.686258Z","shell.execute_reply":"2023-04-16T09:10:19.237408Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"From the graph, we can conclude that there is no global difference. However, players who played the 'normal' version of the game have a slightly better final score, but they also have more average results","metadata":{}},{"cell_type":"markdown","source":"# Summing up","metadata":{}},{"cell_type":"markdown","source":"It was clear from the results that there was no global difference in the results, i.e. the hypothesis was wrong. However, some interesting details did emerge.\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":{}}]}