{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import riiideducation\nimport pandas as pd\n\n# You can only call make_env() once, so don't lose it!\nenv = riiideducation.make_env()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"train_df = pd.read_csv('/kaggle/input/riiid-test-answer-prediction/train.csv', usecols=[1, 2, 3,7],\n                       dtype={'timestamp': 'int64', 'user_id': 'int64' ,'content_id': 'int16','answered_correctly':'int8'}\n                      )","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"content_acc = train_df.query('answered_correctly != -1').groupby('content_id')['answered_correctly'].mean().to_dict()\nuser_acc = train_df.query('answered_correctly != -1').groupby('user_id')['answered_correctly'].mean().to_dict()\n# explanation_acc = train_df.query('answered_correctly != -1').groupby('prior_question_had_explanation')['answered_correctly'].mean().to_dict()\n# task_acc = train_df.query('answered_correctly != -1').groupby('task_container_id')['answered_correctly'].mean().to_dict()\niter_test = env.iter_test()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def add_user_acc(x):\n    if x in user_acc.keys():\n        return user_acc[x]\n    else:\n        return 0.5\n    \ndef add_content_acc(x):\n    if x in content_acc.keys():\n        return content_acc[x]\n    else:\n        return 0.5\n\ndef add_task_acc(x):\n    if x in task_acc.keys():\n        return task_acc[x]\n    else:\n        return 0.5\n\ndef add_explanation_acc(x):\n    if x in explanation_acc.keys():\n        return explanation_acc[x]\n    else:\n        return 0.5 \n\n\nfor (test_df, sample_prediction_df) in iter_test:\n    test_df['answered_correctly1'] = test_df['user_id'].apply(add_user_acc).values\n    test_df['answered_correctly2'] = test_df['content_id'].apply(add_content_acc).values\n#     test_df['answered_correctly3'] = test_df['task_container_id'].apply(add_task_acc).values\n#     test_df['answered_correctly4'] = test_df['prior_question_had_explanation'].apply(add_explanation_acc).values\n    test_df['answered_correctly'] = 0.5*test_df['answered_correctly1']+0.5*test_df['answered_correctly2']#+0.15*test_df['answered_correctly3']+0.15*test_df['answered_correctly4']\n    env.predict(test_df.loc[test_df['content_type_id'] == 0, ['row_id', 'answered_correctly']])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"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}