{"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":"# Game Room Click EDA\n\nThank you to @cdoette for giving us [this great notebook](https://www.kaggle.com/code/cdeotte/game-room-click-eda) that displays the clicks distribution in each of the 19 rooms.\nHe says in [the discussion](https://www.kaggle.com/competitions/predict-student-performance-from-game-play/discussion/387864) that these are of great interest....\n\n\nbut they're only of interest if the help predict correct answers right? I've taken the liberty to re-plot these figures splitting out correct vs incorrect sessions for each room.\nWhat do we learn? Please share in the comments","metadata":{}},{"cell_type":"code","source":"import pandas as pd, numpy as np\nimport matplotlib.pyplot as plt\nfrom PIL import Image\n\ntrain = pd.read_csv('/kaggle/input/predict-student-performance-from-game-play/train.csv')\ntrain = train[[\"session_id\",\"event_name\",\"room_coor_x\",\"room_coor_y\",\"fqid\",\"room_fqid\",\"level_group\"]]\nprint('Train data shape:', train.shape )\ntrain.head()","metadata":{"execution":{"iopub.status.busy":"2023-02-17T03:13:16.779275Z","iopub.execute_input":"2023-02-17T03:13:16.779740Z","iopub.status.idle":"2023-02-17T03:14:21.416894Z","shell.execute_reply.started":"2023-02-17T03:13:16.779631Z","shell.execute_reply":"2023-02-17T03:14:21.415634Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# load the labels\nlabels = pd.read_csv('/kaggle/input/predict-student-performance-from-game-play/train_labels.csv')\nprint('Train labels shape:', labels.shape )\nlabels['session'] = labels['session_id'].str[:17].astype(int)\nlabels['question'] = labels['session_id'].str[19:].astype(int)\n\n# calculate group the questions belong to\nlevel_groups = train.level_group.unique()\nlast_question = max(labels[\"question\"])\ncheckpoints = ([int(x.split(\"-\")[0]) for x in level_groups])\ncheckpoints = np.append(np.array(checkpoints), last_question)\ntimes_to_repeat = checkpoints[1:] - checkpoints[ : -1]\ngroupings = np.repeat(level_groups, times_to_repeat)\nlabels[\"level_group\"] = groupings[labels[\"question\"] -1]\n\nlabels = labels[[\"correct\",\"session\",\"question\",\"level_group\"]]\n\nlabels.head()","metadata":{"execution":{"iopub.status.busy":"2023-02-17T03:14:21.418766Z","iopub.execute_input":"2023-02-17T03:14:21.419084Z","iopub.status.idle":"2023-02-17T03:14:22.765746Z","shell.execute_reply.started":"2023-02-17T03:14:21.419056Z","shell.execute_reply":"2023-02-17T03:14:22.764782Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"## DICTIONARY TO IMAGE PATHS\n#dd = {}\n#PATH = '/kaggle/input/kaggle-game-images/'\n#dd['tunic.historicalsociety.closet'] = Image.open(PATH+'closet.png')\n#dd['tunic.historicalsociety.basement'] = Image.open(PATH+'basement.png')\n#dd['tunic.historicalsociety.entry'] = Image.open(PATH+'entry.png')\n#dd['tunic.historicalsociety.collection'] = Image.open(PATH+'collection.png')\n#dd['tunic.historicalsociety.stacks'] = Image.open(PATH+'stacks.png')\n#dd['tunic.kohlcenter.halloffame'] = Image.open(PATH+'halloffame.png')\n#dd['tunic.capitol_0.hall'] = Image.open(PATH+'capitol_hall.png')\n#dd['tunic.historicalsociety.closet_dirty'] = Image.open(PATH+'dirty_closet.png')\n#dd['tunic.historicalsociety.frontdesk'] = Image.open(PATH+'frontdesk.png')\n#dd['tunic.humanecology.frontdesk'] = Image.open(PATH+'humanecology.png')\n#dd['tunic.drycleaner.frontdesk'] = Image.open(PATH+'drycleaner.png')\n#dd['tunic.library.frontdesk'] = Image.open(PATH+'library.png')\n#dd['tunic.library.microfiche'] = Image.open(PATH+'microfiche.png')\n#dd['tunic.capitol_1.hall'] = Image.open(PATH+'capitol_hall.png')\n#dd['tunic.historicalsociety.cage'] = Image.open(PATH+'cage.png')\n#dd['tunic.historicalsociety.collection_flag'] = Image.open(PATH+'collection_flag.png')\n#dd['tunic.wildlife.center'] = Image.open(PATH+'wildlife.png')\n#dd['tunic.flaghouse.entry'] = Image.open(PATH+'flaghouse.png')\n#dd['tunic.capitol_2.hall'] = Image.open(PATH+'capitol_hall.png')","metadata":{"execution":{"iopub.status.busy":"2023-02-17T03:14:22.767213Z","iopub.execute_input":"2023-02-17T03:14:22.767902Z","iopub.status.idle":"2023-02-17T03:14:22.774635Z","shell.execute_reply.started":"2023-02-17T03:14:22.767866Z","shell.execute_reply":"2023-02-17T03:14:22.773770Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ROOMS = train[[\"room_fqid\",\"level_group\"]].drop_duplicates()\n\nfor j, room in ROOMS.iterrows():\n    rm = room[\"room_fqid\"]\n    \n    for q in np.argwhere(groupings == room[\"level_group\"]):\n        question = q[0]+1\n        print('\\n')\n        print('#'*25)\n        print(f'###', rm, f'   QUESTION #{question}')\n        print('#'*25)\n        correct_sessions = labels[(labels[\"question\"] == (question)) &\n                                  (labels[\"correct\"] == 1)][\"session\"]\n        fig, axs = plt.subplots(3,2, figsize = (30,30))\n\n#        # DISPLAY IMAGE\n#        if rm in dd:\n#            plt.figure(figsize=(17,17))\n#            plt.imshow(dd[rm])\n#            plt.axis('off')\n#            plt.show()\n    \n        # DISPLAY NAVIGATION CLICKS - Correct\n        df = train.loc[(train.event_name=='navigate_click')\n                       &(train.room_fqid==rm)&(train.fqid.isna())\n                       &(train.session_id.isin(correct_sessions))]\n        x_min,y_min = df[['room_coor_x','room_coor_y']].min().values\n        x_max,y_max = df[['room_coor_x','room_coor_y']].max().values\n        axs[0, 0].scatter(df.room_coor_x,df.room_coor_y,s=0.1, c= \"blue\")\n        axs[0, 0].set_xlim([x_min, x_max])\n        axs[0, 0].set_ylim([y_min, y_max])\n        axs[0, 0].set_title(f'question {question} - NAVIGATION CLICKS - {rm} - Correct')\n    \n        # DISPLAY NAVIGATION CLICKS - Incorrect\n        df = train.loc[(train.event_name=='navigate_click')\n                       &(train.room_fqid==rm)&(train.fqid.isna())\n                       &  ~(train.session_id.isin(correct_sessions))]\n        x_min,y_min = df[['room_coor_x','room_coor_y']].min().values\n        x_max,y_max = df[['room_coor_x','room_coor_y']].max().values\n        axs[0, 1].scatter(df.room_coor_x,df.room_coor_y,s=0.1, c= \"red\")\n        axs[0, 1].set_xlim([x_min, x_max])\n        axs[0, 1].set_ylim([y_min, y_max])\n        axs[0, 1].set_title(f'question {question} - NAVIGATION CLICKS - {rm} - Incorrect')\n    \n        # DISPLAY ITEMS OF INTEREST - Correct\n        df = train.loc[(train.event_name=='navigate_click')\n                       &(train.room_fqid==rm)&(train.fqid.notna())\n                       &(train.session_id.isin(correct_sessions))]\n        ITEMS = df.fqid.unique()\n        axs[1, 0].scatter(df.room_coor_x,df.room_coor_y,s=0.1, c= \"blue\")\n        for i in ITEMS:\n            mns = df.loc[df.fqid==i,['room_coor_x','room_coor_y']].mean().values\n            axs[1, 0].text(mns[0],mns[1],i)\n        axs[1, 0].set_xlim([x_min, x_max])\n        axs[1, 0].set_ylim([y_min, y_max])\n        axs[1, 0].set_title(f'question {question} - ITEMS OF INTEREST - {rm} - Correct')\n    \n        # DISPLAY ITEMS OF INTEREST - Incorrect\n        df = train.loc[(train.event_name=='navigate_click')\n                       &(train.room_fqid==rm)&(train.fqid.notna())\n                       & ~(train.session_id.isin(correct_sessions))]\n        ITEMS = df.fqid.unique()\n        axs[1, 1].scatter(df.room_coor_x,df.room_coor_y,s=0.1, c= \"red\")\n        for i in ITEMS:\n            mns = df.loc[df.fqid==i,['room_coor_x','room_coor_y']].mean().values\n            axs[1, 1].text(mns[0],mns[1],i)\n        axs[1, 1].set_xlim([x_min, x_max])\n        axs[1, 1].set_ylim([y_min, y_max])\n        axs[1, 1].set_title(f'question {question} - ITEMS OF INTEREST - {rm} - Incorrect')\n    \n        # DISPLAY PERSON CLICKS - Correct\n        df = train.loc[(train.event_name=='person_click')\n                       &(train.room_fqid==rm)&(train.fqid.notna())\n                       &(train.session_id.isin(correct_sessions))]\n        if len(df)!=0:\n            ITEMS = df.fqid.unique()\n            axs[2, 0].scatter(df.room_coor_x,df.room_coor_y,s=0.1, c= \"blue\")\n            for i in ITEMS:\n                mns = df.loc[df.fqid==i,['room_coor_x','room_coor_y']].mean().values\n                axs[2, 0].text(mns[0],mns[1],i)\n                axs[2, 0].set_xlim([x_min, x_max])\n                axs[2, 0].set_ylim([y_min, y_max])\n            axs[2, 0].set_title(f'question {question} - PERSON CLICKS - {rm} - Correct')\n\n        # DISPLAY PERSON CLICKS - Incorrect\n        df = train.loc[(train.event_name=='person_click')\n                       &(train.room_fqid==rm)&(train.fqid.notna())\n                       & ~(train.session_id.isin(correct_sessions))]\n        if len(df)!=0:\n            ITEMS = df.fqid.unique()\n            axs[2, 1].scatter(df.room_coor_x,df.room_coor_y,s=0.1, c= \"red\")\n            for i in ITEMS:\n                mns = df.loc[df.fqid==i,['room_coor_x','room_coor_y']].mean().values\n                axs[2, 1].text(mns[0],mns[1],i)\n            axs[2, 1].set_xlim([x_min, x_max])\n            axs[2, 1].set_ylim([y_min, y_max])\n            axs[2, 1].set_title(f'question {question} - PERSON CLICKS - {rm} - Incorrect')\n\n        plt.show()","metadata":{"execution":{"iopub.status.busy":"2023-02-17T03:47:36.455183Z","iopub.execute_input":"2023-02-17T03:47:36.456304Z"},"trusted":true},"execution_count":null,"outputs":[]}]}