{"cells":[{"metadata":{},"cell_type":"markdown","source":"I made this notebook to have a simple example on how to train a model and submit prediction."},{"metadata":{},"cell_type":"markdown","source":"# Package import"},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"import riiideducation\n\nimport numpy as np\nimport os\nimport pandas as pd\nfrom sklearn.ensemble import RandomForestClassifier\n\nfrom sklearn import metrics","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# List Files"},{"metadata":{"trusted":true},"cell_type":"code","source":"for dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Loading the data"},{"metadata":{},"cell_type":"markdown","source":"We are just going to use the train.csv file  and a few columns "},{"metadata":{"trusted":true},"cell_type":"code","source":"train = pd.read_csv('/kaggle/input/riiid-test-answer-prediction/train.csv', nrows=10**5, \n                    dtype={'row_id': 'int64', 'timestamp': 'int64', 'user_id': 'int32', 'content_id': 'int16', 'content_type_id': 'int8',\n                              'task_container_id': 'int16', 'user_answer': 'int8', 'answered_correctly': 'int8', 'prior_question_elapsed_time': 'float32', \n                             'prior_question_had_explanation': 'boolean',\n                             })\ntrain = train.drop(train[train['answered_correctly']==-1].index)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Create Model and train it"},{"metadata":{"trusted":true},"cell_type":"code","source":"RFC = RandomForestClassifier(max_depth=10, random_state=0)\nRFC.fit(train[['timestamp', 'content_id', 'content_type_id', 'task_container_id', 'prior_question_elapsed_time', 'prior_question_had_explanation']].fillna(0), train['answered_correctly'])","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Prediction"},{"metadata":{"trusted":true},"cell_type":"code","source":"#Create the env\nenv = riiideducation.make_env()\n\n#Create the iterator\niter_test = env.iter_test()\n\n#Iter and predict\nfor (test_df, sample_prediction_df) in iter_test:\n    test_df['answered_correctly'] = RFC.predict(test_df[['timestamp', 'content_id', 'content_type_id', 'task_container_id', 'prior_question_elapsed_time', 'prior_question_had_explanation']].fillna(0))\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}