{"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\nIn this notebook we display game room click EDA for Kaggle's Predict Student Performance from Game Play competition. The images below are screenshots from playing the game. The game has 19 rooms. (Many room images below required taking multiple screen shots and stitching them together with PhotoShop because the web browser does not show the entire room at once). The plots with dots are where the 11k train users click inside these rooms. For each room, we display scatter plots where users `navigate_click` and where users `person_click`. We then use the column `fqid` to add names to areas of interest in the scatter plots. Discussion about these scatter plots is [here][1].\n\n[1]: https://www.kaggle.com/competitions/predict-student-performance-from-game-play/discussion/387864","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')\nprint('Train data shape:', train.shape )\ntrain.head()","metadata":{"execution":{"iopub.status.busy":"2023-02-15T20:43:54.771438Z","iopub.execute_input":"2023-02-15T20:43:54.771873Z","iopub.status.idle":"2023-02-15T20:44:32.708634Z","shell.execute_reply.started":"2023-02-15T20:43:54.771838Z","shell.execute_reply":"2023-02-15T20:44:32.707401Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ROOMS = train.room_fqid.unique()\nprint('Number of rooms:', len(ROOMS) )\nprint( ROOMS )","metadata":{"execution":{"iopub.status.busy":"2023-02-15T20:44:32.710721Z","iopub.execute_input":"2023-02-15T20:44:32.711351Z","iopub.status.idle":"2023-02-15T20:44:33.921387Z","shell.execute_reply.started":"2023-02-15T20:44:32.711303Z","shell.execute_reply":"2023-02-15T20:44:33.920290Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# DICTIONARY TO IMAGE PATHS\ndd = {}\nPATH = '/kaggle/input/kaggle-game-images/'\ndd['tunic.historicalsociety.closet'] = Image.open(PATH+'closet.png')\ndd['tunic.historicalsociety.basement'] = Image.open(PATH+'basement.png')\ndd['tunic.historicalsociety.entry'] = Image.open(PATH+'entry.png')\ndd['tunic.historicalsociety.collection'] = Image.open(PATH+'collection.png')\ndd['tunic.historicalsociety.stacks'] = Image.open(PATH+'stacks.png')\ndd['tunic.kohlcenter.halloffame'] = Image.open(PATH+'halloffame.png')\ndd['tunic.capitol_0.hall'] = Image.open(PATH+'capitol_hall.png')\ndd['tunic.historicalsociety.closet_dirty'] = Image.open(PATH+'dirty_closet.png')\ndd['tunic.historicalsociety.frontdesk'] = Image.open(PATH+'frontdesk.png')\ndd['tunic.humanecology.frontdesk'] = Image.open(PATH+'humanecology.png')\ndd['tunic.drycleaner.frontdesk'] = Image.open(PATH+'drycleaner.png')\ndd['tunic.library.frontdesk'] = Image.open(PATH+'library.png')\ndd['tunic.library.microfiche'] = Image.open(PATH+'microfiche.png')\ndd['tunic.capitol_1.hall'] = Image.open(PATH+'capitol_hall.png')\ndd['tunic.historicalsociety.cage'] = Image.open(PATH+'cage.png')\ndd['tunic.historicalsociety.collection_flag'] = Image.open(PATH+'collection_flag.png')\ndd['tunic.wildlife.center'] = Image.open(PATH+'wildlife.png')\ndd['tunic.flaghouse.entry'] = Image.open(PATH+'flaghouse.png')\ndd['tunic.capitol_2.hall'] = Image.open(PATH+'capitol_hall.png')\n\n# ITERATE ROOMS AND DISPLAY IMAGES AND SCATTER PLOTS\nfor j,rm in enumerate(ROOMS):\n    print('\\n')\n    print('#'*25)\n    print(f'### ROOM {j+1}:',rm)\n    print('#'*25)\n    \n    # DISPLAY NAVIGATION CLICKS\n    df = train.loc[(train.event_name=='navigate_click')\n                   &(train.room_fqid==rm)&(train.fqid.isna())]\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    plt.figure(figsize=(20,20))\n    plt.scatter(df.room_coor_x,df.room_coor_y,s=0.1)\n    plt.xlim((x_min,x_max))\n    plt.ylim((y_min,y_max))\n    plt.gca().set_aspect('equal')\n    plt.title(f'room {j+1} - NAVIGATION CLICKS - {rm}',size=20)\n    plt.gca().yaxis.tick_right()\n    plt.show()\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 ITEMS OF INTEREST\n    df = train.loc[(train.event_name=='navigate_click')\n                   &(train.room_fqid==rm)&(train.fqid.notna())]\n    ITEMS = df.fqid.unique()\n    plt.figure(figsize=(20,20))\n    plt.scatter(df.room_coor_x,df.room_coor_y,s=0.1)\n    for i in ITEMS:\n        mns = df.loc[df.fqid==i,['room_coor_x','room_coor_y']].mean().values\n        plt.text(mns[0],mns[1],i,fontsize=26)\n    plt.xlim((x_min,x_max))\n    plt.ylim((y_min,y_max))\n    plt.gca().set_aspect('equal')\n    plt.title(f'room {j+1} - ITEMS OF INTEREST - {rm}',size=20)\n    plt.gca().yaxis.tick_right()\n    plt.show()\n    \n    # DISPLAY PERSON CLICKS\n    df = train.loc[(train.event_name=='person_click')\n                   &(train.room_fqid==rm)&(train.fqid.notna())]\n    if len(df)!=0:\n        ITEMS = df.fqid.unique()\n        plt.figure(figsize=(20,20))\n        plt.scatter(df.room_coor_x,df.room_coor_y,s=0.1)\n        for i in ITEMS:\n            mns = df.loc[df.fqid==i,['room_coor_x','room_coor_y']].mean().values\n            plt.text(mns[0],mns[1],i,fontsize=26)\n        plt.xlim((x_min,x_max))\n        plt.ylim((y_min,y_max))\n        plt.gca().set_aspect('equal')\n        plt.title(f'room {j+1} - PERSON CLICKS - {rm}',size=20)\n        plt.gca().yaxis.tick_right()\n        plt.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2023-02-15T20:44:33.922851Z","iopub.execute_input":"2023-02-15T20:44:33.923617Z","iopub.status.idle":"2023-02-15T20:47:35.559431Z","shell.execute_reply.started":"2023-02-15T20:44:33.923577Z","shell.execute_reply":"2023-02-15T20:47:35.557986Z"},"trusted":true},"execution_count":null,"outputs":[]}]}