{"cells":[{"metadata":{},"cell_type":"markdown","source":"## In-depth Introduction\nFirst let's import the module and create an environment."},{"metadata":{"trusted":true},"cell_type":"code","source":"from keras.models import Sequential\nfrom keras.layers import Dense\nfrom numpy import loadtxt\nimport tensorflow as tf\n\nimport keras\nimport pandas as pd\nimport numpy as np\nimport riiideducation\n\n# You can only call make_env() once, so don't lose it!\n#env = riiideducation.make_env()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"questions = pd.read_csv(\"../input/userquestions-dataframes-csv/questions_dataframe.csv\")\nusers = pd.read_csv(\"../input/userquestions-dataframes-csv/users_dataframe.csv\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"users","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"model = keras.models.load_model(\"../input/model2/wholedatamodel_5layers_256r_128r_64r_32r_1s_lr.00001.h5\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#p = np.array([1.20100000e+04,8.30090791e-01,7.09174841e-01,1,0])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#p = p.reshape(-1,1)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#p.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#model.predict([ 5.69200000e+03,  0.00000000e+00,  0.00000000e+00,\n#         7.45494879e-01,  6.95652174e-01])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"model.summary()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"feature_list = ['content_id','prior_question_elapsed_time','prior_question_had_explanation', 'question_correct_ratio','student_correct_ratio']","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def prepare_test_features(test_df,feature_list):\n    ['content_id','prior_question_elapsed_time','prior_question_had_explanation', 'question_correct_ratio','student_correct_ratio']\n    \n        \n    test_df = pd.merge(test_df,questions[['content_id', 'question_correct_ratio']],how='left',on='content_id')\n    test_df = pd.merge(test_df,users[['user_id','student_correct_ratio']],how='left',on='user_id')\n    test_df['prior_question_elapsed_time'].fillna(-1,inplace = True)\n    test_df['prior_question_had_explanation'] *= 1 # convert from boolean to numbers\n    test_df['prior_question_had_explanation'].fillna(-1,inplace = True)\n    test_df.fillna(-1,inplace = True)\n    return test_df[feature_list].to_numpy().astype(float)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"env = riiideducation.make_env()\niter_test = env.iter_test()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"for (test_df, sample_prediction_df) in iter_test:\n    test_questions = test_df['content_id'].to_numpy()\n    #print(\"test_questions: \", test_questions)\n    test_users = test_df['user_id'].to_numpy()\n    #print(\"test_users: \", test_users)\n    test_set = prepare_test_features(test_df,feature_list)\n    #print(\"test_set: \", test_set)\n    answered_correctly = model.predict_classes(test_set)\n    #print(\"answered_correctly: \", answered_correctly)\n    #answered_correctly = clf.predict(test_set)\n    test_df['answered_correctly'] = answered_correctly\n    env.predict(test_df.loc[test_df['content_type_id']==0,['row_id','answered_correctly']])","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}