{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"<h1><center>Riiid! Answer Correctness Prediction. Exploratory Data Analysis.</center></h1>","metadata":{}},{"cell_type":"markdown","source":"#### In this competition, your challenge is to create algorithms for \"Knowledge Tracing,\" the modeling of student knowledge over time. The goal is to accurately predict how students will perform on future interactions. You will pair your machine learning skills using Riiid’s EdNet data.\n\n\n#### This notebook contains an elementary analysis of given data for a better understanding of the challenges input.\n\n#### Let's check our data in depth before we start this challenge!","metadata":{}},{"cell_type":"markdown","source":"\n<div class=\"list-group\" id=\"list-tab\" role=\"tablist\">\n<h2 class=\"list-group-item list-group-item-action active\" data-toggle=\"list\" role=\"tab\" aria-controls=\"home\"><center>Quick navigation</center></h2>\n\n* [1. train.csv](#1)\n* [2. questions.csv](#2)\n* [3. lectures.csv](#3)\n* [4. example_test.csv](#4)","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\n\nimport plotly.express as px\nfrom plotly.subplots import make_subplots\nimport plotly.graph_objs as go\nimport matplotlib.pyplot as plt\n\n\nimport riiideducation","metadata":{"execution":{"iopub.status.busy":"2021-06-26T06:47:55.986115Z","iopub.execute_input":"2021-06-26T06:47:55.986508Z","iopub.status.idle":"2021-06-26T06:47:55.991615Z","shell.execute_reply.started":"2021-06-26T06:47:55.986468Z","shell.execute_reply":"2021-06-26T06:47:55.990501Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"1\"></a>\n<h2 ><center>1. train.csv<center><h2>","metadata":{}},{"cell_type":"markdown","source":"**train.csv**\n\n* **row_id**: (int64) ID code for the row.\n\n* **timestamp**: (int64) the time between the first event from a userand the current one.\n\n* **user_id**: (int32) ID code for the user.\n\n* **content_id**: (int16) ID code for the user interaction.\n\n* **content_type_id**: (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* **task_container_id**: (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**. Monotonically increasing for each user.\n\n* **user_answer**: (int8) the user's answer to the question, if any. Read -1 as null, for lectures.\n\n* **answered_correctly**: (int8) if the user responded correctly. Read -1 as null, for lectures.\n\n* **prior_question_elapsed_time**: (float32) How long it took a user to answer their 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. Note that the time is the total time a user took to solve all the questions in the previous bundle.\n\n* **prior_question_had_explanation**: (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 an onboarding diagnostic test where they did not get any feedback.","metadata":{}},{"cell_type":"code","source":"types = {\n        'row_id': 'int64', \n        'timestamp': 'int64', \n        'user_id': 'int32', \n        'content_id': 'int16', \n        'content_type_id': 'int8',\n        'task_container_id': 'int16', \n        'user_answer': 'int8', \n        'answered_correctly': 'int8', \n        'prior_question_elapsed_time': 'float32', \n        'prior_question_had_explanation': 'boolean'\n}","metadata":{"execution":{"iopub.status.busy":"2021-06-26T06:47:56.166189Z","iopub.execute_input":"2021-06-26T06:47:56.166608Z","iopub.status.idle":"2021-06-26T06:47:56.171869Z","shell.execute_reply.started":"2021-06-26T06:47:56.166572Z","shell.execute_reply":"2021-06-26T06:47:56.170777Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The `train.csv` file is too large for kaggle kernel. It will show up a memory error if you try to load it all without specifying types. We will ignore some columns for now to save RAM and load only 1M rows.","metadata":{}},{"cell_type":"code","source":"train_df = pd.read_csv(\n    '/kaggle/input/riiid-test-answer-prediction/train.csv', \n    low_memory=False, \n    nrows=10**6, \n    dtype=types\n)","metadata":{"execution":{"iopub.status.busy":"2021-06-26T06:47:56.336182Z","iopub.execute_input":"2021-06-26T06:47:56.336584Z","iopub.status.idle":"2021-06-26T06:47:57.685855Z","shell.execute_reply.started":"2021-06-26T06:47:56.336544Z","shell.execute_reply":"2021-06-26T06:47:57.684771Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Let's look at the data and main columns properties:","metadata":{}},{"cell_type":"code","source":"train_df.head(10)","metadata":{"execution":{"iopub.status.busy":"2021-06-26T06:47:57.687528Z","iopub.execute_input":"2021-06-26T06:47:57.687809Z","iopub.status.idle":"2021-06-26T06:47:57.709724Z","shell.execute_reply.started":"2021-06-26T06:47:57.687781Z","shell.execute_reply":"2021-06-26T06:47:57.708530Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.info()","metadata":{"execution":{"iopub.status.busy":"2021-06-26T06:47:57.711567Z","iopub.execute_input":"2021-06-26T06:47:57.711862Z","iopub.status.idle":"2021-06-26T06:47:57.758788Z","shell.execute_reply.started":"2021-06-26T06:47:57.711822Z","shell.execute_reply":"2021-06-26T06:47:57.757708Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('Part of missing values for every column')\nprint(train_df.isnull().sum() / len(train_df))","metadata":{"execution":{"iopub.status.busy":"2021-06-26T06:47:57.762227Z","iopub.execute_input":"2021-06-26T06:47:57.762600Z","iopub.status.idle":"2021-06-26T06:47:57.785540Z","shell.execute_reply.started":"2021-06-26T06:47:57.762565Z","shell.execute_reply":"2021-06-26T06:47:57.784512Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#1 year = 31536000000 ms\nts = train_df['timestamp']/(31536000000/12)\nfig = plt.figure(figsize=(12,6))\nts.plot.hist(bins=100)\nplt.title(\"Histogram of timestamp\")\nplt.xticks(rotation=0)\nplt.xlabel(\"Months between this user interaction and the first event completion from that user\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-06-26T06:47:57.786789Z","iopub.execute_input":"2021-06-26T06:47:57.787033Z","iopub.status.idle":"2021-06-26T06:47:58.230819Z","shell.execute_reply.started":"2021-06-26T06:47:57.787007Z","shell.execute_reply":"2021-06-26T06:47:58.229680Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(f'Of the {train_df.user_id.nunique()} users in train we have {train_df[train_df.timestamp == 0].user_id.nunique()} users with a timestamp zero row.')","metadata":{"execution":{"iopub.status.busy":"2021-06-26T06:47:58.232155Z","iopub.execute_input":"2021-06-26T06:47:58.232465Z","iopub.status.idle":"2021-06-26T06:47:58.258562Z","shell.execute_reply.started":"2021-06-26T06:47:58.232431Z","shell.execute_reply":"2021-06-26T06:47:58.257423Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"WIDTH = 800","metadata":{"execution":{"iopub.status.busy":"2021-06-26T06:47:58.259763Z","iopub.execute_input":"2021-06-26T06:47:58.260020Z","iopub.status.idle":"2021-06-26T06:47:58.264667Z","shell.execute_reply.started":"2021-06-26T06:47:58.259994Z","shell.execute_reply":"2021-06-26T06:47:58.263368Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ds = train_df['user_id'].value_counts().reset_index()\n\nds.columns = [\n    'user_id', \n    'count'\n]\n\nds['user_id'] = ds['user_id'].astype(str) + '-'\nds = ds.sort_values(['count']).tail(40)\n\nfig = px.bar(\n    ds, \n    x='count', \n    y='user_id', \n    orientation='h', \n    title='Top 40 users by number of actions', \n    width=WIDTH,\n    height=900 \n)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-06-26T06:47:58.266890Z","iopub.execute_input":"2021-06-26T06:47:58.267193Z","iopub.status.idle":"2021-06-26T06:47:58.350393Z","shell.execute_reply.started":"2021-06-26T06:47:58.267166Z","shell.execute_reply":"2021-06-26T06:47:58.349389Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ds = train_df['user_id'].value_counts().reset_index()\n\nds.columns = [\n    'user_id', \n    'count'\n]\n\nds = ds.sort_values('user_id')\n\nfig = px.line(\n    ds, \n    x='user_id', \n    y='count', \n    title='User action distribution', \n    width=WIDTH,\n    height=600 \n)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-06-26T06:47:58.352171Z","iopub.execute_input":"2021-06-26T06:47:58.352482Z","iopub.status.idle":"2021-06-26T06:47:58.435852Z","shell.execute_reply.started":"2021-06-26T06:47:58.352450Z","shell.execute_reply":"2021-06-26T06:47:58.434705Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ds = train_df['content_id'].value_counts().reset_index()\n\nds.columns = [\n    'content_id', \n    'count'\n]\n\nds['content_id'] = ds['content_id'].astype(str) + '-'\nds = ds.sort_values(['count']).tail(40)\n\nfig = px.bar(\n    ds, \n    x='count', \n    y='content_id', \n    orientation='h', \n    title='Top 40 most used content_ids',  \n    width=WIDTH,\n    height=900\n)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-06-26T06:47:58.437405Z","iopub.execute_input":"2021-06-26T06:47:58.437712Z","iopub.status.idle":"2021-06-26T06:47:58.519433Z","shell.execute_reply.started":"2021-06-26T06:47:58.437683Z","shell.execute_reply":"2021-06-26T06:47:58.518302Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ds = train_df['content_id'].value_counts().reset_index()\n\nds.columns = [\n    'content_id', \n    'count'\n]\n\nds = ds.sort_values('content_id')\n\nfig = px.line(\n    ds, \n    x='content_id', \n    y='count', \n    title='content_id action distribution', \n    width=WIDTH,\n    height=600 \n)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-06-26T06:47:58.520563Z","iopub.execute_input":"2021-06-26T06:47:58.520819Z","iopub.status.idle":"2021-06-26T06:47:58.638132Z","shell.execute_reply.started":"2021-06-26T06:47:58.520793Z","shell.execute_reply":"2021-06-26T06:47:58.637369Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ds = train_df['content_type_id'].value_counts().reset_index()\n\nds.columns = [\n    'content_type_id', \n    'percent'\n]\n\nds['percent'] /= len(train_df)\n\nfig = px.pie(\n    ds, \n    names='content_type_id', \n    values='percent', \n    title='Lecures & questions', \n    width=WIDTH,\n    height=500 \n)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-06-26T06:47:58.639079Z","iopub.execute_input":"2021-06-26T06:47:58.639313Z","iopub.status.idle":"2021-06-26T06:47:58.693683Z","shell.execute_reply.started":"2021-06-26T06:47:58.639289Z","shell.execute_reply":"2021-06-26T06:47:58.692778Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ds = train_df['task_container_id'].value_counts().reset_index()\n\nds.columns = [\n    'task_container_id', \n    'count'\n]\n\nds['task_container_id'] = ds['task_container_id'].astype(str) + '-'\nds = ds.sort_values(['count']).tail(40)\n\nfig = px.bar(\n    ds, \n    x='count', \n    y='task_container_id', \n    orientation='h', \n    title='Top 40 most useful task_container_ids', \n    width=WIDTH,\n    height=900\n)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-06-26T06:47:58.695215Z","iopub.execute_input":"2021-06-26T06:47:58.695480Z","iopub.status.idle":"2021-06-26T06:47:58.768288Z","shell.execute_reply.started":"2021-06-26T06:47:58.695453Z","shell.execute_reply":"2021-06-26T06:47:58.767401Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ds = train_df['task_container_id'].value_counts().reset_index()\n\nds.columns = [\n    'task_container_id', \n    'count'\n]\n\nds = ds.sort_values('task_container_id')\n\nfig = px.line(\n    ds, \n    x='task_container_id', \n    y='count', \n    title='task_container_id action distribution', \n    width=WIDTH,\n    height=600  \n)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-06-26T06:47:58.769472Z","iopub.execute_input":"2021-06-26T06:47:58.769717Z","iopub.status.idle":"2021-06-26T06:47:58.859927Z","shell.execute_reply.started":"2021-06-26T06:47:58.769692Z","shell.execute_reply":"2021-06-26T06:47:58.858970Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ds = train_df['user_answer'].value_counts().reset_index()\n\nds.columns = [\n    'user_answer', \n    'percent_of_answers'\n]\n\nds['percent_of_answers'] /= len(train_df)\nds = ds.sort_values(['percent_of_answers'])\n\nfig = px.bar(\n    ds, \n    x='user_answer', \n    y='percent_of_answers', \n    orientation='v', \n    title='Percent of user answers for every option', \n    width=WIDTH,\n    height=400 \n)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-06-26T06:47:58.861326Z","iopub.execute_input":"2021-06-26T06:47:58.861623Z","iopub.status.idle":"2021-06-26T06:47:58.926743Z","shell.execute_reply.started":"2021-06-26T06:47:58.861593Z","shell.execute_reply":"2021-06-26T06:47:58.925789Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ds = train_df['answered_correctly'].value_counts().reset_index()\n\nds.columns = [\n    'answered_correctly', \n    'percent_of_answers'\n]\n\nds['percent_of_answers'] /= len(train_df)\nds = ds.sort_values(['percent_of_answers'])\n\nfig = px.pie(\n    ds, \n    names='answered_correctly', \n    values='percent_of_answers', \n    title='Percent of correct answers', \n    width=WIDTH,\n    height=500 \n)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-06-26T06:47:58.952326Z","iopub.execute_input":"2021-06-26T06:47:58.952685Z","iopub.status.idle":"2021-06-26T06:47:59.005985Z","shell.execute_reply.started":"2021-06-26T06:47:58.952652Z","shell.execute_reply":"2021-06-26T06:47:59.005214Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = make_subplots(rows=3, cols=2)\n\ntraces = [\n    go.Bar(\n        x=[\n            -1, 0, 1\n        ], \n        y=[\n            len(train_df[(train_df['user_answer'] == item) & (train_df['answered_correctly'] == -1)]),\n            len(train_df[(train_df['user_answer'] == item) & (train_df['answered_correctly'] == 0)]),\n            len(train_df[(train_df['user_answer'] == item) & (train_df['answered_correctly'] == 1)])\n        ], \n        name='Option: ' + str(item),\n        text = [\n            str(round(100 * len(train_df[(train_df['user_answer'] == item) & (train_df['answered_correctly'] == -1)]) / len(train_df[(train_df['user_answer'] == item)]), 2)) + '%',\n            str(round(100 * len(train_df[(train_df['user_answer'] == item) & (train_df['answered_correctly'] == -0)]) / len(train_df[(train_df['user_answer'] == item)]), 2)) + '%',\n            str(round(100 * len(train_df[(train_df['user_answer'] == item) & (train_df['answered_correctly'] == 1)]) / len(train_df[(train_df['user_answer'] == item)]), 2)) + '%',\n        ],\n        textposition='auto'\n    ) for item in train_df['user_answer'].unique().tolist()\n]\n\nfor i in range(len(traces)):\n    fig.append_trace(\n        traces[i], \n        (i // 2) + 1, \n        (i % 2)  + 1\n    )\n\nfig.update_layout(\n    title_text='Percent of correct answers for every option',\n    height=900,\n    width=WIDTH\n)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-06-26T06:47:59.132581Z","iopub.execute_input":"2021-06-26T06:47:59.133158Z","iopub.status.idle":"2021-06-26T06:47:59.675172Z","shell.execute_reply.started":"2021-06-26T06:47:59.133124Z","shell.execute_reply":"2021-06-26T06:47:59.674464Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = px.histogram(\n    train_df, \n    x=\"prior_question_elapsed_time\",\n    nbins=50,\n    title='prior_question_elapsed_time distribution',\n    width=WIDTH,\n    height=500\n)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-06-26T06:47:59.676278Z","iopub.execute_input":"2021-06-26T06:47:59.676683Z","iopub.status.idle":"2021-06-26T06:48:03.892831Z","shell.execute_reply.started":"2021-06-26T06:47:59.676644Z","shell.execute_reply":"2021-06-26T06:48:03.891096Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"2\"></a>\n<h2><center>2. questions.csv<center><h2>","metadata":{}},{"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](https://www.iibc-global.org/english/toeic/test/lr/about/format.html).\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":{}},{"cell_type":"code","source":"questions = pd.read_csv('/kaggle/input/riiid-test-answer-prediction/questions.csv')","metadata":{"execution":{"iopub.status.busy":"2021-06-26T06:48:03.895794Z","iopub.execute_input":"2021-06-26T06:48:03.896106Z","iopub.status.idle":"2021-06-26T06:48:03.916094Z","shell.execute_reply.started":"2021-06-26T06:48:03.896076Z","shell.execute_reply":"2021-06-26T06:48:03.914623Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"questions.head(10)","metadata":{"execution":{"iopub.status.busy":"2021-06-26T06:48:03.918154Z","iopub.execute_input":"2021-06-26T06:48:03.918574Z","iopub.status.idle":"2021-06-26T06:48:03.933223Z","shell.execute_reply.started":"2021-06-26T06:48:03.918530Z","shell.execute_reply":"2021-06-26T06:48:03.932126Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"questions.info()","metadata":{"execution":{"iopub.status.busy":"2021-06-26T06:48:03.935195Z","iopub.execute_input":"2021-06-26T06:48:03.935628Z","iopub.status.idle":"2021-06-26T06:48:03.963748Z","shell.execute_reply.started":"2021-06-26T06:48:03.935582Z","shell.execute_reply":"2021-06-26T06:48:03.962791Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('Part of missing values for every column')\nprint(questions.isnull().sum() / len(questions))","metadata":{"execution":{"iopub.status.busy":"2021-06-26T06:48:03.964999Z","iopub.execute_input":"2021-06-26T06:48:03.965261Z","iopub.status.idle":"2021-06-26T06:48:03.977049Z","shell.execute_reply.started":"2021-06-26T06:48:03.965234Z","shell.execute_reply":"2021-06-26T06:48:03.975762Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"questions['tag'] = questions['tags'].str.split(' ')\nquestions = questions.explode('tag')\nquestions = pd.merge(\n    questions, \n    questions.groupby('question_id')['tag'].count().reset_index(), \n    on='question_id'\n)\n\nquestions = questions.drop(['tag_x'], axis=1)\n\nquestions.columns = [\n    'question_id', \n    'bundle_id', \n    'correct_answer', \n    'part', \n    'tags', \n    'tags_number'\n]\n\nquestions = questions.drop_duplicates()","metadata":{"execution":{"iopub.status.busy":"2021-06-26T06:48:03.978729Z","iopub.execute_input":"2021-06-26T06:48:03.979141Z","iopub.status.idle":"2021-06-26T06:48:04.048807Z","shell.execute_reply.started":"2021-06-26T06:48:03.979100Z","shell.execute_reply":"2021-06-26T06:48:04.047582Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ds = questions['correct_answer'].value_counts().reset_index()\n\nds.columns = [\n    'correct_answer', \n    'number_of_answers'\n]\n\nds['correct_answer'] = ds['correct_answer'].astype(str) + '-'\nds = ds.sort_values(['number_of_answers'])\n\nfig = px.bar(\n    ds, \n    x='number_of_answers', \n    y='correct_answer', \n    orientation='h', \n    title='Number of correct answers per group', \n    width=WIDTH,\n    height=300\n)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-06-26T06:48:04.051368Z","iopub.execute_input":"2021-06-26T06:48:04.051689Z","iopub.status.idle":"2021-06-26T06:48:04.118815Z","shell.execute_reply.started":"2021-06-26T06:48:04.051657Z","shell.execute_reply":"2021-06-26T06:48:04.117878Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ds = questions['part'].value_counts().reset_index()\n\nds.columns = [\n    'part', \n    'count'\n]\n\nds['part'] = ds['part'].astype(str) + '-'\nds = ds.sort_values(['count'])\n\nfig = px.bar(\n    ds, \n    x='count', \n    y='part', \n    orientation='h', \n    title='Parts distribution',\n    width=WIDTH,\n    height=400\n)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-06-26T06:48:04.120439Z","iopub.execute_input":"2021-06-26T06:48:04.120871Z","iopub.status.idle":"2021-06-26T06:48:04.179381Z","shell.execute_reply.started":"2021-06-26T06:48:04.120837Z","shell.execute_reply":"2021-06-26T06:48:04.178656Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ds = questions['tags_number'].value_counts().reset_index()\n\nds.columns = [\n    'tags_number', \n    'count'\n]\n\nds['tags_number'] = ds['tags_number'].astype(str) + '-'\nds = ds.sort_values(['tags_number'])\n\nfig = px.bar(\n    ds, \n    x='count', \n    y='tags_number', \n    orientation='h', \n    title='Number tags distribution', \n    width=WIDTH,\n    height=400 \n)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-06-26T06:48:04.180379Z","iopub.execute_input":"2021-06-26T06:48:04.180853Z","iopub.status.idle":"2021-06-26T06:48:04.239290Z","shell.execute_reply.started":"2021-06-26T06:48:04.180820Z","shell.execute_reply":"2021-06-26T06:48:04.238588Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"check = questions['tags'].str.split(' ').explode('tags').reset_index()\ncheck = check['tags'].value_counts().reset_index()\n\ncheck.columns = [\n    'tag', \n    'count'\n]\n\ncheck['tag'] = check['tag'].astype(str) + '-'\ncheck = check.sort_values(['count']).tail(30)\n\nfig = px.bar(\n    check, \n    x='count', \n    y='tag', \n    orientation='h', \n    title='Top 30 most useful tags', \n    width=WIDTH,\n    height=900 \n)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-06-26T06:48:04.240266Z","iopub.execute_input":"2021-06-26T06:48:04.240684Z","iopub.status.idle":"2021-06-26T06:48:04.328557Z","shell.execute_reply.started":"2021-06-26T06:48:04.240652Z","shell.execute_reply":"2021-06-26T06:48:04.327562Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"3\"></a>\n<h2><center>3. lectures.csv<center><h2>","metadata":{}},{"cell_type":"markdown","source":"**lectures.csv**: metadata for the lectures watched by users as they progress in their education.\n\n* **lecture_id**: foreign key for the train/test content_id column, when the content type is lecture (1).\n\n* **part**: top level category code for the lecture.\n\n* **tag**: one tag codes for the lecture. The meaning of the tags will not be provided, but these codes are sufficient for clustering the lectures together.\n\n* **type_of**: brief description of the core purpose of the lecture","metadata":{}},{"cell_type":"code","source":"lectures = pd.read_csv('/kaggle/input/riiid-test-answer-prediction/lectures.csv')\nlectures.head(10)","metadata":{"execution":{"iopub.status.busy":"2021-06-26T06:48:04.329874Z","iopub.execute_input":"2021-06-26T06:48:04.330172Z","iopub.status.idle":"2021-06-26T06:48:04.346202Z","shell.execute_reply.started":"2021-06-26T06:48:04.330140Z","shell.execute_reply":"2021-06-26T06:48:04.345128Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lectures.info()","metadata":{"execution":{"iopub.status.busy":"2021-06-26T06:48:04.347670Z","iopub.execute_input":"2021-06-26T06:48:04.348069Z","iopub.status.idle":"2021-06-26T06:48:04.366107Z","shell.execute_reply.started":"2021-06-26T06:48:04.348024Z","shell.execute_reply":"2021-06-26T06:48:04.364502Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('Part of missing values for every column')\nprint(lectures.isnull().sum() / len(lectures))","metadata":{"execution":{"iopub.status.busy":"2021-06-26T06:48:04.368199Z","iopub.execute_input":"2021-06-26T06:48:04.368542Z","iopub.status.idle":"2021-06-26T06:48:04.386948Z","shell.execute_reply.started":"2021-06-26T06:48:04.368502Z","shell.execute_reply":"2021-06-26T06:48:04.385924Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ds = lectures['tag'].value_counts().reset_index()\n\nds.columns = [\n    'tag', \n    'count'\n]\n\nds['tag'] = ds['tag'].astype(str) + '-'\nds = ds.sort_values(['count']).tail(40)\n\nfig = px.bar(\n    ds, \n    x='count', \n    y='tag', \n    orientation='h', \n    title='Top 40 lectures by number of tags', \n    height=900, \n    width=WIDTH\n)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-06-26T06:48:04.388144Z","iopub.execute_input":"2021-06-26T06:48:04.388625Z","iopub.status.idle":"2021-06-26T06:48:04.484621Z","shell.execute_reply.started":"2021-06-26T06:48:04.388576Z","shell.execute_reply":"2021-06-26T06:48:04.483214Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ds = lectures['part'].value_counts().reset_index()\n\nds.columns = [\n    'part', \n    'count'\n]\n\nds['part'] = ds['part'].astype(str) + '-'\nds = ds.sort_values(['count'])\n\nfig = px.bar(\n    ds, \n    x='count', \n    y='part', \n    orientation='h', \n    title='Parts distribution', \n    height=400, \n    width=WIDTH\n)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-06-26T06:48:04.486089Z","iopub.execute_input":"2021-06-26T06:48:04.486433Z","iopub.status.idle":"2021-06-26T06:48:04.578549Z","shell.execute_reply.started":"2021-06-26T06:48:04.486397Z","shell.execute_reply":"2021-06-26T06:48:04.577428Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ds = lectures['type_of'].value_counts().reset_index()\n\nds.columns = [\n    'type_of', \n    'count'\n]\n\nds = ds.sort_values(['count'])\n\nfig = px.bar(\n    ds, \n    x='count', \n    y='type_of', \n    orientation='h', \n    title='type_of lectures', \n    height=300, \n    width=WIDTH\n)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-06-26T06:48:04.580201Z","iopub.execute_input":"2021-06-26T06:48:04.580668Z","iopub.status.idle":"2021-06-26T06:48:04.647148Z","shell.execute_reply.started":"2021-06-26T06:48:04.580622Z","shell.execute_reply":"2021-06-26T06:48:04.645966Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"4\"></a>\n<h2><center>4. example_test.csv<center><h2>","metadata":{}},{"cell_type":"markdown","source":"**example_test.csv**: Three sample groups of the test set data as it will be delivered by the time-series API. The format is largely the same as **train.csv**. There are two different rows that mirror what information the AI tutor actually has available at any given time, but with the user interactions grouped together for the sake of API performance rather than strictly showing information for a single user at a time. Some questions will appear in the hidden test set that have NOT been presented in the train set, emulating the challenge of quickly adapting to modeling newly introduced questions. Their metadata is still in question.csv as usual.\n\n**prior_group_responses**: (string) provides all of the **user_answer** entries for previous group in a string representation of a list in the first row of the group. All other rows in each group are null. If you are using Python, you will likely want to call **eval** on the non-null rows. Some rows may be null, or empty lists.\n\n**prior_group_answers_correct**: (string) provides all the **answered_correctly** field for previous group, with the same format and caveats as **prior_group_responses**. Some rows may be null, or empty lists.","metadata":{}},{"cell_type":"code","source":"test_ex = pd.read_csv('/kaggle/input/riiid-test-answer-prediction/example_test.csv')\ntest_ex","metadata":{"execution":{"iopub.status.busy":"2021-06-26T06:48:04.648771Z","iopub.execute_input":"2021-06-26T06:48:04.649099Z","iopub.status.idle":"2021-06-26T06:48:04.674672Z","shell.execute_reply.started":"2021-06-26T06:48:04.649063Z","shell.execute_reply":"2021-06-26T06:48:04.673673Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_ex.info()","metadata":{"execution":{"iopub.status.busy":"2021-06-26T06:48:04.676139Z","iopub.execute_input":"2021-06-26T06:48:04.676458Z","iopub.status.idle":"2021-06-26T06:48:04.698663Z","shell.execute_reply.started":"2021-06-26T06:48:04.676426Z","shell.execute_reply":"2021-06-26T06:48:04.695978Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('Part of missing values for every column')\nprint(test_ex.isnull().sum() / len(test_ex))","metadata":{"execution":{"iopub.status.busy":"2021-06-26T06:48:04.700585Z","iopub.execute_input":"2021-06-26T06:48:04.701196Z","iopub.status.idle":"2021-06-26T06:48:04.711524Z","shell.execute_reply.started":"2021-06-26T06:48:04.701111Z","shell.execute_reply":"2021-06-26T06:48:04.710297Z"},"trusted":true},"execution_count":null,"outputs":[]}]}