{"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":"# Clues clicks EDA and feature enginnering (10 new features at the end)\nCredit where credit is due: See [Chris's Notebook](https://www.kaggle.com/code/cdeotte/game-room-click-eda/notebook), and thx @cdeotte for the idea!\n\nIn this notebook, I will only pay attention to **clicks where the user has the find clues** on an item or on the reader in the library and put boolean masks to see when the user clicked that were not the right answer, this will allow you to count the number of mistakes the user did ! \n\n*Dataset for the pictures has also been made public, feel free to re-use those pictures if needed.*\n\nHope this notebook helps you find more ideas, Have fun kaggling !\n\n**See [here](https://www.kaggle.com/code/janmpia/person-clicks-eda-features) for person click EDA by myself similar to this one !**","metadata":{}},{"cell_type":"code","source":"import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport xgboost as xgb\nfrom PIL import Image\nsns.set()\npd.set_option('display.max_column', 200)\n\n\ndtypes={'session_id':np.int64, \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'}","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-02-27T20:12:20.164500Z","iopub.execute_input":"2023-02-27T20:12:20.164884Z","iopub.status.idle":"2023-02-27T20:12:20.178361Z","shell.execute_reply.started":"2023-02-27T20:12:20.164852Z","shell.execute_reply":"2023-02-27T20:12:20.177312Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df =  pd.read_csv(\"/kaggle/input/predict-student-performance-from-game-play/train.csv\", dtype = dtypes)\ndf_final = pd.DataFrame(df.groupby(['session_id','level_group'])['index'].count()).drop(columns = 'index')","metadata":{"execution":{"iopub.status.busy":"2023-02-27T20:12:20.765916Z","iopub.execute_input":"2023-02-27T20:12:20.766386Z","iopub.status.idle":"2023-02-27T20:12:58.427918Z","shell.execute_reply.started":"2023-02-27T20:12:20.766347Z","shell.execute_reply":"2023-02-27T20:12:58.426425Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dd = {}\nPATH = '/kaggle/input/kaggle-game-images/'\ndd['tunic'] = Image.open('/kaggle/input/find-the-spot/dataset/Screenshot_1.jpg')\ndd['plaque'] = Image.open('/kaggle/input/find-the-spot/dataset/Screenshot_2.jpg')\ndd['businesscards'] = Image.open('/kaggle/input/find-the-spot/dataset/Screenshot_3.jpg')\ndd['logbook'] = Image.open('/kaggle/input/find-the-spot/dataset/Screenshot_4.jpg')\ndd['reader'] = Image.open('/kaggle/input/find-the-spot/dataset/Screenshot_5.jpg')\ndd['tracks'] = Image.open('/kaggle/input/find-the-spot/dataset/Screenshot_9.jpg')\ndd['colorbook'] = Image.open('/kaggle/input/find-the-spot/dataset/Screenshot_10.jpg')\ndd['reader_flag'] = Image.open('/kaggle/input/find-the-spot/dataset/Screenshot_11.jpg')\ndd['journals_flag'] = Image.open('/kaggle/input/find-the-spot/dataset/Screenshot_6.jpg')","metadata":{"execution":{"iopub.status.busy":"2023-02-27T20:19:45.626866Z","iopub.execute_input":"2023-02-27T20:19:45.627313Z","iopub.status.idle":"2023-02-27T20:19:45.655131Z","shell.execute_reply.started":"2023-02-27T20:19:45.627274Z","shell.execute_reply":"2023-02-27T20:19:45.654195Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def plot_clicks(fqid, mask):\n    plt.figure(figsize = (10,10))\n    blue_df = df.loc[((df.fqid==fqid))&(df.event_name!='navigate_click') & mask & out]\n    red_df = df.loc[((df.fqid==fqid))&(df.event_name!='navigate_click') & ~mask & out]\n    plt.figure(figsize = (10,10))\n    plt.scatter(blue_df.room_coor_x,blue_df.room_coor_y,alpha = 0.5, s = 5)\n    plt.scatter(red_df.room_coor_x,red_df.room_coor_y,alpha = 0.5, s = 5, color ='red')\n    plt.title(fqid)\n    if fqid in dd:\n        plt.figure(figsize=(10,10))\n        plt.imshow(dd[fqid])\n        plt.axis('off')\n        plt.show()\n    print('------------------------------------------------------------------------------------------------------------------------------')\n    ","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2023-02-27T20:24:53.860708Z","iopub.execute_input":"2023-02-27T20:24:53.861139Z","iopub.status.idle":"2023-02-27T20:24:53.872161Z","shell.execute_reply.started":"2023-02-27T20:24:53.861101Z","shell.execute_reply":"2023-02-27T20:24:53.870991Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"out = True\nright_tunic = ~((df.room_coor_x < 200) & (df.room_coor_x > 50 ) & (df.room_coor_y < 350) & (df.room_coor_y >200))\nright_plaque  = ~((df.room_coor_x < 590) & (df.room_coor_x > 500 ) & (df.room_coor_y < -80) & (df.room_coor_y >-150))\nright_businesscards  = ~((df.room_coor_x < 150) & (df.room_coor_x > 50 ) & (df.room_coor_y < -100) & (df.room_coor_y >-150))\nright_logbook = ~((df.room_coor_y < 40) & (df.room_coor_y >-10))\nright_reader = ~((df.room_coor_x < -150) & (df.room_coor_x > -300 ) & (df.room_coor_y < -90) & (df.room_coor_y >-120))\nright_directory = ~((df.room_coor_x < -60) & (df.room_coor_x > -390 ) & (df.room_coor_y < -280) & (df.room_coor_y >-460))\nright_tracks = ~((df.room_coor_x < 1100) & (df.room_coor_x > 950 ) & (df.room_coor_y < -320) & (df.room_coor_y >-500))\nright_colorbook = True\nright_reader_flag = ~((df.room_coor_x < 0) & (df.room_coor_x > -290 ) & (df.room_coor_y < 110) & (df.room_coor_y >-90))\nright_journals_flag = True\n\nFQID = ['tunic', 'plaque','businesscards','logbook','reader','tracks','colorbook','reader_flag','journals_flag']\nRIGHT_FQID =  [right_tunic, right_plaque, right_businesscards, right_logbook, right_reader, right_tracks, right_colorbook, right_reader_flag, right_journals_flag]\n","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2023-02-27T20:24:54.699179Z","iopub.execute_input":"2023-02-27T20:24:54.700076Z","iopub.status.idle":"2023-02-27T20:24:55.453726Z","shell.execute_reply.started":"2023-02-27T20:24:54.700023Z","shell.execute_reply":"2023-02-27T20:24:55.452486Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# PLOTS","metadata":{}},{"cell_type":"code","source":"for fqid, right in zip(FQID, RIGHT_FQID):\n    plot_clicks(fqid, right)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2023-02-27T20:24:59.107660Z","iopub.execute_input":"2023-02-27T20:24:59.108729Z","iopub.status.idle":"2023-02-27T20:25:07.150616Z","shell.execute_reply.started":"2023-02-27T20:24:59.108680Z","shell.execute_reply":"2023-02-27T20:25:07.149641Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Features","metadata":{}},{"cell_type":"code","source":"def create_feature_from_clicks(fqid, right,lots = 10):\n    IDX = ((df.fqid==fqid))&(df.event_name!='navigate_click') & out & right\n    tmp = df.loc[IDX]\n    events_in_room = tmp.groupby(['session_id','level_group'])['index'].count()\n    return events_in_room\n\nfor fqid, right in zip(FQID, RIGHT_FQID):\n    df_final[f\"{fqid}_mistakes\"] = create_feature_from_clicks(fqid, right)\n\ndf_final.head(12)","metadata":{"execution":{"iopub.status.busy":"2023-02-27T20:25:28.853968Z","iopub.execute_input":"2023-02-27T20:25:28.854391Z","iopub.status.idle":"2023-02-27T20:25:31.114932Z","shell.execute_reply.started":"2023-02-27T20:25:28.854354Z","shell.execute_reply":"2023-02-27T20:25:31.112707Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**See [here](https://www.kaggle.com/code/janmpia/person-clicks-eda-features) for person click EDA by myself similar to this one !**","metadata":{}}]}