{"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 \nimport pandas as pd \nimport matplotlib.pyplot as plt\nimport seaborn as sns\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-03-13T19:17:07.955159Z","iopub.execute_input":"2023-03-13T19:17:07.955580Z","iopub.status.idle":"2023-03-13T19:17:07.966006Z","shell.execute_reply.started":"2023-03-13T19:17:07.955544Z","shell.execute_reply":"2023-03-13T19:17:07.964755Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 1. Read data and first look","metadata":{}},{"cell_type":"code","source":"train_label = pd.read_csv('/kaggle/input/predict-student-performance-from-game-play/train_labels.csv')","metadata":{"execution":{"iopub.status.busy":"2023-03-13T19:20:11.573504Z","iopub.execute_input":"2023-03-13T19:20:11.574023Z","iopub.status.idle":"2023-03-13T19:20:11.734291Z","shell.execute_reply.started":"2023-03-13T19:20:11.573978Z","shell.execute_reply":"2023-03-13T19:20:11.733133Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_label.shape","metadata":{"execution":{"iopub.status.busy":"2023-03-13T19:20:14.614728Z","iopub.execute_input":"2023-03-13T19:20:14.615172Z","iopub.status.idle":"2023-03-13T19:20:14.621687Z","shell.execute_reply.started":"2023-03-13T19:20:14.615132Z","shell.execute_reply":"2023-03-13T19:20:14.620626Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_label.head(5)","metadata":{"execution":{"iopub.status.busy":"2023-03-13T19:20:20.449974Z","iopub.execute_input":"2023-03-13T19:20:20.450385Z","iopub.status.idle":"2023-03-13T19:20:20.463165Z","shell.execute_reply.started":"2023-03-13T19:20:20.450349Z","shell.execute_reply":"2023-03-13T19:20:20.461921Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_label.info()","metadata":{"execution":{"iopub.status.busy":"2023-03-13T19:20:23.284674Z","iopub.execute_input":"2023-03-13T19:20:23.285110Z","iopub.status.idle":"2023-03-13T19:20:23.310444Z","shell.execute_reply.started":"2023-03-13T19:20:23.285071Z","shell.execute_reply":"2023-03-13T19:20:23.309583Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 2. Explore questions' difficulty","metadata":{}},{"cell_type":"code","source":"train_label['Session'] = train_label['session_id'].apply(lambda x: int(x.split('_')[0]))\ntrain_label['Question'] = train_label['session_id'].apply(lambda x: int(x.split('_')[1][1:]))","metadata":{"execution":{"iopub.status.busy":"2023-03-13T19:22:26.747928Z","iopub.execute_input":"2023-03-13T19:22:26.748832Z","iopub.status.idle":"2023-03-13T19:22:27.125917Z","shell.execute_reply.started":"2023-03-13T19:22:26.748784Z","shell.execute_reply":"2023-03-13T19:22:27.124917Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_label.head(5)","metadata":{"execution":{"iopub.status.busy":"2023-03-13T19:22:29.212899Z","iopub.execute_input":"2023-03-13T19:22:29.213313Z","iopub.status.idle":"2023-03-13T19:22:29.226196Z","shell.execute_reply.started":"2023-03-13T19:22:29.213278Z","shell.execute_reply":"2023-03-13T19:22:29.224878Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"student_number = train_label['session_id'].nunique()\nstudent_number","metadata":{"execution":{"iopub.status.busy":"2023-03-13T19:22:53.028971Z","iopub.execute_input":"2023-03-13T19:22:53.029408Z","iopub.status.idle":"2023-03-13T19:22:53.093114Z","shell.execute_reply.started":"2023-03-13T19:22:53.029359Z","shell.execute_reply":"2023-03-13T19:22:53.092154Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# group by question_id to calculate the accuracy rate\naccuracy_rate = pd.DataFrame(train_label.groupby('Question')['correct'].agg('sum') / student_number)\naccuracy_rate.columns = ['Correct']\naccuracy_rate = accuracy_rate.sort_values('Correct', ascending = True)\naccuracy_rate","metadata":{"execution":{"iopub.status.busy":"2023-03-13T19:22:55.921002Z","iopub.execute_input":"2023-03-13T19:22:55.921641Z","iopub.status.idle":"2023-03-13T19:22:55.941382Z","shell.execute_reply.started":"2023-03-13T19:22:55.921603Z","shell.execute_reply":"2023-03-13T19:22:55.940479Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.rcParams['figure.figsize']=(15,5)\nsns.barplot(x = accuracy_rate.index, \n            y = accuracy_rate['Correct'], \n            order = accuracy_rate.index,\n            data = accuracy_rate)\nplt.title('Question difficulty')","metadata":{"execution":{"iopub.status.busy":"2023-03-13T19:26:53.069114Z","iopub.execute_input":"2023-03-13T19:26:53.069514Z","iopub.status.idle":"2023-03-13T19:26:53.380734Z","shell.execute_reply.started":"2023-03-13T19:26:53.069480Z","shell.execute_reply":"2023-03-13T19:26:53.379843Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<font size = 3> **From the graph above, we can find that question 2's accuracy rate is the highest and question 13's accuracy rate is the lowest, which means question 2 is the easiest and question 13 is the hardest.** ","metadata":{}},{"cell_type":"markdown","source":"# 3. Group questions Analysis","metadata":{}},{"cell_type":"code","source":"def get_group(n):\n    if n <= 3:\n        group = '0-4'\n    elif  n <= 13:\n        group = '5-12'\n    elif  n <= 18:\n        group = '13-22'\n        \n    return group\n\ndef group_q_number(q):\n    if q <= 3:\n        return 3\n    elif q <= 13:\n        return 10\n    elif q <= 18:\n        return 5","metadata":{"execution":{"iopub.status.busy":"2023-03-13T19:27:23.836121Z","iopub.execute_input":"2023-03-13T19:27:23.837328Z","iopub.status.idle":"2023-03-13T19:27:23.843637Z","shell.execute_reply.started":"2023-03-13T19:27:23.837278Z","shell.execute_reply":"2023-03-13T19:27:23.842734Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_label['Group'] = train_label['Question'].apply(lambda x : get_group(x))\ntrain_label['Group_number'] = train_label['Question'].apply(lambda x: group_q_number(x))\n#train_label['Group_correct'] = train_label['correct'] / train_label['Group_number']","metadata":{"execution":{"iopub.status.busy":"2023-03-13T19:27:26.349927Z","iopub.execute_input":"2023-03-13T19:27:26.351064Z","iopub.status.idle":"2023-03-13T19:27:26.542056Z","shell.execute_reply.started":"2023-03-13T19:27:26.351009Z","shell.execute_reply":"2023-03-13T19:27:26.540846Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_label.head(5)","metadata":{"execution":{"iopub.status.busy":"2023-03-13T19:27:29.550751Z","iopub.execute_input":"2023-03-13T19:27:29.551180Z","iopub.status.idle":"2023-03-13T19:27:29.564807Z","shell.execute_reply.started":"2023-03-13T19:27:29.551143Z","shell.execute_reply":"2023-03-13T19:27:29.563592Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_label.groupby('Group').agg('correct').sum()","metadata":{"execution":{"iopub.status.busy":"2023-03-13T19:35:10.255184Z","iopub.execute_input":"2023-03-13T19:35:10.255606Z","iopub.status.idle":"2023-03-13T19:35:10.283486Z","shell.execute_reply.started":"2023-03-13T19:35:10.255570Z","shell.execute_reply":"2023-03-13T19:35:10.282347Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"accuracy_rate_by_group = pd.DataFrame(train_label.groupby('Group').agg('correct').sum() / train_label.groupby('Group').agg('correct').count())\naccuracy_rate_by_group.columns = ['Correction']\naccuracy_rate_by_group","metadata":{"execution":{"iopub.status.busy":"2023-03-13T19:36:49.370620Z","iopub.execute_input":"2023-03-13T19:36:49.371047Z","iopub.status.idle":"2023-03-13T19:36:49.418368Z","shell.execute_reply.started":"2023-03-13T19:36:49.371010Z","shell.execute_reply":"2023-03-13T19:36:49.417494Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.rcParams['figure.figsize']=(6,4)\nsns.barplot(x = accuracy_rate_by_group.index, \n            y = accuracy_rate_by_group['Correction'], \n            order = accuracy_rate_by_group.index,\n            data = accuracy_rate_by_group)\nplt.title('Questions\\' difficulty by group')","metadata":{"execution":{"iopub.status.busy":"2023-03-13T19:36:56.890591Z","iopub.execute_input":"2023-03-13T19:36:56.891976Z","iopub.status.idle":"2023-03-13T19:36:57.042317Z","shell.execute_reply.started":"2023-03-13T19:36:56.891919Z","shell.execute_reply":"2023-03-13T19:36:57.040250Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<font size=3> **From above graph, we can find group 0-4 has the highest accuracy rate which is nearly 88% and group 5-12 has the lowest accuracy rate which is nearly 65%.**","metadata":{}},{"cell_type":"markdown","source":"# Each student's performance in each question.","metadata":{}},{"cell_type":"code","source":"each_student_performance = train_label[['Session', 'Question', 'correct']]","metadata":{"execution":{"iopub.status.busy":"2023-03-13T20:02:45.775242Z","iopub.execute_input":"2023-03-13T20:02:45.775654Z","iopub.status.idle":"2023-03-13T20:02:45.783225Z","shell.execute_reply.started":"2023-03-13T20:02:45.775615Z","shell.execute_reply":"2023-03-13T20:02:45.781983Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"each_student = each_student_performance[each_student_performance['Question']==1]\neach_student = each_student[['Session','correct']]  \neach_student.columns = ['Session', f'q{1}']\neach_student.head(2)","metadata":{"execution":{"iopub.status.busy":"2023-03-13T20:02:47.830724Z","iopub.execute_input":"2023-03-13T20:02:47.831158Z","iopub.status.idle":"2023-03-13T20:02:47.848999Z","shell.execute_reply.started":"2023-03-13T20:02:47.831121Z","shell.execute_reply":"2023-03-13T20:02:47.848048Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for question in range(2,19):\n    each_students = each_student_performance[each_student_performance['Question'] == question]\n    each_students = each_students[['Session','correct']]  \n    each_students.columns = ['Session', f'q{question}']\n    each_student = pd.merge(each_student, each_students, how = 'left', on = 'Session') \n\neach_student.head(5)","metadata":{"execution":{"iopub.status.busy":"2023-03-13T20:02:50.433701Z","iopub.execute_input":"2023-03-13T20:02:50.434126Z","iopub.status.idle":"2023-03-13T20:02:50.579893Z","shell.execute_reply.started":"2023-03-13T20:02:50.434080Z","shell.execute_reply":"2023-03-13T20:02:50.579016Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"each_student.shape","metadata":{"execution":{"iopub.status.busy":"2023-03-13T20:03:10.370465Z","iopub.execute_input":"2023-03-13T20:03:10.370876Z","iopub.status.idle":"2023-03-13T20:03:10.377970Z","shell.execute_reply.started":"2023-03-13T20:03:10.370841Z","shell.execute_reply":"2023-03-13T20:03:10.376879Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"raw","source":"","metadata":{}}]}