{"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":"## Naive approach - Score 0.6\n\nLet's make predictions based on consensus.\n\nIf more than 50% of students have answer correctely to the question, we will consider new students will too.\nOtherwise we will consider that they will fail.","metadata":{}},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np","metadata":{"execution":{"iopub.status.busy":"2023-06-11T13:01:10.491603Z","iopub.execute_input":"2023-06-11T13:01:10.492056Z","iopub.status.idle":"2023-06-11T13:01:10.496743Z","shell.execute_reply.started":"2023-06-11T13:01:10.492027Z","shell.execute_reply":"2023-06-11T13:01:10.495798Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels = pd.read_csv('/kaggle/input/predict-student-performance-from-game-play/train_labels.csv')\n\nlabels[\"question\"] = labels.session_id.str.split(\"_q\").str[1]\nlabels","metadata":{"execution":{"iopub.status.busy":"2023-06-11T13:01:10.498723Z","iopub.execute_input":"2023-06-11T13:01:10.499358Z","iopub.status.idle":"2023-06-11T13:01:12.389657Z","shell.execute_reply.started":"2023-06-11T13:01:10.499329Z","shell.execute_reply":"2023-06-11T13:01:12.388939Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"naive_approach = labels.groupby(\"question\")[\"correct\"].mean()\nnaive_approach","metadata":{"execution":{"iopub.status.busy":"2023-06-11T13:01:12.390855Z","iopub.execute_input":"2023-06-11T13:01:12.391316Z","iopub.status.idle":"2023-06-11T13:01:12.456284Z","shell.execute_reply.started":"2023-06-11T13:01:12.391290Z","shell.execute_reply":"2023-06-11T13:01:12.455300Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"As we can see, only **questions 13 and 15** have more bad responses than good, so we will predict 1 for all the questions except theses two","metadata":{}},{"cell_type":"code","source":"df_naive_approach = pd.DataFrame({\"average_score\": naive_approach})\n\ndf_naive_approach[\"predicted\"] = df_naive_approach[\"average_score\"].apply(lambda x: 1 if x > 0.5 else 0)\ndf_naive_approach.index = df_naive_approach.index.astype(int)\ndf_naive_approach","metadata":{"execution":{"iopub.status.busy":"2023-06-11T13:01:12.458664Z","iopub.execute_input":"2023-06-11T13:01:12.458963Z","iopub.status.idle":"2023-06-11T13:01:12.472061Z","shell.execute_reply.started":"2023-06-11T13:01:12.458940Z","shell.execute_reply":"2023-06-11T13:01:12.471286Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import jo_wilder_310\nenv = jo_wilder_310.make_env()\niter_test = env.iter_test()","metadata":{"execution":{"iopub.status.busy":"2023-06-11T13:01:12.473318Z","iopub.execute_input":"2023-06-11T13:01:12.473832Z","iopub.status.idle":"2023-06-11T13:01:12.509097Z","shell.execute_reply.started":"2023-06-11T13:01:12.473805Z","shell.execute_reply":"2023-06-11T13:01:12.508247Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for (test, sample_submission) in iter_test:\n    sample_submission[\"correct\"] = sample_submission[\"session_id\"]\\\n        .apply(lambda x: int(df_naive_approach.loc[int(x.split(\"_q\")[1])].predicted))\n    env.predict(sample_submission)","metadata":{"execution":{"iopub.status.busy":"2023-06-11T13:01:12.510301Z","iopub.execute_input":"2023-06-11T13:01:12.510851Z","iopub.status.idle":"2023-06-11T13:01:12.575786Z","shell.execute_reply.started":"2023-06-11T13:01:12.510822Z","shell.execute_reply":"2023-06-11T13:01:12.574843Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"! head submission.csv","metadata":{"execution":{"iopub.status.busy":"2023-06-11T13:01:12.577325Z","iopub.execute_input":"2023-06-11T13:01:12.577645Z","iopub.status.idle":"2023-06-11T13:01:13.619174Z","shell.execute_reply.started":"2023-06-11T13:01:12.577620Z","shell.execute_reply":"2023-06-11T13:01:13.618192Z"},"trusted":true},"execution_count":null,"outputs":[]}]}