{"cells":[{"metadata":{"_uuid":"16b018d8-1e53-4c24-bae1-da09824253c5","_cell_guid":"3334154d-97bc-44c5-9c5f-92ef38402d86","trusted":true},"cell_type":"markdown","source":"<h1><center>Riiid! Answer Correctness Prediction. Data Analysis and visualization.</center></h1>\n\n<center><img src=\"https://www.riiid.co/assets/main_hero_aied.png\"></center>"},{"metadata":{"_uuid":"309014fe-b336-4236-9efc-b8966245fa6b","_cell_guid":"22a4a7d8-f865-40a1-8721-649c99550594","trusted":true},"cell_type":"markdown","source":"**Reading this notebook, you will find,**\n\n1. Incomplete rows (with null values) which might be removed or complemented\n2. Strange task_container_id jumps which might be revised\n3. Analysis of features (answer correctness by features, etc)"},{"metadata":{"_uuid":"6af0d2be-6dbc-4c3e-b27a-bc4533dddc06","_cell_guid":"aebc62b7-b843-4602-be8b-e6334db83cb0","trusted":true},"cell_type":"markdown","source":"<a id=\"top\"></a>\n\n<div class=\"list-group\" id=\"list-tab\" role=\"tablist\">\n<h3 class=\"list-group-item list-group-item-action active\" data-toggle=\"list\" style='background:blue; border:0' role=\"tab\" aria-controls=\"home\"><center>Quick navigation</center></h3>\n\n* [1. train.csv](#1)\n    * [1.1 row_id, timestamp, user_id, user_answer](#11)\n    * [1.2 content_type_id, questions / lectures](#12)\n    * [1.3 prior_question_had_explanation](#13)\n    * [1.4 the incomplete 392,506 rows](#14)\n    * [1.5 prior_question_elapsed_time](#15)\n    * [1.6 task_container_id](#16)\n    * [1.7 user_id](#17)\n    * [1.8 content_id](#18)\n    \n* [2. question.csv](#2)\n* [3. work in progress](#3)"},{"metadata":{},"cell_type":"markdown","source":"Using .jay format, we can read the full train.csv very fast. You can see the details in [Vopani's fantastic notebook](https://www.kaggle.com/rohanrao/riiid-with-blazing-fast-rid)"},{"metadata":{"trusted":true},"cell_type":"code","source":"# datatable library installation\n!pip install ../input/python-datatable/datatable-0.11.0-cp37-cp37m-manylinux2010_x86_64.whl","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"5edfcbb1-33ea-4e7d-a769-ae3565d569d8","_cell_guid":"ed880b99-13b9-4a51-b500-146533b40337","trusted":true,"_kg_hide-input":false,"_kg_hide-output":false},"cell_type":"code","source":"import time\nstart_time = time.time()\n\nimport numpy as np\nimport pandas as pd\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\nimport plotly.express as px\nfrom plotly.subplots import make_subplots\nimport plotly.graph_objs as go\n\nimport sys\nimport gc\nimport datatable as dt","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"7dea20d5-ca68-4efa-b6c1-4464feed89d5","_cell_guid":"e229d539-e42c-4644-a3a1-d0d2a9296a56","trusted":true},"cell_type":"markdown","source":"<a id=\"1\"></a>\n# <center>1. train.csv<center>"},{"metadata":{"_uuid":"b84da723-b748-4ca2-a4e2-766c01419b73","_cell_guid":"3331a971-6e1f-4267-b275-7f5c0fb8d292","trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"# saving the dataset in .jay (binary format)\ndt.fread(\"../input/riiid-test-answer-prediction/train.csv\").to_jay(\"train.jay\")","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"8ded64ff-d73f-4f54-b692-6004fbcb02b1","_cell_guid":"2b8d396d-3de2-474f-8a06-3f4e1a8feab4","trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"# reading the dataset from .jay format\nimport datatable as dt\ntrain = dt.fread(\"train.jay\")","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"bdc5fa3e-a040-45c3-a864-25a5f412585f","_cell_guid":"591ab182-9305-4360-bee7-8a9bccb544bc","trusted":true,"_kg_hide-input":false,"_kg_hide-output":false},"cell_type":"code","source":"# transforming to pandas format\ntrain_df = dt.fread(\"train.jay\").to_pandas()\nprint(train.shape)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"dbe468d4-01ab-4614-ae9d-35e3a6fafa3c","_cell_guid":"e55925f4-362e-49d9-aafe-4b1d89212251","trusted":true},"cell_type":"markdown","source":"# <center>1.1 row_id, timestamp</center>\n\n<a id=\"11\"></a>\n* Format  \n<font color=\"Magenta\">**Feature column name**:</font> (Data format) *Description by the host*  \n**My findings**\n  \n<font color=\"Magenta\">**row_id**:</font> (int64) *ID code for the row.*  \n**This database contains 101,230,332 rows (users' interactions).**  \n\n[Data Description](https://www.kaggle.com/c/riiid-test-answer-prediction/data) says, \"<font color=\"Red\">*Expect to see roughly 2.5 million questions in the hidden test set.*</font>\" **<- I think *'the 2.5 million questions'* means interactions (rows).**\n\n<font color=\"Magenta\">**timestamp**:</font> (int64) *the time in milliseconds between this user interaction and the first event completion from that user.*  \n**Max value is 87,425,770,000. 1 year is 365 \\* 24 \\* 60 \\* 60 \\* 1000 = 31,536,000,000. The longest span of interactions is 2.77 years.**"},{"metadata":{"_kg_hide-input":true,"trusted":true},"cell_type":"code","source":"# transform 'content_type_id' from bool to int\ntrain_df['content_type_id'] = train_df['content_type_id'] * 1","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"6d7ec544-3b86-408d-8892-01c719ed0eb0","_cell_guid":"157aece4-866e-4fd7-80e1-c35006af597f","trusted":true},"cell_type":"code","source":"pd.options.display.float_format = '{:.11g}'.format\ntrain_df.describe()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"01734acd-5143-4044-a191-0fa023e583d4","_cell_guid":"1fe10d99-0f05-4e21-97d4-c2fc93ae5ac9","trusted":true},"cell_type":"markdown","source":"# <center>1.2 content_type_id</center>\n<a id=\"12\"></a>\n<font color=\"Magenta\">**content_type_id**:</font> (int8) *0 if the event was a question being posed to the user, 1 if the event was the user watching a lecture.*  \n  \n**The average user answers 51.7 questions (1 / 0.01935) per lecture.  \nAll lecture rows have <font color=\"Red\">\"-1\"</font> in <font color=\"Magenta\">'answered_correctly'</font> and <font color=\"Red\">null</font> in <font color=\"Magenta\">'prior_question_elapsed_time'</font>. But despite the description, they have <font color=\"Red\">'False'</font> value instead of 'null' in <font color=\"Magenta\">'prior_question_had_explanation'</font>.**\n\n[Data Description](https://www.kaggle.com/c/riiid-test-answer-prediction/data) says,\n\"<font color=\"Red\">*The lecture rows in test_df should not be submitted.*</font>\""},{"metadata":{"_uuid":"ecc8fc68-3e6c-4bcf-8fd7-a5c2285f6b16","_cell_guid":"b6859360-cbba-48bd-9c3e-e3051d1b4554","trusted":true},"cell_type":"code","source":"train_df_lecture = train_df[train_df['content_type_id'] == 1]\ntrain_df_lecture.shape","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"78bcc5c0-8c0a-4bb8-b079-29a6509ccee5","_cell_guid":"0208eacd-2859-4fb9-b9f4-395c092ab94d","trusted":true},"cell_type":"code","source":"train_df_lecture['answered_correctly'].value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df[train_df['answered_correctly'] == -1]['content_type_id'].value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df_lecture['prior_question_elapsed_time'].isnull().count()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df_lecture['prior_question_had_explanation'].value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_kg_hide-input":true,"_kg_hide-output":true},"cell_type":"code","source":"del train_df_lecture\ngc.collect()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"19929082-66d0-4d3f-a621-24b91d7631f7","_cell_guid":"7b845834-fc0f-40b1-8f4e-4a0fa2210714","trusted":true},"cell_type":"code","source":"print('Number of missing values for every column')\nprint(train_df.isnull().sum())","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"349e50cb-826f-438f-b2cf-e6003e50b91d","_cell_guid":"898c4cbf-dfa1-452c-8292-239db6c8b8e9","trusted":true},"cell_type":"markdown","source":"<a id=\"13\"></a>\n# <center>1.3 prior_question_had_explanation</center>\n  \n<font color=\"Magenta\">**prior_question_had_explanation**:</font> (bool) *Whether or not the user saw an explanation and the correct response(s) after answering the previous question bundle, ignoring any lectures in between. The value is shared across a single question bundle, and is null for a user's first question bundle or lecture. Typically the first several questions a user sees were part of <font color=\"Chocolate\">an onboarding diagnostic test</font> where they did not get any feedback.*  \n  \n**90.7% of the questions were answered after reading the explanation, and 67.3% of them were correct.  \nOn the other hand, 9.3% of the questions were answered without explanation, and only 50% of them were correct.**"},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df_questions_only = train_df[train_df['content_type_id'] == 0]\ntrain_df_questions_only['prior_question_had_explanation'].value_counts() / (len(train_df_questions_only) - 392506)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df_questions_only.groupby('prior_question_had_explanation')['answered_correctly'].mean()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"14\"></a>\n# <center>1.4 the incomplete 392,506 rows</center>\n  \n**I found 392,506 null values in the <font color=\"Magenta\">'prior_question_had_explanation'</font> column. \nOf those <font color=\"Red\">'incomplete 392,506 rows'</font>, 392,441 rows' 'timestamps' are zeros, meaning user's first question bundle.  The remaining 65 rows also have lower task_container_ids, inferring <font color=\"Chocolate\">'the onboarding diagnostic test'</font>. Answer correctness is not so bad (68% and 65%, respectably).**  \n  \n**I may remove these rows when modeling or fill the <font color=\"Magenta\">'prior_question_had_explanation'</font> columns with 'False' because users were novices and in <font color=\"Chocolate\">'the onboarding diagnostic test'</font>.**"},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df_explanation_null = train_df[train_df['prior_question_had_explanation'].isnull()]\ntrain_df_explanation_null.shape","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"b6de2e31-20d6-4833-ac1f-c4a8496dc762","_cell_guid":"9776cb3c-3b7d-4c6a-bd22-d00ac06332a3","trusted":true},"cell_type":"code","source":"train_df_explanation_null[train_df_explanation_null['timestamp'] == 0].describe()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df_explanation_null[train_df_explanation_null['timestamp'] != 0].describe()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_kg_hide-input":true,"_kg_hide-output":true},"cell_type":"code","source":"del train_df_explanation_null\ngc.collect()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"15\"></a>\n# <center>1.5 prior_question_elapsed_time</center>\n  \n<font color=\"Magenta\">**prior_question_elapsed_time**:</font> *(float32) The average time in milliseconds it took a user to answer each question in the previous question bundle, ignoring any lectures in between. Is null for a user's first question bundle or lecture. Note that the time is the average time a user took to solve each question in the previous bundle. * \n  \n**This column contains 2,351,538 null values. 1,959,032 of them are lectures. The remaining rows are** <font color=\"Red\">'the incomplete 392,506 rows'</font>\n  \n**The last two digits of this column seems not to be significant.  Max value is 300,000, I guess the time limit for one bundle is 5 minutes.**"},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df_elapsed_null = train_df[train_df['prior_question_elapsed_time'].isnull()]\ntrain_df_elapsed_null = train_df_elapsed_null[train_df_elapsed_null['content_type_id'] == 0]\ntrain_df_elapsed_null.shape","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**Most of the 'timestamp == 0' columns have null values in <font color=\"Magenta\">'prior_question_had_explanation'</font>.  \nBut <font color=\"Red\">the remaining 3,976 rows</font> have 'False' or 'True' value.  I may remove these rows, too.**"},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df_timestamp0 = train_df[train_df['timestamp'] == 0]\ntrain_df_timestamp0.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df_timestamp0['prior_question_had_explanation'].value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df_elapsed_check = train_df[train_df['prior_question_elapsed_time'] < 10000]\ntrain_df_elapsed_check = train_df_elapsed_check.sort_values('prior_question_elapsed_time')\ntrain_df_elapsed_check['prior_question_elapsed_time'].unique()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_kg_hide-input":true,"_kg_hide-output":true},"cell_type":"code","source":"del train_df_elapsed_null, train_df_timestamp0, train_df_elapsed_check\ngc.collect()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"4bc65077-6e37-481e-8dba-3b8949ca1a18","_cell_guid":"3d0c77a4-faa4-4299-b9f2-b204d20acb41","trusted":true},"cell_type":"markdown","source":"<a id=\"16\"></a>\n# <center>1.6 task_container_id</center>\n  \n<font color=\"Magenta\">**task_container_id**:</font> (int16) *Id code for the batch of questions or lectures. For example, a user might see three questions in a row before seeing the explanations for any of them. Those three would all share a task_container_id.*  \n\n**Max value of 9999 seems artificial and I suspect that the system can only count up to 9999 for task_container_id. I checked the behavior after 9999 and found strange counting.**  \n(The first case, id returned from 9999 to 1396 and stopped. The second, it stopped just at 9999. The third, returned to 9506. The fourth, returned to 9989. The fifth, returned to 9953 and then 9122, 9841, 3296, and stopped. It seems a bug to me.)"},{"metadata":{"trusted":true,"_kg_hide-input":true,"_kg_hide-output":true},"cell_type":"code","source":"train_df_questions_only.reset_index(inplace=True, drop=True)\ntrain_df_questions_only","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_kg_hide-input":true,"_kg_hide-output":true},"cell_type":"code","source":"train_df_doubtful_task_id = train_df_questions_only[(train_df_questions_only['task_container_id'].diff() < -1000) & (train_df_questions_only['task_container_id'] != 0)]\ntrain_df_doubtful_task_id","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_kg_hide-input":true,"_kg_hide-output":true},"cell_type":"code","source":"train_df_doubtful_container_id_bins = pd.cut(train_df_doubtful_task_id['task_container_id'], [0, 1, 9, 99, 999, 9999, 20000]).value_counts().reset_index()\ntrain_df_doubtful_container_id_bins.columns = ['bins', 'count']\ntrain_df_doubtful_container_id_bins = train_df_doubtful_container_id_bins.sort_values(by=['bins'])\ntrain_df_doubtful_container_id_bins","execution_count":null,"outputs":[]},{"metadata":{"_kg_hide-input":true,"_kg_hide-output":true,"trusted":true},"cell_type":"code","source":"del train_df_doubtful_task_id, train_df_doubtful_container_id_bins\ngc.collect()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"37f76983-864f-4b55-b159-06f4efe18d64","_cell_guid":"2e32508c-1d14-46c8-91ed-fca55ffbc492","trusted":true,"scrolled":false},"cell_type":"code","source":"train_df['task_container_id'].value_counts()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"3886f8c8-0f6f-4601-907a-13cc11529a00","_cell_guid":"b2cab6bb-49ad-4500-8406-4cba9b85d410","trusted":true},"cell_type":"code","source":"train_df[train_df['task_container_id'] == 9999]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df[1896755:1896762]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"train_df[1929138:1929144]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"train_df[3101565:3101572]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"train_df[4301504:4301511]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"train_df[5295816:5295826]","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**I also found other types of <font color=\"Magenta\">'task_container_ids'</font> jumps. Many (but not all) lecture rows show these jumps. And I have no idea why id went from 4556 to 2786 in row_id 21234106.**"},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df[21234101:21234110]","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**The graph below seems like a learning curve to me. Although <font color=\"Magenta\">'task_container_id'</font> contains some noise, I may use it as an indicator of <font color=\"Red\">users' experience</font>.**"},{"metadata":{"trusted":true},"cell_type":"code","source":"task_accuracy = train_df.groupby('task_container_id')['answered_correctly'].mean()\ntask_accuracy = task_accuracy.rolling(50).mean()\n\nfig = px.line(\n    task_accuracy, \n    title='Answer correctness by task_container_id', \n    height=600, \n    width=800\n)\n\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_kg_hide-input":true,"_kg_hide-output":true},"cell_type":"code","source":"del task_accuracy\ngc.collect()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"21e32b9c-c078-4f99-8aea-3a9988eaae66","_cell_guid":"a20bd8cf-64c0-40dd-8041-597c69876014","trusted":true},"cell_type":"markdown","source":"<a id=\"17\"></a>\n# <center>1.7 user_id</center>\n\n<font color=\"Magenta\">**user_id**:</font> (int32) *ID code for the user.*  \n  \n**The database seems to be sorted by this column. When I split the data into four, all user_ids in the first set are smaller than any of those in the latter sets, and so forth.**\n  \n**393,656 users are in the train.csv.  \n68.2% of users had interacted less than 100 times. 87 of them had only interacted once.  \n346 users had interacted more than or equal to 10,000 times. The most active user (user_id == '801103753') had interacted 17,917 times.**\n\n**In [this Discussion](https://www.kaggle.com/c/riiid-test-answer-prediction/discussion/191106),** Kaggle staff said,\n\"<font color=\"Red\">*the hidden test set contains new users but not new questions.*</font>\""},{"metadata":{"_uuid":"b47eaa77-d7c2-4c12-9b91-1c74d2b8a7a7","_cell_guid":"3fe9d1cd-edb6-422d-ae10-53d285f6bdb1","trusted":true},"cell_type":"code","source":"train_df_user_activeness = train_df['user_id'].value_counts()\ntrain_df_user_activeness","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df_user_activeness_bins = pd.cut(train_df_user_activeness, [0, 1, 9, 99, 999, 9999, 20000]).value_counts().reset_index()\ntrain_df_user_activeness_bins.columns = ['bins', 'count']\ntrain_df_user_activeness_bins = train_df_user_activeness_bins.sort_values(by=['bins'])\ntrain_df_user_activeness_bins","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"8d74ede5-b4d0-4514-8298-1e97f115610e","_cell_guid":"2bc5e917-477c-427b-ac4b-34eff6bfab6a","trusted":true},"cell_type":"code","source":"user_accuracy = train_df_questions_only.groupby('user_id')['answered_correctly'].mean()\n\nfig = px.histogram(\n    user_accuracy, \n    x=\"answered_correctly\",\n    nbins=100,\n    width=700,\n    height=500,\n    title='Answer correctness by user'\n)\n\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"del train_df_user_activeness, train_df_user_activeness_bins, user_accuracy\ngc.collect()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<a id=\"18\"></a>\n# <center>1.8 content_id</center>\n\n<font color=\"Magenta\">**content_id**:</font> (int16) *ID code for the user interaction*  \n**The content_id corresponds to 13523 question_ids (0 to 13522) and 415 lecture_ids (89 to 32736), mixedly.  \nThe most popular 36 questions were answered more than 100,000 times for each. On the other hand, the least popular 243 questions were answered less than 100 times. 9 of them were answered only once. (dummy questions?)**\n\n\n  \n"},{"metadata":{},"cell_type":"markdown","source":"<font color=\"Magenta\">**user_answer**:</font> (int8) *the user's answer to the question, if any. Read -1 as null, for lectures.*  \n**One correct answer among 4 options(0-3). *question.csv* shows that the correct answer rate of option 2 is lower than the other three.  Users answered option 2 less, properly.**"},{"metadata":{"_uuid":"2388415c-08a3-4711-9d7c-eb3c14fc1daa","_cell_guid":"6770390e-9446-45d8-b504-15ba6cbbc929","trusted":true,"_kg_hide-input":true,"_kg_hide-output":true},"cell_type":"code","source":"train_df['content_id'].value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df_questions_id_check = train_df_questions_only['content_id'].value_counts()\ntrain_df_questions_id_check","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df_lectures_only = train_df[train_df['content_type_id'] == 1]\ntrain_df_lectures_id_check = train_df_lectures_only['content_id'].value_counts()\ntrain_df_lectures_id_check","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df_popularity_of_questions = pd.cut(train_df_questions_id_check, [0, 1, 10, 100, 1000, 10000, 100000, 210000]).value_counts().reset_index()\ntrain_df_popularity_of_questions.columns = ['bins', 'count']\ntrain_df_popularity_of_questions = train_df_popularity_of_questions.sort_values(by=['bins'])\ntrain_df_popularity_of_questions","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_kg_hide-input":true,"_kg_hide-output":true},"cell_type":"code","source":"del train_df_popularity_of_questions, train_df_lectures_only, train_df_lectures_id_check\ngc.collect()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"b031056e-2d1e-4449-af8a-06e084415d6c","_cell_guid":"77cb0894-69e3-4368-b873-046a52e299df","trusted":true},"cell_type":"code","source":"content_accuracy = train_df_questions_only.groupby('content_id')['answered_correctly'].mean()\n\nfig = px.histogram(\n    content_accuracy, \n    x=\"answered_correctly\",\n    nbins=100,\n    width=700,\n    height=500,\n    title='Answer correctness by content'\n)\n\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_kg_hide-input":true,"_kg_hide-output":true},"cell_type":"code","source":"del train_df_questions_only, \ngc.collect()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"7ccb468d-8aa9-436f-8ebf-7a45a9fe11f3","_cell_guid":"5e87e64c-2d31-496b-a3ca-0d572a079464","trusted":true},"cell_type":"markdown","source":"<a id=\"2\"></a>\n# <center>2. questions.csv<center>"},{"metadata":{"_uuid":"9ed500d3-27b6-484b-a335-5f778a0f6ce7","_cell_guid":"bc52764b-7218-4a32-809d-89069023cc9a","trusted":true},"cell_type":"markdown","source":"**questions.csv**: metadata for the questions posed to users.\n\n* question_id: foreign key for the train/test content_id column, when the content type is question (0).\n\n* bundle_id: code for which questions are served together.\n\n* correct_answer: the answer to the question. Can be compared with the train user_answer column to check if the user was right.\n\n* part: the relevant section of the TOEIC test.\n\n* tags: one or more detailed tag codes for the question. The meaning of the tags will not be provided, but these codes are sufficient for clustering the questions together."},{"metadata":{"_uuid":"dc7b7664-be0e-4997-a1de-8b9ad77a0b12","_cell_guid":"8fe3d1d3-440e-4b08-9db7-002509c14296","trusted":true},"cell_type":"code","source":"questions_df = pd.read_csv('/kaggle/input/riiid-test-answer-prediction/questions.csv')\nquestions_df.rename(columns={'question_id': 'content_id'}, inplace='True')\nquestions_df","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"307e0201-0027-4b81-aef4-a22dd1332d97","_cell_guid":"9b7733bb-2df2-442f-a4d8-7272bf815444","trusted":true},"cell_type":"markdown","source":"# <center>2.1 part</center>\n\n<font color=\"Magenta\">**part**:</font> top level category code for the question.  \n  \n**In the first place, Riiid is for TOEIC . You can see what is [TOEIC here](https://www.iibc-global.org/english.html). 'part' means [Question types](https://www.iibc-global.org/english/toeic/test/lr/about/format.html)**\n\n* Listening Section  \nPart1:  Photographs - 6 questions  \nPart2:  Question-Response - 25 questions  \nPart3:  Conversations - 39 questions  \nPart4:  Talks - 30 questions  \n\n* Reading Section  \nPart5:  Incomplete Sentences - 30 questions  \nPart6:  Text Completion - 16 questions  \nPart7:  Single Passages - 29 questions / Multiple Passages - 25 questions\n\n**Part1 is the easiest, 81.5% of the questions were answered correctly. Part5 is the hardest, their answer correctness was 66.6%.**"},{"metadata":{"trusted":true},"cell_type":"code","source":"questions_df = pd.merge(content_accuracy, questions_df, on='content_id')\nquestions_df","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"part_accuracy = questions_df.groupby('part')['answered_correctly'].mean()\npart_accuracy.columns = ['part', 'answer_correctness']\npart_accuracy","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"fig = px.bar(\n    part_accuracy, \n    title='accuracy by part'\n)\n\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"run_time = time.time() - start_time\nprint(run_time)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**Thank you for reading my notebook. This notebook is an additional analysis of [Isaienkov's great notebook](https://www.kaggle.com/isaienkov/riiid-answer-correctness-prediction-eda-modeling) from a different angle.  Read his if you haven't. I also reuse some of his code. Thanks, [Isaienkov](https://www.kaggle.com/isaienkov).  \nThis is my first open public book. I appreciate if you**  \n# comment and/or upvote."}],"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":4,"nbformat_minor":4}