{"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 pandas as pd, numpy as np, polars as pl\nfrom sklearn.model_selection import KFold, GroupKFold\nfrom xgboost import XGBClassifier\nfrom tqdm.notebook import tqdm\nfrom sklearn.metrics import f1_score\nimport os\nimport time\nimport pickle\n\nimport warnings\nwarnings.filterwarnings(\"ignore\")\nwarnings.filterwarnings(\"ignore\", category=UserWarning, module=\"xgboost\")","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-06-26T17:27:36.384299Z","iopub.execute_input":"2023-06-26T17:27:36.385562Z","iopub.status.idle":"2023-06-26T17:27:38.598207Z","shell.execute_reply.started":"2023-06-26T17:27:36.385485Z","shell.execute_reply":"2023-06-26T17:27:38.597264Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"- FE with Hoang's extra data: https://www.kaggle.com/code/hoangnguyen719/pspfgp-fe-priyanshu-25-8-oed-v4\n- Training: https://www.kaggle.com/code/hoangnguyen719/pspfgp-xgb-priyanshu-25-8-oedv4\n- Priyanshu original FE and training notebook: https://www.kaggle.com/chaudharypriyanshu/mb-fb5-train-xgb-25-8-external-data","metadata":{}},{"cell_type":"code","source":"THRESHOLD = 0.6155000000000002\nclass CFG:\n    n_folds=5\n    MODEL_PATH='/kaggle/input/pspfgp-xgb-priyanshu-25-8-oedv4/models'\n    TRANSFORMS_PATH='/kaggle/input/pspfgp-xgb-priyanshu-25-8-oedv4/models'","metadata":{"execution":{"iopub.status.busy":"2023-06-26T17:54:59.902693Z","iopub.execute_input":"2023-06-26T17:54:59.903167Z","iopub.status.idle":"2023-06-26T17:54:59.908926Z","shell.execute_reply.started":"2023-06-26T17:54:59.903137Z","shell.execute_reply":"2023-06-26T17:54:59.907936Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"columns = [\n    pl.col(\"page\").cast(pl.Float32),\n    (\n        (pl.col(\"elapsed_time\") - pl.col(\"elapsed_time\").shift(1))\n        .fill_null(0)\n        .clip(0, 3600000)\n        .over([\"session_id\", \"level_group\"])\n        .alias(\"elapsed_time_diff\")\n    ),\n     \n    (\n        (pl.col(\"screen_coor_x\") - pl.col(\"screen_coor_x\").shift(1))\n        .abs()\n        .over([\"session_id\", \"level\"])\n    ),\n    (\n        (pl.col(\"screen_coor_y\") - pl.col(\"screen_coor_y\").shift(1))\n        .abs()\n        .over([\"session_id\", \"level\"])\n    ),\n    (\n        (pl.col(\"event_name\").fill_null('NAT') + pl.col(\"name\").fill_null('NAT')).alias('event_comb')\n    ),    \n    \n    (\n        (pl.col(\"event_name\")=='navigate_click').alias(\"C_naviate_click\")\n    ),\n    \n    (\n        (pl.col(\"event_name\")=='observation_click').alias(\"C_observation_click\")\n    ),       \n    \n    (\n        (pl.col(\"event_name\")=='object_click').alias(\"C_object_click\")\n    ),         \n    pl.col(\"fqid\").fill_null(\"fqid_None\"),\n    pl.col(\"text_fqid\").fill_null(\"text_fqid_None\"),\n    pl.col('text').fill_null(\"undefined\"),\n]\n\n\ncolumns1=[\n    (pl.col('C_naviate_click').cumsum().over([\"session_id\", \"level_group\"]).alias('C_naviate_click')),\n    (pl.col('C_observation_click').cumsum().over([\"session_id\", \"level_group\"]).alias('C_observation_click')),\n    (pl.col('C_object_click').cumsum().over([\"session_id\", \"level_group\"]).alias('C_object_click')),\n]","metadata":{"execution":{"iopub.status.busy":"2023-06-26T17:55:00.751069Z","iopub.execute_input":"2023-06-26T17:55:00.751953Z","iopub.status.idle":"2023-06-26T17:55:00.764212Z","shell.execute_reply.started":"2023-06-26T17:55:00.751915Z","shell.execute_reply":"2023-06-26T17:55:00.763088Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"CATS = ['event_name', 'name', 'fqid', 'room_fqid', 'text_fqid','event_comb']\nNUMS = ['page', 'room_coor_x', 'room_coor_y', 'screen_coor_x', 'screen_coor_y',\n        'hover_duration', 'elapsed_time_diff']\n\nname = ['basic', 'undefined', 'close', 'open', 'prev', 'next']\n\nevent_name= ['cutscene_click', 'person_click', 'navigate_click',\n       'observation_click', 'notification_click', 'object_click',\n       'object_hover', 'map_hover', 'map_click', 'checkpoint',\n       'notebook_click']\n\nlevel=dict()\nlevel[\"0-4\"]=[0, 1, 2, 3, 4]\nlevel[\"5-12\"]=[ 5,  6,  7,  8,  9, 10, 11, 12]\nlevel[\"13-22\"]=[13, 14, 15, 16, 17, 18, 19, 20, 21, 22]\n\nfqid=dict()\nfqid[\"0-4\"]=['intro', 'gramps', 'teddy', 'photo', 'notebook','retirement_letter', 'tobasement', 'janitor', 'toentry',\n       'groupconvo', 'report', 'boss', 'wells', 'directory','tocollection', 'cs', 'tunic', 'tunic.hub.slip', 'tostacks',\n       'outtolunch', 'tocloset', 'tomap', 'tunic.historicalsociety','tunic.kohlcenter', 'plaque', 'plaque.face.date', 'togrampa',\n       'tunic.capitol_0', 'chap1_finale', 'chap1_finale_c','block_tocollection', 'doorblock', 'block_tomap2', 'block_tomap1','block_0']\n\nfqid[\"5-12\"]=['boss', 'toentry', 'tunic.historicalsociety', 'tobasement','tocloset_dirty', 'what_happened', 'gramps', 'trigger_scarf','trigger_coffee', 'tomap', 'tunic.capitol_1', 'tostacks','tofrontdesk', 'archivist', 'magnify', 'tunic.humanecology','worker', 'businesscards', 'businesscards.card_0.next',\n       'businesscards.card_1.next', 'businesscards.card_bingo.next','businesscards.card_bingo.bingo', 'tohallway', 'tunic.drycleaner',\n       'logbook', 'logbook.page.bingo', 'tunic.library', 'tomicrofiche','reader', 'reader.paper0.next', 'reader.paper1.next',\n       'reader.paper2.bingo', 'wellsbadge', 'journals','journals.hub.topics', 'journals.pic_0.next',\n       'journals.pic_1.next', 'journals.pic_2.bingo', 'chap2_finale_c','outtolunch', 'janitor', 'tunic.kohlcenter', 'reader.paper2.next',\n       'directory', 'journals.pic_2.next', 'tunic.capitol_0', 'reader.paper1.prev', 'reader.paper0.prev', 'photo', 'block_0','block_magnify', 'door_block_clean', 'door_block_talk','reader.paper2.prev', 'block', 'tocollection', 'tunic', 'plaque',\n       'tunic.hub.slip', 'block_badge', 'block_badge_2', 'block_1','chap2_finale']\nfqid[\"13-22\"]=['toentry', 'tunic.drycleaner', 'tunic.historicalsociety','tunic.capitol_1', 'tunic.library', 'tobasement', 'ch3start',\n       'seescratches', 'gramps', 'tocage', 'glasses', 'teddy', 'tostacks','directory', 'directory.closeup.archivist', 'tofrontdesk', 'key',\n       'unlockdoor', 'confrontation', 'savedteddy', 'tocollectionflag','groupconvo_flag', 'wells', 'boss', 'tomap', 'tunic.capitol_2',\n       'tunic.wildlife', 'coffee', 'crane_ranger', 'remove_cup', 'expert','tracks', 'tracks.hub.deer', 'tunic.flaghouse', 'flag_girl',\n       'colorbook', 'worker', 'tomicrofiche', 'reader_flag','reader_flag.paper0.next', 'reader_flag.paper1.next',\n       'reader_flag.paper2.bingo', 'archivist_glasses', 'journals_flag','journals_flag.hub.topics_old', 'journals_flag.hub.topics',\n       'journals_flag.pic_0.bingo', 'journals_flag.pic_0.next','chap4_finale_c', 'lockeddoor', 'tocloset_dirty',\n       'tunic.humanecology', 'tunic.kohlcenter', 'tohallway', 'photo',\n       'plaque', 'journals', 'journals.hub.topics', 'journals.pic_0.next','journals.pic_1.next', 'journals.pic_2.bingo',\n       'journals.pic_2.next', 'businesscards','businesscards.card_0.next', 'businesscards.card_1.next',\n       'logbook', 'reader', 'reader.paper0.next', 'reader.paper1.next','reader.paper2.prev', 'reader.paper2.next', 'reader.paper0.prev',\n       'reader_flag.paper1.prev', 'journals_flag.pic_0_old.next','journals_flag.pic_1_old.next', 'tocollection', 'tunic',\n       'tunic.hub.slip', 'journals_flag.pic_1.bingo','journals_flag.pic_1.next', 'journals_flag.pic_2.bingo',\n       'journals_flag.pic_2.next', 'reader_flag.paper2.next','businesscards.card_bingo.next', 'reader_flag.paper0.prev',\n       'journals_flag.pic_2_old.next', 'outtolunch', 'need_glasses','block_nelson', 'reader_flag.paper2.prev', 'reader.paper1.prev','fox']\n\n\nroom_fqid=dict()\nroom_fqid[\"0-4\"]=['tunic.historicalsociety.closet','tunic.historicalsociety.basement',\n       'tunic.historicalsociety.entry','tunic.historicalsociety.collection',\n       'tunic.historicalsociety.stacks', 'tunic.kohlcenter.halloffame','tunic.capitol_0.hall']\nroom_fqid[\"5-12\"]= ['tunic.capitol_0.hall', 'tunic.historicalsociety.entry',\n       'tunic.historicalsociety.basement','tunic.historicalsociety.closet_dirty','tunic.historicalsociety.stacks',\n       'tunic.historicalsociety.frontdesk','tunic.humanecology.frontdesk', 'tunic.drycleaner.frontdesk',\n       'tunic.library.frontdesk', 'tunic.library.microfiche','tunic.capitol_1.hall', 'tunic.historicalsociety.collection','tunic.kohlcenter.halloffame']\n\nroom_fqid[\"13-22\"]= ['tunic.capitol_1.hall', 'tunic.historicalsociety.entry','tunic.historicalsociety.basement', 'tunic.historicalsociety.cage',\n       'tunic.historicalsociety.stacks','tunic.historicalsociety.frontdesk','tunic.historicalsociety.collection_flag', 'tunic.wildlife.center','tunic.flaghouse.entry', 'tunic.library.frontdesk',\n       'tunic.library.microfiche', 'tunic.capitol_2.hall','tunic.historicalsociety.closet_dirty','tunic.humanecology.frontdesk', 'tunic.kohlcenter.halloffame',\n       'tunic.drycleaner.frontdesk', 'tunic.historicalsociety.collection']\n\n\ntext_fqid=dict()\n\ntext_fqid[\"0-4\"]=['tunic.historicalsociety.closet.intro',\n       'tunic.historicalsociety.closet.gramps.intro_0_cs_0',\n       'tunic.historicalsociety.closet.teddy.intro_0_cs_0',\n       'tunic.historicalsociety.closet.teddy.intro_0_cs_5',\n       'tunic.historicalsociety.closet.photo',\n       'tunic.historicalsociety.closet.notebook',\n       'tunic.historicalsociety.closet.retirement_letter.hub',\n       'tunic.historicalsociety.basement.janitor',\n       'tunic.historicalsociety.entry.groupconvo',\n       'tunic.historicalsociety.entry.boss.talktogramps',\n       'tunic.historicalsociety.entry.wells.talktogramps',\n       'tunic.historicalsociety.collection.cs',\n       'tunic.historicalsociety.collection.tunic.slip',\n       'tunic.historicalsociety.collection.gramps.found',\n       'tunic.historicalsociety.stacks.outtolunch',\n       'tunic.kohlcenter.halloffame.plaque.face.date',\n       'tunic.kohlcenter.halloffame.togrampa',\n       'tunic.historicalsociety.entry.block_tocollection',\n       'tunic.historicalsociety.collection.tunic',\n       'tunic.historicalsociety.collection.gramps.lost',\n       'tunic.historicalsociety.closet.doorblock',\n       'tunic.historicalsociety.entry.block_tomap2',\n       'tunic.historicalsociety.entry.block_tomap1',\n       'tunic.capitol_0.hall.chap1_finale_c',\n       'tunic.kohlcenter.halloffame.block_0',\n       'tunic.historicalsociety.collection.gramps.look_0',\n       'tunic.historicalsociety.entry.gramps.hub']\n\ntext_fqid[\"5-12\"]=['tunic.capitol_0.hall.boss.talktogramps',\n       'tunic.historicalsociety.closet_dirty.what_happened',\n       'tunic.historicalsociety.closet_dirty.gramps.helpclean',\n       'tunic.historicalsociety.closet_dirty.trigger_scarf',\n       'tunic.historicalsociety.closet_dirty.trigger_coffee',\n       'tunic.historicalsociety.closet_dirty.gramps.news',\n       'tunic.historicalsociety.frontdesk.archivist.hello',\n       'tunic.historicalsociety.frontdesk.archivist.need_glass_0',\n       'tunic.historicalsociety.frontdesk.magnify',\n       'tunic.historicalsociety.frontdesk.archivist.have_glass',\n       'tunic.historicalsociety.frontdesk.archivist.have_glass_recap',\n       'tunic.humanecology.frontdesk.worker.intro',\n       'tunic.humanecology.frontdesk.businesscards.card_bingo.bingo',\n       'tunic.humanecology.frontdesk.worker.badger',\n       'tunic.drycleaner.frontdesk.worker.hub',\n       'tunic.drycleaner.frontdesk.logbook.page.bingo',\n       'tunic.drycleaner.frontdesk.worker.done',\n       'tunic.library.frontdesk.worker.hello',\n       'tunic.library.microfiche.reader.paper2.bingo',\n       'tunic.library.frontdesk.wellsbadge.hub',\n       'tunic.library.frontdesk.worker.wells',\n       'tunic.capitol_1.hall.boss.haveyougotit',\n       'tunic.historicalsociety.frontdesk.archivist.newspaper',\n       'tunic.historicalsociety.stacks.journals.pic_2.bingo',\n       'tunic.historicalsociety.stacks.outtolunch',\n       'tunic.historicalsociety.basement.janitor',\n       'tunic.historicalsociety.closet_dirty.gramps.archivist',\n       'tunic.historicalsociety.closet_dirty.photo',\n       'tunic.humanecology.frontdesk.block_0',\n       'tunic.library.frontdesk.worker.wells_recap',\n       'tunic.capitol_1.hall.chap2_finale_c',\n       'tunic.historicalsociety.frontdesk.block_magnify',\n       'tunic.historicalsociety.closet_dirty.door_block_clean',\n       'tunic.historicalsociety.closet_dirty.door_block_talk',\n       'tunic.historicalsociety.stacks.block',\n       'tunic.historicalsociety.frontdesk.archivist.newspaper_recap',\n       'tunic.library.frontdesk.worker.hello_short',\n       'tunic.historicalsociety.closet_dirty.gramps.nothing',\n       'tunic.historicalsociety.frontdesk.archivist.need_glass_1',\n       'tunic.library.frontdesk.worker.droppedbadge',\n       'tunic.drycleaner.frontdesk.worker.takealook',\n       'tunic.library.frontdesk.worker.preflag',\n       'tunic.historicalsociety.frontdesk.archivist.foundtheodora',\n       'tunic.drycleaner.frontdesk.worker.done2',\n       'tunic.library.frontdesk.block_badge',\n       'tunic.drycleaner.frontdesk.block_0',\n       'tunic.library.microfiche.block_0',\n       'tunic.library.frontdesk.block_badge_2',\n       'tunic.humanecology.frontdesk.block_1',\n       'tunic.drycleaner.frontdesk.block_1']\n\ntext_fqid[\"13-22\"]=['tunic.historicalsociety.basement.ch3start',\n       'tunic.historicalsociety.basement.gramps.whatdo',\n       'tunic.historicalsociety.basement.seescratches',\n       'tunic.historicalsociety.cage.glasses.beforeteddy',\n       'tunic.historicalsociety.cage.teddy.trapped',\n       'tunic.historicalsociety.cage.glasses.afterteddy',\n       'tunic.historicalsociety.entry.directory.closeup.archivist',\n       'tunic.historicalsociety.frontdesk.key',\n       'tunic.historicalsociety.cage.unlockdoor',\n       'tunic.historicalsociety.cage.confrontation',\n       'tunic.historicalsociety.basement.savedteddy',\n       'tunic.historicalsociety.collection_flag.gramps.flag',\n       'tunic.historicalsociety.entry.groupconvo_flag',\n       'tunic.historicalsociety.entry.wells.flag',\n       'tunic.historicalsociety.entry.boss.flag',\n       'tunic.historicalsociety.entry.wells.flag_recap',\n       'tunic.historicalsociety.entry.boss.flag_recap',\n       'tunic.wildlife.center.coffee',\n       'tunic.wildlife.center.wells.animals',\n       'tunic.wildlife.center.wells.animals2',\n       'tunic.wildlife.center.crane_ranger.crane',\n       'tunic.wildlife.center.remove_cup',\n       'tunic.wildlife.center.expert.removed_cup',\n       'tunic.wildlife.center.tracks.hub.deer',\n       'tunic.wildlife.center.expert.recap',\n       'tunic.wildlife.center.wells.nodeer',\n       'tunic.flaghouse.entry.flag_girl.hello',\n       'tunic.flaghouse.entry.colorbook',\n       'tunic.flaghouse.entry.flag_girl.symbol',\n       'tunic.flaghouse.entry.flag_girl.symbol_recap',\n       'tunic.library.frontdesk.worker.flag',\n       'tunic.library.microfiche.reader_flag.paper2.bingo',\n       'tunic.library.frontdesk.worker.nelson',\n       'tunic.historicalsociety.frontdesk.archivist_glasses.confrontation',\n       'tunic.historicalsociety.stacks.journals_flag.pic_0.bingo',\n       'tunic.historicalsociety.cage.lockeddoor',\n       'tunic.humanecology.frontdesk.worker.badger',\n       'tunic.capitol_2.hall.boss.haveyougotit',\n       'tunic.drycleaner.frontdesk.worker.done2',\n       'tunic.library.frontdesk.worker.preflag',\n       'tunic.historicalsociety.closet_dirty.photo',\n       'tunic.historicalsociety.stacks.journals.pic_2.bingo',\n       'tunic.historicalsociety.collection_flag.gramps.recap',\n       'tunic.wildlife.center.wells.nodeer_recap',\n       'tunic.library.frontdesk.worker.flag_recap',\n       'tunic.historicalsociety.frontdesk.archivist_glasses.confrontation_recap',\n       'tunic.capitol_1.hall.boss.writeitup',\n       'tunic.historicalsociety.stacks.journals_flag.pic_1.bingo',\n       'tunic.historicalsociety.stacks.journals_flag.pic_2.bingo',\n       'tunic.capitol_2.hall.chap4_finale_c',\n       'tunic.flaghouse.entry.flag_girl.hello_recap',\n       'tunic.historicalsociety.basement.gramps.seeyalater',\n       'tunic.historicalsociety.stacks.outtolunch',\n       'tunic.historicalsociety.cage.need_glasses',\n       'tunic.library.frontdesk.block_nelson',\n       'tunic.library.frontdesk.worker.nelson_recap',\n       'tunic.wildlife.center.fox.concern']\n\n\ntext=dict()\n\ntext['0-4']=['undefined', 'Whatcha doing over there, Jo?',\n       'Just talking to Teddy.', 'I gotta run to my meeting!',\n       'Can I come, Gramps?',\n       'Sure thing, Jo. Grab your notebook and come upstairs!',\n       'See you later, Teddy.', \"I get to go to Gramps's meeting!\",\n       'Now where did I put my notebook?', '\\\\u00f0\\\\u0178\\\\u02dc\\\\u00b4',\n       'I love these photos of me and Teddy!', 'Found it!',\n       'Gramps is in trouble for losing papers?', \"This can't be right!\",\n       'Gramps is a great historian!', \"Hmm. Button's still not working.\",\n       \"Let's get started. The Wisconsin Wonders exhibit opens tomorrow!\",\n       'Who wants to investigate the shirt artifact?',\n       \"Not Leopold here. He's been losing papers lately.\", 'Hey!',\n       \"It's true, they do keep going missing lately.\", 'See?',\n       'Besides, I already figured out the shirt.',\n       \"It's a women's basketball jersey!\", 'That settles it.',\n       'Wells, finish up your report.',\n       \"Leopold, why don't you help me set up in the Capitol?\",\n       'We need to talk about that missing paperwork.', 'Will do, Boss.',\n       \"Hey Jo, let's take a look at the shirt!\",\n       'Your grampa is waiting for you in the collection room.',\n       \"Why don't you go catch up with your grampa?\",\n       'What a fascinating artifact!', \"Wow, that's so cool, Gramps!\",\n       'Can I take a closer look?',\n       \"Hmmm. Shouldn't you be doing your homework?\",\n       \"It's already all done!\",\n       'Plus, my teacher said I could help you out for extra credit!',\n       \"Well, that's good enough for me.\",\n       'Go ahead, take a peek at the shirt!', 'This looks like a clue!',\n       \"I'll record this in my notebook.\", 'Find anything?',\n       'Yes! This old slip from 1916.', 'I knew it!',\n       \"I'm not so sure that this is a basketball jersey.\",\n       'Wait, you mean Wells is wrong?!',\n       'Could be. But we need evidence!',\n       \"Why don't you head to the Basketball Center and rustle up some clues?\",\n       'Sure!',\n       \"I'll be at the Capitol. Let me know if you find anything!\",\n       'Better check back later.', \"That's it!\",\n       \"The slip is from 1916 but the team didn't start until 1974!\",\n       'Our shirt is too old to be a basketball jersey!',\n       'I need to get to the Capitol and tell Gramps!',\n       'I should see what Grampa is up to!',\n       'Ugh. Meetings are so boring.',\n       'Grab your notebook and come upstairs!', 'Hang tight, Teddy.',\n       \"I'll hurry back and then we can go exploring!\",\n       'Well, Leopold here is always losing papers...',\n       'Ha. Told you so!', 'Can we hurry up, Gramps?',\n       'Teddy and I were gonna go climb that huge tree out back!',\n       \"Hmmm. Don't forget about your homework.\",\n       'Your teacher said you missed 7 assignments in a row!',\n       'So? History is boring!', 'I suppose historians are boring, too?',\n       \"No way, Gramps. You're the best!\", 'Then do it for me!',\n       'Your teacher said you could help me for extra credit.',\n       'A boring old shirt.', 'Just this old slip from 1916.',\n       'Do I have to?', 'Um... what did you want me to do again?',\n       'Head over to the Basketball Center.',\n       'Hopefully you can find some clues!', 'Meetings are BORING!',\n       \"I feel like I'm forgetting something.\",\n       'Gramps is the best historian ever!', 'This button never works!',\n       \"Why don't you go play with your grampa?\",\n       \"Look at that! It's the bee's knees!\",\n       \"Well, I did SOME of those. I just couldn't find them!\",\n       'Did you do all of them?', 'No... because history is boring!',\n       'Hooray, a boring old shirt.', 'Hot Dog! I knew it!',\n       'Ooh, I like clues!', 'Hopefully you can rustle up some clues!',\n       'I should go talk to Gramps!',\n       'Yes! This cool old slip from 1916.',\n       'I should see what Gramps is up to!',\n       'Gramps said to look for clues. Better look around.',\n       'Have a look at the artifact!', 'Come on, Jo!',\n       \"Meet me back in my office and we'll get started!\"]\n\ntext['5-12']=['What are you still doing here,  Jolie?',\n       'Go find your grampa and get to work!', 'Oh no!', 'undefined',\n       'What happened here?!', \"I don't know!\",\n       'I got here and the whole place was a mess!',\n       'Can you help me tidy up?',\n       \"Teddy's scarf! Somebody must've taken him!\",\n       'Try not to panic, Jo.', 'Maybe he just got scared and ran off.',\n       'But he never goes anywhere without his scarf!',\n       \"I think he's in trouble!\", 'Is this your coffee, Gramps?',\n       \"Nope, that's from Bean Town. I only drink Holdgers!\",\n       \"Who could've done this?\", \"It must've been Wells.\",\n       \"He's always trying to get you in trouble, and he doesn't like animals!\",\n       'Slow down, Jo.', 'But what if Wells kidnapped Teddy?',\n       'Then we need evidence.',\n       \"You're right, Gramps. Let's investigate!\",\n       \"I'm afraid my papers have gone missing in this mess.\",\n       \"You'll have to get started without me.\", \"Okay. I'll find Teddy!\",\n       \"And I'll figure out the shirt, too.\",\n       'I knew I could count on you, Jo!',\n       \"Why don't you go upstairs and see the archivist?\",\n       \"He's our expert record keeper.\", 'I need your help!',\n       'Who are you?', \"I'm Leopold's grandkid!\",\n       \"Sorry, I'm too busy for kids right now.\",\n       'Now if only I could read this thing.',\n       \"Can't believe I lost my reading glasses.\",\n       'I bet the archivist could use this!', \"Ah, that's better!\",\n       'Did you have a question?', 'Yes! I was wondering-',\n       'Wait a minute!', 'Where did you get that coffee?',\n       \"Oh, that's from Bean Town.\",\n       'I ran into Wells there this morning.', 'Wells? I knew it!',\n       'Do you know anything about this slip?',\n       'I found it on an old shirt.', 'An old shirt? Try the university.',\n       'You can talk to a textile expert there.',\n       \"What's a textile expert?\", 'They study clothes and fabric.',\n       'Great! Thanks for the help!', 'Head over to the university.',\n       'Hello there!', 'Wow! What is all this stuff?',\n       \"It's our Norwegian Craft exhibit!\", 'Can I give you the tour?',\n       \"Sorry, I'm in a hurry.\", 'Do you know what this slip is?',\n       'Looks like a dry cleaning receipt.', 'Thanks.',\n       'Now I Just need to find all the cleaners from way back in 1916.',\n       'Maybe I can help!',\n       \"I've got a stack of business cards from my favorite cleaners.\",\n       \"Why don't you take a look?\",\n       'This place was around in 1916! I can start there!',\n       \"You haven't seen any badgers around here, have you?\",\n       'Badgers? No.', 'Okay. Thanks anyway.', 'Hi! How can I help you?',\n       'I need to find the owner of this slip.',\n       \"Well, I can't show our log books to just anybody.\", 'Please?',\n       \"It's for Grampa Leo. He's a historian!\",\n       'Leo... you mean Leopold?',\n       'Your gramps is awesome! Always full of stories.',\n       \"Guess it couldn't hurt to let you take a look.\",\n       \"Here's the log book.\", \"It's a match!\",\n       'Theodora Youmans must be the owner!',\n       'Do you know who Theodora Youmans is?',\n       \"Hmmm... not sure. Why don't you try the library?\",\n       'Thanks for the help!', 'Oh, hello there!', 'How can I help you?',\n       'Have you seen a badger around here?', \"I'm afraid not.\",\n       'Please let me know if you do.',\n       \"I'm also looking for Theodora Youmans. Have you heard of her?\",\n       'Theodora Youmans? Of course!',\n       \"Check out our microfiche. It's right through that door.\",\n       'Youmans was a suffragist!', 'She helped get votes for women!',\n       'Wells! What was he doing here? I should ask the librarian.',\n       'What was Wells doing here?', 'He was looking for a taxidermist.',\n       \"What's a taxidermist?\", 'Not sure. Here, let me look it up.',\n       '\\\\Taxidermy: the art of preparing, stuffing, and mounting the skins of animals.\\\\',\n       'Oh no... Teddy!', 'Can you help me find Wells?',\n       'You could ask the archivist. He knows everybody!',\n       \"Jolie! I was hoping you'd stop by. Any news on the shirt artifact?\",\n       \"I haven't quite figured it out just yet...\",\n       \"Well, get on it. I'm counting on you and your gramps to figure this out!\",\n       'Can you help me? I need to find Wells!', \"I haven't seen him.\",\n       'Please? This is really important.', \"Sorry, can't help you.\",\n       'Do you have any info on Theodora Youmans?',\n       'Theodora Youmans? Is that who owned the shirt?', 'Yep.',\n       \"Why didn't you say so?\",\n       'Youmans was a suffragist here in Wisconsin.',\n       'She led marches and helped women get the right to vote!',\n       \"Wait a sec. Women couldn't vote?!\",\n       'Nope. But Youmans and other suffragists worked hard to change that.',\n       'Thanks to them, Wisconsin was the first state to approve votes for women!',\n       'Wow!', \"Here's a call number to find more info in the Stacks.\",\n       'Where are the Stacks?', 'Right outside the door.',\n       'Hey, this is Youmans!', \"And look! She's wearing the shirt!\",\n       'I should go to the Capitol and tell everyone!',\n       'Better check back later.', \"Hmm. Button's still not working.\",\n       'What should I do first?',\n       'Head upstairs and talk to the archivist. He might be able to help!',\n       'What the-', 'I have an idea.',\n       \"He's wrong about old shirts and his name rhymes with \\\\smells\\\\...\",\n       'BUT WELLS STOLE TEDDY!', 'Could be. But we need evidence.',\n       \"Fine. Let's investigate!\",\n       \"Don't worry, Gramps. I'll find Teddy!\",\n       \"Please let me know if you do. It's important!\",\n       'I need to find Wells right away! Do you know where he is?',\n       'I need to find Wells!!!', \"I can't calm down. This is important!\",\n       'Ugh. Fine.', 'I love these photos of me and Teddy.',\n       'I should stay and look for clues!', 'Where should I go again?',\n       'You could try the archivist. Maybe he can help you find Wells!',\n       'Hi, Mrs. M.', \"I don't need that right now.\",\n       'I got here and the whole place was ransacked!',\n       'Hold your horses, Jo.', '*grumble grumble*', 'And you are?',\n       \"I don't have time for kids.\",\n       'Now if only I could read this thing. Blasted tiny letters...',\n       'Knew what?', 'Did you have a question or not?', 'Yes!',\n       \"You're still here? I'm trying to work!\",\n       'Run along to the university.', 'Ooh, thanks!',\n       'Now I just need to find all the cleaners from wayyyy back in 1916.',\n       'Yikes... this could take a while.', 'Hi! *cough*',\n       'Can you help-', '*cough cough*', 'Can you help me-',\n       '*COUGH COUGH COUGH*', 'Um, are you okay?',\n       \"Oh, I'm fine! Just a little hoarse.\",\n       'Ha! What do you call a pony with a sore throat?', 'Huh?',\n       'A little horse!', \"Ha! You're funny.\",\n       'I got that one from my Gramps!',\n       'Can you help me? I need to find the owner of this slip.',\n       \"Yup, that's him!\", \"Unless you're too busy horsing around.\",\n       'Ha! Good one.', \"You look like you're on a mission.\",\n       'Two missions, actually!', 'Oh my!',\n       'I need to find Wells right away!! Do you know where he is?',\n       \"Calm down, kid. I haven't seen him.\",\n       'I should help Gramps clean.',\n       \"Maybe there's a clue in this mess!\",\n       \"Poor Gramps! I should make sure he's okay.\",\n       'The archivist said I should look in the stacks.',\n       'Yeah. Thanks anyway.',\n       'What are you waiting for? The Stacks are right outside the door.',\n       'This button never works!', 'Are you okay?',\n       \"Weren't you going to check out our microfiche?\",\n       \"I'm sure you'll find Theodora in there somewhere!\",\n       'Well? What are you still doing here?',\n       'So much cleaning to do...',\n       'I used to have a magnifying glass around here\\\\u00e2\\\\u20ac\\\\u00a6',\n       \"But I hear the museum's got one on the loose!\",\n       \"Did you drop something, Dear? There's a card on the floor.\",\n       'Take a look!', \"It's such a nice fall day.\", 'I found it!',\n       'Theodora wearing the shirt!', 'You better get to the capitol!',\n       'Nice decorations.', 'Nice seeing you, Jolie!',\n       'Did you drop something, Dear?',\n       'I should find out if she can help me!', 'Ooh, nice decorations!',\n       'The libarian said I could find some information on Youmans in here...',\n       'I should ask the librarian why Wells was here.',\n       \"I wonder if there's a clue in those business cards...\",\n       'Thanks. Did you figure out the shirt?',\n       'Welcome back, Jolie. Did you figure out the shirt?',\n       'I should check that logbook to see who owned this slip...',\n       'AND I know who took Teddy!', 'Who is Teddy?',\n       \"And where's your grampa?\", 'Sorry for the delay, Boss.',\n       'I had some cleaning up to do in my office.',\n       'Mrs. M, I think Wells kidnapped Teddy.',\n       \"And he messed up Gramps's office, too!\",\n       'One step at a time, Jo.', 'Did you figure out the shirt?',\n       'I knew you could do it, Jo!',\n       'Now can I tell you what happened to Teddy?', 'He needs our help!',\n       \"Sorry I'm late.\", \"Wells! Where's Teddy? Is he okay?\",\n       'I figured out that you kidnapped him!', 'Easy, Jo.',\n       \"Why don't you prove your case?\",\n       \"It'll be okay, Jo. We'll find Teddy!\",\n       'Nice work on the shirt, Jolie!',\n       'Leopold, can you run back to the museum?', 'Sounds good, Boss.',\n       'Jo, meet me back at my office.',\n       'I hope you find your badger, kid.', 'Here I am!',\n       'Wells sabotaged Gramps!', 'AND he stole Teddy!']\ntext['13-22']=['Jo!', 'Check out the next artifact!', 'What is it?',\n       \"I think it's a flag! Pretty interesting, huh?\",\n       \"It's really cool, Gramps. But I'm worried about Teddy.\",\n       \"He's still missing!\", \"We'll find him, Jo.\",\n       'Want to look for more clues?', \"We'll find Teddy.\",\n       'We just have to keep our eyes open!',\n       'Hey, look at those scratches!',\n       'The kidnapper probably took Teddy on the elevator!',\n       \"You're right, Jo!\", \"Why isn't the button working?\",\n       \"We'll need a key card.\", 'I had one, but Teddy chewed it up.',\n       \"I've got Wells's ID!\", 'What should we do next?',\n       \"I need to take the artifact upstairs. Why don't you investigate those scratch marks?\",\n       \"Okay. I'll try.\", 'Teddy, here I come!',\n       'I wonder whose glasses these are.', 'Teddy!!!',\n       \"Hang on. I'll get you out of there!\",\n       'Whoever lost these glasses probably took Teddy!',\n       'How can I find out whose glasses these are?',\n       'Oh! There was a staff directory in the entryway!',\n       \"I'll go look at everyone's pictures!\",\n       'Those are the same glasses!',\n       \"The archivist must've taken Teddy!\",\n       \"Yes! It's the key for Teddy's cage!\", 'I found the key!',\n       \"Come on, let's get out of here!\", \"Here's your scarf back!\",\n       'undefined', 'Hey!', 'What are you doing down here?',\n       'And how did that badger get free?',\n       \"I'm here to rescue my friend!\", \"What's going on here?\",\n       'Thanks for coming, Boss.', 'I told you!',\n       'I captured a badger in our museum!',\n       \"He's been eating my lunch every day this week!\", 'He has??',\n       \"I've seen him eating homework and important papers, too.\",\n       \"Jolie- keep your badger under control, or he'll have to go.\",\n       'And you, Frank-', \"You can't just steal Jolie's pet.\",\n       'Ugh. Fine.', 'Alright, Jolie. Back to work.',\n       'Your grampa is waiting for you in the collection room.',\n       \"Come on, Teddy. Let's go help Gramps!\", \"Let's go help Gramps!\",\n       'Gramps must be up in the collection room.', \"Let's go find him!\",\n       \"Teddy! I'm glad to see you.\", 'The archivist had him locked up!',\n       'Poor badger.', \"You're becoming quite the detective, Jo.\",\n       'Notice any clues about this flag?',\n       'Well... it looks hand-stitched.', 'Good catch!',\n       'Go on, tell the boss what you found!',\n       \"I'm telling you, Boss. Taxidermy is the way to go!\",\n       'Nonsense. I want live animals at the exhibit, not stuffed ones.',\n       \"Ah, Jolie! I'm glad you're here.\",\n       \"I'm putting you in charge of the flag case.\",\n       'Make sure to get some old photos for the exhibit, like last time!',\n       \"Wait! Can't I do it?\",\n       'The symbol on the flag looks sort of like a deer hoof.',\n       'It could be an early design for the Wisconsin state flag!',\n       'Wells, you already have a job to do.', 'What now, kid?',\n       'Do you really think that symbol is a deer hoof?', 'Not sure.',\n       'Do you know where I can find a deer expert?',\n       'Hmm. You could try the Aldo Leopold Wildlife Center.',\n       'I have to head over there and check out the animals.',\n       \"I'll ride with you!\", \"Come on, kid. Let's go.\",\n       'Head over to the Wildlife Center!',\n       \"I'm sure they'll be able to help.\",\n       'People sure drink a lot of coffee around here.',\n       \"I can't believe this.\", 'Ugh...',\n       'Oh no! What happened to that crane?',\n       'Her beak is stuck in a coffee cup.', \"It's lucky we found her.\",\n       'Ugh! Those cups are all over the place.',\n       \"I need to get her free. She won't hold still!\",\n       'Can Teddy and I help?', 'Sure! Give it a try.',\n       'Careful. That beak is sharp!', 'We need to calm her down, Teddy.',\n       'Any ideas?', '\\\\u00f0\\\\u0178\\\\u00a6\\\\u2014',\n       'Oh yeah, cranes eat insects!',\n       'Luckily there are tons of insects around here...', 'Got one!',\n       \"Maybe she'll let me take off the cup!\",\n       \"It's OK, girl! Look, I found you a cricket!\",\n       'You did it! Thanks, kid.', 'Can I help you with anything?',\n       \"I'm investigating this symbol.\", 'Does it look like a deer hoof?',\n       \"There's a diagram of animal tracks over there.\",\n       'Go take a look!', \"That hoofprint doesn't match the flag!\",\n       'Thanks for your help, kid!', \"So? What'd you find out?\",\n       \"Looks like it's not a deer hoof.\",\n       \"Oh no. If I don't impress the boss soon,  I'm gonna get fired!\",\n       'Hey, Wells...', 'I think I might be able to help you.',\n       \"No thanks. I don't need help from kids.\",\n       'Are you sure? I know where you can find a real, live badger for the exhibit!',\n       'Wait! What?! Really?', 'Wells, meet Teddy.',\n       '\\\\u00f0\\\\u0178\\\\u02dc\\\\u0160',\n       \"He says he'd be willing to help out.\", 'Yes!!!',\n       'We still need to figure out that flag. Do you know anyone who could help?',\n       \"Hmm. Let's see...\",\n       'Actually, I went to school with somebody who LOVES old flags.',\n       \"Why don't you go talk to her? I'll let her know you're coming.\",\n       'Hey, nice dog! What breed is he?', \"Actually, he's a badger.\",\n       \"Oh, cool! I've never seen a badger in real life.\",\n       \"You've got a million flags here!\", \"Yep. I'm a vexillophile!\",\n       \"What's a vexillophile? \",\n       'It just means flag expert. How can I help?',\n       \"I'm investigating this flag.\", 'Can you take a look?',\n       \"Hey, I've seen that symbol before! Check it out!\",\n       '\\\\Ecology flag, by Ron Cobb.\\\\', \"It's an ecology flag!\",\n       'Do you know what this flag was used for?', \"I'm not sure.\",\n       \"If I were you, I'd go to the library and do some digging.\",\n       'Good idea. Thanks!', 'Welcome back, Dear! How can I help you?',\n       'I need to learn more about this flag!',\n       'It has something to do with ecology.',\n       'Hmm... those stripes remind me of the American flag.',\n       'Your flag must have been part of a national movement!',\n       \"Go check the microfiche. Maybe you'll find something!\",\n       \"Hey! That's Governor Nelson in front of our flag!\",\n       'I found the flag! Governor Nelson used it on the first Earth Day!',\n       'Wow! You figured it out!',\n       'Now I just need some old photos, like last time.',\n       'The boss is gonna love it!', 'You could try the archives.',\n       'Though the archivist might be too busy to help...',\n       'Okay. Thanks!', 'What are you doing here?',\n       \"We're looking for some photos.\", \"It's for the flag display!\",\n       'Wait a minute...',\n       \"YOU'RE the new history detective everybody's talking about?\",\n       \"Teddy's helping too.\", 'What kind of photos do you need?',\n       'Something to do with ecology and Wisconsin.',\n       \"Here's a call number for the Stacks. Go find some photos.\",\n       'Look at all those activists!', 'This is perfect for the exhibit.',\n       'I should go to the Capitol and tell Mrs. M!', \"It's locked!\",\n       \"You haven't seen any badgers around here, have you?\",\n       'Badgers? No.', 'Okay. Thanks anyway.',\n       \"Jolie! I was hoping you'd stop by. Any news on the flag artifact?\",\n       \"I haven't quite figured it out just yet...\",\n       \"Well, get on it. I'm counting on you to figure this out!\",\n       'Nice seeing you, Jolie!', \"It's such a nice fall day.\",\n       'I love these photos of me and Teddy.', 'Hey, this is Youmans!',\n       \"And look! She's wearing the shirt!\",\n       'I should go to the Capitol and tell everyone!',\n       \"Why don't you go talk to the boss?\", \"She's right outside.\",\n       'My friend is a flag expert.',\n       'She should be able to help you out.',\n       'There are some old newspapers loaded up in the microfiche.',\n       'The Stacks are right outside the door. Go find some photos!',\n       \"I don't have time for this, Gramps.\", 'Teddy is still missing!',\n       \"Let's follow those scratch marks!\",\n       \"I can't go with you. I need to take the artifact upstairs.\",\n       \"It's okay, Gramps. I'll go by myself.\",\n       'You stole Teddy! How could you?!', \"No he hasn't!\",\n       \"Yes, he has. I've seen him eating homework and important papers, too.\",\n       'Come on, Teddy.', \"Let's go find Gramps!\",\n       'I think I can help with your animal problem.',\n       \"Ha! I don't need your help.\",\n       \"Fine. Then I guess you don't want a real, live badger for the exhibit.\",\n       \"Oh, trust me. He'll make time.\",\n       'Head back to the museum. Your gramps is waiting for you.',\n       \"I think it's a flag! Pretty spiffy, eh?\",\n       \"Great Scott, you're right!\",\n       \"Jo! I can't go with you. I need to take the artifact upstairs.\",\n       '\\\\u00f0\\\\u0178\\\\u02dc\\\\u00ad',\n       '\\\\u00e2\\\\u009d\\\\u00a4\\\\u00ef\\\\u00b8\\\\u008f', 'GRRRRRRR',\n       'GAH! And what is THAT doing out of its cage?!',\n       '\\\\u00f0\\\\u0178\\\\u02dc\\\\u0090',\n       'Teddy! Did you really eat his lunch?',\n       \"Did you steal Gramps's paperwork too?!\", 'And my homework?!?!',\n       'See?!', \"That thing's a monster!\", \"I don't have time for this.\",\n       'YEAH!', 'Wait- me?',\n       \"You can't just steal Jolie's pet. Don't you know badgers are protected animals?\",\n       'Besides, he looks friendly to me.', 'Wha?!',\n       '\\\\u00f0\\\\u0178\\\\u02dc\\\\u009d', \"Teddy! I'm sure glad to see you.\",\n       'Gadzooks! Poor critter.', 'Aha! Good catch, Jo.',\n       'Not sure. Do I look like a deer expert to you?',\n       'Ugh. I have to head over there and check out the animals.',\n       'FINE. That possum better not scratch my leather seats...',\n       \"He's a badger!\", '\\\\u00f0\\\\u0178\\\\u00a7\\\\u02dc',\n       'Yoga does sound nice.', \"But cranes can't do yoga, Teddy!\",\n       '\\\\u00f0\\\\u0178\\\\u008d\\\\u00a9', \"Cranes don't eat donuts!\",\n       'Besides, you just ate my last snack.',\n       \"Gah. I can't believe this.\", \"I'm a historian, not a zookeeper!\",\n       'And this place is dirty, and itchy, and-', 'I love it!',\n       \"Of course you do. You've got a rodent following you around.\",\n       \"Actually, badgers aren't rodents-\", 'Whatever.',\n       'Great. Just great. Could this day get any worse?!',\n       \"Yes!!! I'm saved!\", 'A real, live ferret!', \"He's. A. Badger.\",\n       'And we still need to figure out that flag!',\n       \"Fine, fine. Let's see...\", 'A vexy-wha?',\n       'Ooh... \\\\Ecology flag, by Ron Cobb.\\\\',\n       'The boss is gonna love it!!!',\n       \"You again! Don't let him hurt me!\",\n       '\\\\u00f0\\\\u0178\\\\u2122\\\\u201e',\n       \"Actually, we're just here for some photos.\", 'Guess so!', 'YOU?!',\n       \"Just please, don't let your badger eat them!\",\n       'There should be some info about that symbol in my book.',\n       'Yeah. Thanks anyway.',\n       \"I'll be in the collection room. Come find me when you're ready to check out the artifact.\",\n       'Good luck!', 'Better check back later.', 'What?!',\n       'Can I ride with you?',\n       \"Don't worry, he won't! (And he's a badger, by the way.)\",\n       'Ugh... I think that lynx is looking at me funny.',\n       \"Don't worry, Teddy won't eat your lunch anymore!\",\n       \"We're just looking for photos for the flag display.\",\n       \"But I hear the museum's got one on the loose!\",\n       'I should check out that pair of glasses.',\n       'I should ask the librarian where to go next.',\n       \"Check out the archives. They've got tons of old photos!\",\n       \"Come on, kid. You're slowing me down.\", 'What is it, Teddy?',\n       'Oh no... they got sick from polluted water?', 'Poor foxes!',\n       'Jolie! Where have you been?', 'The exhibit opens tomorrow.',\n       'Wells got in trouble for littering at the Wildlife Center.',\n       'Thanks!', \"Are you going home now? Tomorrow's the big day!\",\n       'Huh?', 'He got a park named after him? Cool!']\n\nlevel_groups = [\"0-4\", \"5-12\", \"13-22\"]\n\nevent_comb=['notebook_clickclose',\n 'observation_clickbasic',\n 'navigate_clickundefined',\n 'notebook_clicknext',\n 'map_clickbasic',\n 'checkpointbasic',\n 'map_clickclose',\n 'person_clickbasic',\n 'notebook_clickbasic',\n 'cutscene_clickbasic',\n 'object_clickbasic',\n 'notification_clickbasic',\n 'object_clickclose',\n 'map_hoverbasic',\n 'notebook_clickopen',\n 'notebook_clickprev',\n 'map_clickundefined',\n 'object_hoverundefined',\n 'object_hoverbasic']\n\n\nbreak_point=[         49,          99,         149,         199,\n               249,         299,         349,         399,         449,\n               499,         549,         599,         649,         699,\n               749,         799,         849,         899,         949,\n               999,        1049,        1099,        1149,        1199,\n              1249,        1299,        1349,        1399,        1449,\n              1499,        1549,        1599,        1649,        1699,\n              1749,        1799,        1849,        1899,        1949,\n              1999]","metadata":{"execution":{"iopub.status.busy":"2023-06-26T17:55:01.195915Z","iopub.execute_input":"2023-06-26T17:55:01.196849Z","iopub.status.idle":"2023-06-26T17:55:01.279292Z","shell.execute_reply.started":"2023-06-26T17:55:01.196811Z","shell.execute_reply":"2023-06-26T17:55:01.277955Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def time_feature(train):\n#     train[\"year\"] = train[\"session_id\"].apply(lambda x: int(str(x)[:2])).astype(np.uint8)\n    train[\"month\"] = train[\"session_id\"].apply(lambda x: int(str(x)[2:4])+1).astype(np.uint8)\n    train[\"day\"] = train[\"session_id\"].apply(lambda x: int(str(x)[4:6])).astype(np.uint8)\n    train[\"hour\"] = train[\"session_id\"].apply(lambda x: int(str(x)[6:8])).astype(np.uint8)\n    train[\"minute\"] = train[\"session_id\"].apply(lambda x: int(str(x)[8:10])).astype(np.uint8)\n    train[\"second\"] = train[\"session_id\"].apply(lambda x: int(str(x)[10:12])).astype(np.uint8)\n    return train\ndef instance_feature(data,text1,text2):\n    time_diffs = []\n    object_click_counts = []\n    hover_duration_sums = []\n    room_coor_x_first = []\n    room_coor_y_first = []\n\n    grouped = data.groupby('session_id')\n    # Iterate over each session\n    for session_id, session_data in grouped:\n        # Find the indices of the first occurrences of the two texts\n        index1 = session_data['fqid'].eq(text1).idxmax()\n        index2 = session_data['text'].eq(text2).idxmax()+1\n\n        session_data=session_data.loc[index1:index2]\n\n        object_click_count = session_data[session_data['event_name']=='object_click']\n        object_click_counts.append(object_click_count.shape[0])    \n\n\n        room_coor_x = object_click_count['room_coor_x'].values\n        room_coor_y = object_click_count['room_coor_y'].values\n        \n\n        if(len(room_coor_x)):\n            room_coor_x_first.append(room_coor_x[0])  \n            room_coor_y_first.append(room_coor_y[0]) \n            \n        else:\n            room_coor_x_first.append(-1001)  \n            room_coor_y_first.append(-1001) \n\n            \n    # Create a DataFrame from the extracted features\n    result = pd.DataFrame({\n        'session_id': grouped.groups.keys(),\n\n        f'{text1}_object_click_counts_instance': object_click_counts,\n        f'{text1}_room_coor_x_first_instance': room_coor_x_first,\n        f'{text1}_room_coor_y_first_instance': room_coor_y_first,\n    })\n    return result\n\ndef level_group_features(train,grp):\n    result1=None\n    if(grp=='0-4'):\n        result1=instance_feature(train,'report',\"That settles it.\")\n        result2=instance_feature(train,'tunic',\"This looks like a clue!\")\n        result3=instance_feature(train,'plaque',\"The slip is from 1916 but the team didn't start until 1974!\")\n\n        result1[result2.columns]=result2\n        result1[result3.columns]=result3\n    if(grp=='5-12'):\n        result1=instance_feature(train,'businesscards',\"This place was around in 1916! I can start there!\")\n        result2=instance_feature(train,'logbook',\"It's a match!\")\n        result3=instance_feature(train,'reader',\"Youmans was a suffragist!\")\n        result4=instance_feature(train,'journals',\"Hey, this is Youmans!\")\n\n        result1[result2.columns]=result2\n        result1[result3.columns]=result3\n        result1[result4.columns]=result4\n    if(grp=='13-22'):\n        result1=instance_feature(train,'directory',\"The archivist must've taken Teddy!\")\n        result2=instance_feature(train,'tracks',\"That hoofprint doesn't match the flag!\")\n        result3=instance_feature(train,'colorbook',\"It's an ecology flag!\")\n        result4=instance_feature(train,'reader_flag',\"Hey! That's Governor Nelson in front of our flag!\")\n        result5=instance_feature(train,'journals_flag',\"Look at all those activists!\")\n\n        result1[result2.columns]=result2\n        result1[result3.columns]=result3\n        result1[result4.columns]=result4\n        result1[result5.columns]=result5\n\n    return pl.DataFrame(result1) \n    \ndef feature_engineer(x, grp,cols, use_extra):\n    aggs = [\n        pl.col(\"index\").count().alias(f\"session_number\"),\n\n        #######################################  CATEGORICAL_AGGREGATIONS ###################################################\n        *[pl.col(c).drop_nulls().n_unique().alias(f\"{c}_unique\") for c in CATS],\n\n        #######################################  NUMERICAL_AGGREGATIONS #####################################################\n        \n        *[pl.col(c).std().alias(f\"{c}_std\") for c in NUMS],\n        *[pl.col(c).mean().alias(f\"{c}_mean\") for c in NUMS],\n        *[pl.col(c).min().alias(f\"{c}_min\") for c in NUMS],\n        *[pl.col(c).max().alias(f\"{c}_max\") for c in NUMS],\n        *[pl.col(c).sum().alias(f\"{c}_sum\") for c in NUMS],\n\n        ####################################### COUNTING_AGGREGATIONS #######################################################\n        \n        *[pl.col(\"fqid\").filter(pl.col(\"fqid\") == c).count().alias(f\"{c}_fqid_counts\")\n          for c in fqid[grp]],\n        *[pl.col(\"fqid\").filter((pl.col(\"fqid\") == c)&(pl.col(\"event_name\") != 'navigate_click')).count().alias(f\"{c}_fqid_withnonavigate_counts\")\n          for c in fqid[grp]],\n        \n        \n        *[pl.col(\"text_fqid\").filter(pl.col(\"text_fqid\") == c).count().alias(f\"{c}_text_fqid_counts\") for\n          c in text_fqid[grp]],        \n        \n        \n        \n        *[pl.col(\"event_comb\").filter(pl.col(\"event_comb\") == c).count().alias(f\"{c}_event_comb_counts\")\n          for c in event_comb],\n        \n        *[pl.col(\"event_name\").filter(pl.col(\"event_name\") == c).count().alias(f\"{c}_event_name_counts\")\n          for c in event_name],\n\n\n        \n        *[pl.col(\"level\").filter(pl.col(\"level\") == c).count().alias(f\"{c}_level_count\") for c in level[grp]],\n        \n        \n        *[pl.col(\"text\").filter(pl.col(\"text\") == c).count().alias(f\"{c}_text_count\") for c in text[grp]],\n    \n        \n        \n        *[pl.col(\"elapsed_time_diff\").filter(pl.col(\"break_point\") == c).sum().alias(f\"{c}_ET_break_point_sum\") for c in break_point],\n        \n        *[pl.col(\"fqid\").filter(pl.col(\"break_point\") == c).n_unique().alias(f\"{c}_fqid_break_point_unique\") for c in break_point],\n        ####################################### COMBINATION_FEATURES #######################################################\n        \n        #################################################### TEXT ##########################################################\n        *[pl.col(\"elapsed_time_diff\").filter(pl.col(\"text\") == c).sum().alias(f\"{c}_ET_sum_\") for\n          c in text[grp]],\n        *[pl.col(\"elapsed_time_diff\").filter(pl.col(\"text\") == c).first().alias(f\"{c}_ET_first_\") for\n          c in text[grp]],   \n#         ################################################### FQID############################################################\n        \n        *[pl.col(\"elapsed_time_diff\").filter(pl.col(\"fqid\") == c).sum().alias(f\"{c}_ET_sum_\") for\n          c in fqid[grp]],\n        \n#         *[pl.col(\"elapsed_time_diff\").filter((pl.col(\"fqid\") == c)&(pl.col(\"event_name\") != 'navigate_click')).sum().alias(f\"{c}_no_navigate_ET_sum_\") for\n#           c in fqid[grp]],\n        \n        *[pl.col(\"elapsed_time_diff\").filter(pl.col(\"fqid\") == c).first().alias(f\"{c}_ET_first_\") for\n          c in fqid[grp]],\n#          #######################################  TEXT_FQID  ###############################################################\n\n        *[pl.col(\"elapsed_time_diff\").filter(pl.col(\"text_fqid\") == c).sum().alias(f\"{c}_ET_sum_\") for\n          c in text_fqid[grp]],\n        *[pl.col(\"elapsed_time_diff\").filter(pl.col(\"text_fqid\") == c).first().alias(f\"{c}_ET_first_\") for\n          c in text_fqid[grp]],        \n        \n#         ############################################# ROOM_FQID  ##########################################################\n\n        *[pl.col(\"elapsed_time_diff\").filter(pl.col(\"room_fqid\") == c).sum().alias(f\"{c}_ET_sum_\") for\n          c in room_fqid[grp]],\n        *[pl.col(\"elapsed_time_diff\").filter(pl.col(\"room_fqid\") == c).first().alias(f\"{c}_ET_first_\") for\n          c in room_fqid[grp]],  \n        \n        ############################################ EVENT_NAME  #########################################################\n\n#         *[pl.col(\"elapsed_time_diff\").filter(pl.col(\"event_name\") == c).sum().alias(f\"{c}_ET_sum_{feature_suffix}\") for\n#           c in event_name_feature],\n\n        ############################################ INDEX_FEATURE  ######################################################\n        \n        *[(pl.col(\"elapsed_time\").filter(pl.col(\"fqid\") == c).min()//1000).alias(f\"{c}_index_first_\") for\n          c in fqid[grp]],\n        *[(pl.col(\"elapsed_time\").filter(pl.col(\"text\") == c).min()//1000).alias(f\"{c}_index_first_\") for\n          c in text[grp]],   \n#         *[pl.col(\"break_point\").filter(pl.col(\"text\") == c).first().alias(f\"{c}_index_first_\") for\n#           c in text[grp]],\n        *[pl.col(\"break_point\").filter(pl.col(\"fqid\") == c).first().alias(f\"{c}_break_point_first_\") for\n          c in fqid[grp]],\n\n        ############################################# HOVER_DURATION ######################################################\n        \n        *[pl.col(\"hover_duration\").filter((pl.col(\"hover_duration\").is_not_null()) & (pl.col(\"fqid\") == c)).sum().alias(f\"{c}_HD_sum_\") for\n          c in fqid[grp]],\n        *[pl.col(\"hover_duration\").filter((pl.col(\"hover_duration\").is_not_null()) & (pl.col(\"event_name\") == c)).sum().alias(f\"{c}_HD_sum_\") for\n          c in event_name],        \n        \n        ############################################ TWO_COMBINATION_FEATURES #############################################\n        *[pl.col(\"break_point_1\").filter((pl.col(\"event_comb\") == c) & (pl.col('room_fqid') == d)).count().alias(f\"{c}{d}_event_comb_room_fqid_count_\") for c in event_comb for d in room_fqid[grp]],\n        \n        ############################################ TWO_COMBINATION_FEATURES #############################################\n        \n    ]\n\n\n    df = x.groupby(['session_id'], maintain_order=True).agg(aggs).sort(\"session_id\")\n\n    tmp=level_group_features(x.to_pandas(),grp)\n  \n    df = df.join(tmp, on=\"session_id\", how='left')\n\n    if use_extra:\n        if grp == '0-4':\n#                 print(1)\n            aggs = [\n                (pl.col(\"elapsed_time\").filter((pl.col(\"text\")==\"That settles it.\")|(pl.col(\"fqid\")==\"report\"))).apply(lambda s: s.max() - s.min() if s.len() > 0 else 0).alias(\"report_read_duration\"),\n                (pl.col(\"elapsed_time\").filter((pl.col(\"text\")==\"This looks like a clue!\")|(pl.col(\"fqid\")==\"tunic\"))).apply(lambda s: s.max() - s.min() if s.len() > 0 else 0).alias(\"tunic_duration\"),\n                (pl.col(\"elapsed_time\").filter((pl.col(\"text\")==\"The slip is from 1916 but the team didn't start until 1974!\")|(pl.col(\"fqid\")==\"plaque\"))).apply(lambda s: s.max() - s.min() if s.len() > 0 else 0).alias(\"plaque_duration\"),      \n                (pl.col(\"elapsed_time\").filter((pl.col(\"text\")==\"Now where did I put my notebook?\")|(pl.col(\"text\")==\"Found it!\"))).apply(lambda s: s.max() - s.min() if s.len() > 0 else 0).alias(\"notebook_find_duration\"),   \n            ]\n            tmp = x.groupby([\"session_id\"], maintain_order=True).agg(aggs).sort(\"session_id\")\n            df = df.join(tmp, on=\"session_id\", how='left')\n        if grp == '5-12':\n        \n            aggs = [\n\n                ######################################################################\n                pl.col(\"elapsed_time\").filter(\n                    ((pl.col(\"event_name\") == 'navigate_click') & (pl.col(\"fqid\") == 'reader')) | (\n                                pl.col(\"fqid\") == \"reader.paper2.bingo\")).apply(lambda s: s.max() - s.min() if s.len() > 0 else 0).alias(\n                    \"reader_bingo_duration\"),\n                \n                pl.col(\"index\").filter(((pl.col(\"event_name\") == 'navigate_click') & (pl.col(\"fqid\") == 'reader')) | (\n                            pl.col(\"fqid\") == \"reader.paper2.bingo\")).apply(lambda s: s.max() - s.min() if s.len() > 0 else 0).alias(\n                    \"reader_bingo_indexCount\"),\n                \n                pl.col(\"elapsed_time\").filter(\n                    ((pl.col(\"event_name\") == 'navigate_click') & (pl.col(\"fqid\") == 'journals')) | (\n                                pl.col(\"fqid\") == \"journals.pic_2.bingo\")).apply(lambda s: s.max() - s.min() if s.len() > 0 else 0).alias(\n                    \"journals_bingo_duration\"),\n                \n                pl.col(\"index\").filter(((pl.col(\"event_name\") == 'navigate_click') & (pl.col(\"fqid\") == 'journals')) | (\n                            pl.col(\"fqid\") == \"journals.pic_2.bingo\")).apply(lambda s: s.max() - s.min() if s.len() > 0 else 0).alias(\n                    \"journals_bingo_indexCount\"),\n            ]\n            tmp = x.groupby([\"session_id\"], maintain_order=True).agg(aggs).sort(\"session_id\")\n            df = df.join(tmp, on=\"session_id\", how='left')\n\n        if grp == '13-22':\n            aggs = [                \n                pl.col(\"elapsed_time\").filter((pl.col(\"text\")==\"It's an ecology flag!\")|(pl.col(\"fqid\")==\"colorbook\")).apply(lambda s: s.max() - s.min() if s.len() > 0 else 0).alias(\"colorbook_duration\"),\n                pl.col(\"elapsed_time\").filter((pl.col(\"text\")==\"The archivist must've taken Teddy!\")|(pl.col(\"fqid\")==\"directory\")).apply(lambda s: s.max() - s.min() if s.len() > 0 else 0).alias(\"directory_duration\"),\n                pl.col(\"elapsed_time\").filter((pl.col(\"text\")==\"That hoofprint doesn't match the flag!\")|(pl.col(\"fqid\")==\"tracks\")).apply(lambda s: s.max() - s.min() if s.len() > 0 else 0).alias(\"tracks_duration\"),\n                pl.col(\"elapsed_time\").filter((pl.col(\"text\")==\"Teddy, here I come!\")|(pl.col(\"text\")==\"I wonder whose glasses these are.\")).apply(lambda s: s.max() - s.min() if s.len() > 0 else 0).alias(\"glass_find_duration\"),\n                pl.col(\"elapsed_time\").filter((pl.col(\"text\")==\"The archivist must've taken Teddy!\")|(pl.col(\"text\")==\"Yes! It's the key for Teddy's cage!\")).apply(\n                    lambda s: s.max() - s.min() if s.len() > 0 else 0).alias(\"key_duration\"),\n\n                \n                pl.col(\"elapsed_time\").filter(\n                    ((pl.col(\"event_name\") == 'navigate_click') & (pl.col(\"fqid\") == 'reader_flag')) | (\n                                pl.col(\"fqid\") == \"tunic.library.microfiche.reader_flag.paper2.bingo\")).apply(\n                    lambda s: s.max() - s.min() if s.len() > 0 else 0).alias(\"reader_flag_duration\"),\n                pl.col(\"index\").filter(\n                    ((pl.col(\"event_name\") == 'navigate_click') & (pl.col(\"fqid\") == 'reader_flag')) | (\n                                pl.col(\"fqid\") == \"tunic.library.microfiche.reader_flag.paper2.bingo\")).apply(\n                    lambda s: s.max() - s.min() if s.len() > 0 else 0).alias(\"reader_flag_indexCount\"),\n                \n                pl.col(\"elapsed_time\").filter(\n                    ((pl.col(\"event_name\") == 'navigate_click') & (pl.col(\"fqid\") == 'journals_flag')) | (\n                                pl.col(\"fqid\") == \"journals_flag.pic_0.bingo\")).apply(\n                    lambda s: s.max() - s.min() if s.len() > 0 else 0).alias(\"journalsFlag_bingo_duration\"),\n                pl.col(\"index\").filter(\n                    ((pl.col(\"event_name\") == 'navigate_click') & (pl.col(\"fqid\") == 'journals_flag')) | (\n                                pl.col(\"fqid\") == \"journals_flag.pic_0.bingo\")).apply(\n                    lambda s: s.max() - s.min() if s.len() > 0 else 0).alias(\"journalsFlag_bingo_indexCount\")\n            ]\n            \n            tmp = x.groupby([\"session_id\"], maintain_order=True).agg(aggs).sort(\"session_id\")\n            df = df.join(tmp, on=\"session_id\", how='left')\n\n\n    df=df.to_pandas()\n    df=time_feature(df)\n#     for col in cols:\n#         if col not in df.columns:\n#             df[col]=0\n            \n    return df","metadata":{"execution":{"iopub.status.busy":"2023-06-26T17:55:01.404697Z","iopub.execute_input":"2023-06-26T17:55:01.405156Z","iopub.status.idle":"2023-06-26T17:55:01.484369Z","shell.execute_reply.started":"2023-06-26T17:55:01.405116Z","shell.execute_reply":"2023-06-26T17:55:01.482954Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Load Models","metadata":{}},{"cell_type":"code","source":"models=dict()\n\ndef level_grp(t):\n    if(t<=3): return '0-4'\n    if(t>=4 and t<=13): return '5-12'\n    else: return '13-22'\n    \nfor t in range(1,19):\n    for fold in range(0,5):\n        with open(f'{CFG.MODEL_PATH}/FOLD_{fold}/{level_grp(t)}_{t}.pickle', 'rb') as f:\n            clf = pickle.load(f)  \n        models[f'{t}_{fold}']=clf","metadata":{"execution":{"iopub.status.busy":"2023-06-26T17:55:01.946519Z","iopub.execute_input":"2023-06-26T17:55:01.946949Z","iopub.status.idle":"2023-06-26T17:55:06.082818Z","shell.execute_reply.started":"2023-06-26T17:55:01.946918Z","shell.execute_reply":"2023-06-26T17:55:06.081444Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Load Columns","metadata":{}},{"cell_type":"code","source":"topcols04=['chap1_finale_c_ET_sum_',\n 'tunic.capitol_0.hall_ET_sum_',\n 'chap1_finale_c_ET_first_',\n 'object_clickbasic_event_comb_counts',\n \"The slip is from 1916 but the team didn't start until 1974!_ET_first_\",\n 'object_click_event_name_counts',\n 'report_ET_first_',\n 'elapsed_time_diff_max',\n \"Why don't you head to the Basketball Center and rustle up some clues?_ET_first_\",\n 'tobasement_ET_sum_',\n \"Why don't you head to the Basketball Center and rustle up some clues?_ET_sum_\",\n 'object_clickbasictunic.kohlcenter.halloffame_event_comb_room_fqid_count_',\n \"The slip is from 1916 but the team didn't start until 1974!_ET_sum_\",\n 'undefined_ET_sum_',\n \"Hey Jo, let's take a look at the shirt!_text_count\",\n 'notebook_clickclosetunic.historicalsociety.collection_event_comb_room_fqid_count_',\n 'report_ET_sum_',\n 'navigate_clickundefinedtunic.capitol_0.hall_event_comb_room_fqid_count_',\n 'plaque.face.date_HD_sum_',\n 'screen_coor_x_sum',\n 'directory_ET_sum_',\n 'session_number',\n 'Ooh, I like clues!_ET_first_',\n 'Gramps is the best historian ever!_ET_first_',\n 'tomap_ET_first_',\n 'chap1_finale_fqid_counts',\n \"Leopold, why don't you help me set up in the Capitol?_ET_first_\",\n \"Leopold, why don't you help me set up in the Capitol?_ET_sum_\",\n \"I'll be at the Capitol. Let me know if you find anything!_ET_first_\",\n 'plaque_fqid_counts',\n 'notebook_clickbasic_event_comb_counts',\n \"I'll be at the Capitol. Let me know if you find anything!_ET_sum_\",\n 'toentry_ET_first_',\n 'object_hover_HD_sum_',\n 'tunic.historicalsociety.collection.gramps.found_ET_sum_',\n 'Gramps is in trouble for losing papers?_ET_first_',\n 'Could be. But we need evidence!_ET_sum_',\n 'plaque_ET_sum_',\n '3_level_count',\n 'We need to talk about that missing paperwork._ET_sum_',\n 'Gramps is the best historian ever!_ET_sum_',\n 'second',\n 'Go ahead, take a peek at the shirt!_ET_first_',\n \"It's a women's basketball jersey!_ET_first_\",\n 'hover_duration_sum',\n 'Go ahead, take a peek at the shirt!_ET_sum_',\n 'navigate_clickundefinedtunic.historicalsociety.collection_event_comb_room_fqid_count_',\n 'notebook_clickopentunic.historicalsociety.collection_event_comb_room_fqid_count_',\n 'report_room_coor_x_first_instance','report_room_coor_y_first_instance',\n 'tunic_object_click_counts_instance', 'plaque_room_coor_x_first_instance', \n 'plaque_room_coor_y_first_instance','tunic_room_coor_x_first_instance', \n 'tunic_room_coor_y_first_instance', 'report_object_click_counts_instance', \n 'plaque_object_click_counts_instance','notebook_find_duration', 'plaque_duration',\n 'tunic_duration', 'report_read_duration', 'hover_duration_mean', 'hover_duration_max',\n 'hover_duration_std', 'hover_duration_min']\n\n\ntopcols512=['session_number',\n 'object_click_event_name_counts',\n 'businesscards.card_1.next_HD_sum_',\n '11_level_count',\n 'businesscards.card_0.next_HD_sum_',\n 'logbook.page.bingo_ET_sum_',\n 'object_clickbasic_event_comb_counts',\n '\\\\Taxidermy: the art of preparing, stuffing, and mounting the skins of animals.\\\\_ET_sum_',\n '\\\\Taxidermy: the art of preparing, stuffing, and mounting the skins of animals.\\\\_ET_first_',\n 'journals.pic_1.next_HD_sum_',\n 'reader.paper1.next_ET_first_',\n 'journals.pic_0.next_HD_sum_',\n 'undefined_text_count',\n 'hover_duration_mean',\n 'journals_bingo_duration',\n 'Your gramps is awesome! Always full of stories._ET_first_',\n 'chap2_finale_c_index_first_',\n 'journals.pic_2.next_ET_sum_',\n 'tostacks_ET_sum_',\n \"Check out our microfiche. It's right through that door._ET_first_\",\n 'journals.pic_1.next_ET_sum_',\n \"Here's a call number to find more info in the Stacks._ET_first_\",\n 'reader.paper0.next_HD_sum_',\n 'reader.paper1.next_HD_sum_',\n 'tunic.historicalsociety.stacks_ET_sum_',\n 'reader_bingo_duration',\n 'journals_ET_sum_',\n 'reader_bingo_indexCount',\n 'Nope. But Youmans and other suffragists worked hard to change that._ET_first_',\n \"I've got a stack of business cards from my favorite cleaners._ET_sum_\",\n 'page_std',\n \"Check out our microfiche. It's right through that door._ET_sum_\",\n 'businesscards.card_1.next_ET_first_',\n 'businesscards.card_0.next_ET_first_',\n 'hover_duration_std',\n 'She led marches and helped women get the right to vote!_ET_first_',\n 'room_coor_y_std',\n 'journals.hub.topics_ET_sum_',\n 'Thanks to them, Wisconsin was the first state to approve votes for women!_ET_first_',\n 'logbook_room_coor_x_first_instance', 'logbook_object_click_counts_instance',\n 'reader_room_coor_y_first_instance', 'journals_object_click_counts_instance', \n 'businesscards_object_click_counts_instance', 'logbook_room_coor_y_first_instance',\n 'reader_object_click_counts_instance', 'journals_room_coor_y_first_instance', \n 'businesscards_room_coor_y_first_instance', 'businesscards_room_coor_x_first_instance',\n 'reader_room_coor_x_first_instance', 'journals_room_coor_x_first_instance',\n 'hover_duration_sum', 'hover_duration_max', 'hover_duration_min']","metadata":{"execution":{"iopub.status.busy":"2023-06-26T17:55:06.086045Z","iopub.execute_input":"2023-06-26T17:55:06.086501Z","iopub.status.idle":"2023-06-26T17:55:06.103189Z","shell.execute_reply.started":"2023-06-26T17:55:06.086464Z","shell.execute_reply":"2023-06-26T17:55:06.101661Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"num_cols=dict()\ncols=dict()\n\n#-------------------------------------------------------------------------------\n\n# with open(f'{CFG.TRANSFORMS_PATH}/num_cols_0-4_1.pickle', 'rb') as f:\n#     num_cols['0-4']=pickle.load(f)\n    \nwith open(f'{CFG.TRANSFORMS_PATH}/cols_0-4_1.pickle', 'rb') as f:\n    cols['0-4']=pickle.load(f)\n    \n#-------------------------------------------------------------------------------\n\n# with open(f'{CFG.TRANSFORMS_PATH}/num_cols_5-12_4.pickle', 'rb') as f:\n#     num_cols['5-12']=pickle.load(f)\n    \nwith open(f'{CFG.TRANSFORMS_PATH}/cols_5-12_4.pickle', 'rb') as f:\n    cols['5-12']=pickle.load(f)\n    \n#-------------------------------------------------------------------------------\n# with open(f'{CFG.TRANSFORMS_PATH}/num_cols_13-22_14.pickle', 'rb') as f:\n#      num_cols['13-22']=pickle.load(f)\n    \nwith open(f'{CFG.TRANSFORMS_PATH}/cols_13-22_14.pickle', 'rb') as f:\n    cols['13-22']=pickle.load(f)","metadata":{"execution":{"iopub.status.busy":"2023-06-26T17:55:06.105134Z","iopub.execute_input":"2023-06-26T17:55:06.105572Z","iopub.status.idle":"2023-06-26T17:55:06.134270Z","shell.execute_reply.started":"2023-06-26T17:55:06.105543Z","shell.execute_reply":"2023-06-26T17:55:06.133228Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def func(t):\n    if t<=3: \n        grp = '0-4' \n    elif t<=13: \n        grp = '5-12'\n    elif t<=22: \n        grp = '13-22'\n    return grp\n\n\nque_cols=dict()\nfor t in range(1,19):\n    with open(f'{CFG.TRANSFORMS_PATH}/cols_{func(t)}_{t}.pickle', 'rb') as f:\n        que_cols[t]=pickle.load(f)","metadata":{"execution":{"iopub.status.busy":"2023-06-26T17:55:06.139593Z","iopub.execute_input":"2023-06-26T17:55:06.139998Z","iopub.status.idle":"2023-06-26T17:55:06.202827Z","shell.execute_reply.started":"2023-06-26T17:55:06.139970Z","shell.execute_reply":"2023-06-26T17:55:06.201525Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# IMPORT KAGGLE API\nimport jo_wilder_310\njo_wilder_310.make_env.__called__ = False\nenv = jo_wilder_310.make_env()\niter_test = env.iter_test()","metadata":{"execution":{"iopub.status.busy":"2023-06-26T17:55:06.204357Z","iopub.execute_input":"2023-06-26T17:55:06.205253Z","iopub.status.idle":"2023-06-26T17:55:06.234257Z","shell.execute_reply.started":"2023-06-26T17:55:06.205221Z","shell.execute_reply":"2023-06-26T17:55:06.232952Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"last_index=dict()\nre_last_index=dict()\n\n\n\n####reindexing the anomaly sessions######\ndef reindex(df,lv,sid):\n    df = df.with_row_count('row_nr')\n\n    reference_ind=0\n    if(lv!='0-4'):\n        reference_ind=df.filter(pl.col(\"row_nr\") == 0).to_pandas()['index'].values[0]-last_index[sid]+re_last_index[sid]-1\n\n    last_index[sid]=df.filter(pl.col(\"row_nr\") == df.shape[0]-1).to_pandas()['index'].values[0]\n    \n    df=df.with_columns(    \n    (pl.col(\"index\") - pl.col(\"index\").shift(1)).fill_null(0)\n    .clip(1,30)\n    .over([\"session_id\"]).alias('index')\n    )\n    df=df.with_columns((pl.col('index').cumsum()+pl.lit(reference_ind)).alias('index'))\n    re_last_index[sid]=df.filter(pl.col(\"row_nr\") == df.shape[0]-1).to_pandas()['index'].values[0]\n    \n    return df.to_pandas()\n\n\n\n\n#########sort the anomaly sessions##################\ndef df_sort(df):\n\n    sid=df['session_id'].values[0]\n    max_index=df['index'].max()\n    min_index=df['index'].min()\n\n    max_elapsed_time=df['elapsed_time'].max()\n    min_elapsed_time=df['elapsed_time'].min()    \n\n    cond1=df[df['index']==max_index]['elapsed_time'].values[0]-df[df['index']==min_index]['elapsed_time'].values[0]\n    cond2=df[df['elapsed_time']==max_elapsed_time]['index'].values[0]-df[df['elapsed_time']==min_elapsed_time]['index'].values[0]\n\n    re_index_cond1=0\n    if((cond1<0)|(cond2<0)):\n        df['ET_seconds']=df['elapsed_time']//1250\n        df=df.sort_values(by=['ET_seconds','index']).reset_index(drop=True)\n        re_index_cond1=1\n    else:\n        df=df.sort_values(by=['index']).reset_index(drop=True)\n    \n    try: \n        re_index_cond2=((df['level_group'].values[0]=='0-4')&(df['index'].values[0]>0))\n        if((re_index_cond1==1)|(re_index_cond2==True)|(sid in last_index.keys())):\n            df=reindex(pl.DataFrame(df),df['level_group'].values[0],sid)\n    except:\n        pass\n    return df","metadata":{"execution":{"iopub.status.busy":"2023-06-26T17:55:07.088507Z","iopub.execute_input":"2023-06-26T17:55:07.089300Z","iopub.status.idle":"2023-06-26T17:55:07.106946Z","shell.execute_reply.started":"2023-06-26T17:55:07.089266Z","shell.execute_reply":"2023-06-26T17:55:07.105796Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"limits = {'0-4':(1,4), '5-12':(4,14), '13-22':(14,19)}\nbest_threshold=THRESHOLD\n\noof = dict()\n\n\nlevel_group_1_questioning_time=dict()\nlevel_group_2_questioning_time=dict()\n\ndf_topcols04=dict()\ndf_topcols512=dict()\n\n\nfor (test, sample_submission) in iter_test:\n    # FEATURE ENGINEER TEST DATA\n#     st=time.time()\n    \n    grp = test.level_group.values[0]\n    session = test.session_id.values[0]\n\n    a,b=limits[grp]\n    \n    try:\n        test=df_sort(test)\n    except:\n        test=test.sort_values(by=['index']).reset_index(drop=True)\n    \n \n    df = (pl.from_pandas(test)\n          .drop([\"fullscreen\", \"hq\", \"music\"])\n          .with_columns(columns))\n    \n    df=df.sort('index')\n    \n    df=df.with_columns((df['index'].cut(bins=[i for i in range(-1,2500,30)], maintain_order=True)['break_point']-pl.lit(29)).clip(0,4000).alias('break_point_1'))\n    df=df.with_columns(pl.col('break_point_1').cast(pl.Int32,strict=False))\n\n    df=df.with_columns(\n        df['index'].cut(bins=[i for i in range(-1,2500,50)], maintain_order=True)['break_point'].clip(0,4000).alias('break_point')\n    )\n    df=df.with_columns(pl.col('break_point').cast(pl.Int32,strict=False))\n    \n    df = feature_engineer(df, grp,cols[grp], use_extra=True)\n    \n    \n    if(grp=='0-4'):\n        level_group_1_questioning_time[session]=test['elapsed_time'].max()\n        df_topcols04[session]=df[topcols04].astype('float32').values\n        \n    elif(grp=='5-12'):\n        level_group_2_questioning_time[session]=test['elapsed_time'].max()\n        df_topcols512[session]=df[topcols512].astype('float32').values\n        df['level_group_1_questioning_time']=level_group_1_questioning_time[session]\n        df[[x+'0-4' for x in topcols04]]=df_topcols04[session]\n            \n    elif(grp=='13-22'):\n        df['level_group_1_questioning_time']=level_group_1_questioning_time[session]\n        df['level_group_2_questioning_time']=test['elapsed_time'].min()-level_group_2_questioning_time[session]\n        df[[x+'0-4' for x in topcols04]]=df_topcols04[session]\n        df[[x+'5-12' for x in topcols512]]=df_topcols512[session]\n        \n        del df_topcols512[session],df_topcols04[session]\n        \n    \n#     display(df)\n#         \n    for t in range(a,b):   \n        \n        p=0\n#         print(t)\n        for q in range(1,t):\n            try:\n                df['q'+str(q)]=oof[f'{session}_{q}']\n            except:\n                df['q'+str(q)]=0.62\n \n        temp_df=df[que_cols[t]].astype('float32').values\n        for fold in range(0,5):\n            clf = models[f'{t}_{fold}']\n            p += clf.predict_proba(temp_df)[0,1]/5\n            \n        oof[f'{session}_{t}']=p\n        \n#         if( t in [2,18]): p=1\n#         print(p)\n        mask = sample_submission.session_id.str.contains(f'q{t}')\n        sample_submission.loc[mask,'correct'] = int( p > best_threshold ) \n\n#     print('time_to_predict_per_session',time.time()-st)\n    env.predict(sample_submission)","metadata":{"execution":{"iopub.status.busy":"2023-06-26T17:55:08.351174Z","iopub.execute_input":"2023-06-26T17:55:08.352029Z","iopub.status.idle":"2023-06-26T17:55:11.532512Z","shell.execute_reply.started":"2023-06-26T17:55:08.351989Z","shell.execute_reply":"2023-06-26T17:55:11.531296Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_submission","metadata":{"execution":{"iopub.status.busy":"2023-06-26T17:55:11.534658Z","iopub.execute_input":"2023-06-26T17:55:11.535002Z","iopub.status.idle":"2023-06-26T17:55:11.561424Z","shell.execute_reply.started":"2023-06-26T17:55:11.534973Z","shell.execute_reply":"2023-06-26T17:55:11.560497Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv('/kaggle/working/submission.csv')\nprint( df.shape )\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2023-06-26T17:55:11.562807Z","iopub.execute_input":"2023-06-26T17:55:11.563139Z","iopub.status.idle":"2023-06-26T17:55:11.578226Z","shell.execute_reply.started":"2023-06-26T17:55:11.563111Z","shell.execute_reply":"2023-06-26T17:55:11.577384Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_submission.info()","metadata":{"execution":{"iopub.status.busy":"2023-06-26T06:08:46.830108Z","iopub.execute_input":"2023-06-26T06:08:46.830734Z","iopub.status.idle":"2023-06-26T06:08:46.851053Z","shell.execute_reply.started":"2023-06-26T06:08:46.8307Z","shell.execute_reply":"2023-06-26T06:08:46.850186Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(sample_submission.correct.mean())","metadata":{"execution":{"iopub.status.busy":"2023-06-26T06:08:46.852318Z","iopub.execute_input":"2023-06-26T06:08:46.85285Z","iopub.status.idle":"2023-06-26T06:08:46.858643Z","shell.execute_reply.started":"2023-06-26T06:08:46.852812Z","shell.execute_reply":"2023-06-26T06:08:46.857713Z"},"trusted":true},"execution_count":null,"outputs":[]}]}