{"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":"code","source":"import pandas as pd","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-01-08T20:29:48.488588Z","iopub.execute_input":"2023-01-08T20:29:48.489350Z","iopub.status.idle":"2023-01-08T20:29:48.495480Z","shell.execute_reply.started":"2023-01-08T20:29:48.489292Z","shell.execute_reply":"2023-01-08T20:29:48.493723Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Loading data","metadata":{}},{"cell_type":"code","source":"train_data = pd.read_csv(\"/kaggle/input/emsi-5iir-ds/train.csv\")\ntest_data = pd.read_csv(\"/kaggle/input/emsi-5iir-ds/test.csv\")","metadata":{"execution":{"iopub.status.busy":"2023-01-08T20:29:48.498873Z","iopub.execute_input":"2023-01-08T20:29:48.499969Z","iopub.status.idle":"2023-01-08T20:29:58.581223Z","shell.execute_reply.started":"2023-01-08T20:29:48.499927Z","shell.execute_reply":"2023-01-08T20:29:58.579732Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Data shape**","metadata":{}},{"cell_type":"code","source":"train_data.shape, test_data.shape","metadata":{"execution":{"iopub.status.busy":"2023-01-08T20:29:58.582750Z","iopub.execute_input":"2023-01-08T20:29:58.583113Z","iopub.status.idle":"2023-01-08T20:29:58.592081Z","shell.execute_reply.started":"2023-01-08T20:29:58.583082Z","shell.execute_reply":"2023-01-08T20:29:58.590590Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing data","metadata":{}},{"cell_type":"code","source":"train_data.describe()","metadata":{"execution":{"iopub.status.busy":"2023-01-08T20:29:58.595444Z","iopub.execute_input":"2023-01-08T20:29:58.595905Z","iopub.status.idle":"2023-01-08T20:29:59.829614Z","shell.execute_reply.started":"2023-01-08T20:29:58.595853Z","shell.execute_reply":"2023-01-08T20:29:59.828326Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data.describe()","metadata":{"execution":{"iopub.status.busy":"2023-01-08T20:29:59.831181Z","iopub.execute_input":"2023-01-08T20:29:59.831586Z","iopub.status.idle":"2023-01-08T20:30:00.812490Z","shell.execute_reply.started":"2023-01-08T20:29:59.831552Z","shell.execute_reply":"2023-01-08T20:30:00.811168Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Data infos**","metadata":{}},{"cell_type":"code","source":"train_data.info()","metadata":{"execution":{"iopub.status.busy":"2023-01-08T20:30:00.814545Z","iopub.execute_input":"2023-01-08T20:30:00.814956Z","iopub.status.idle":"2023-01-08T20:30:00.922733Z","shell.execute_reply.started":"2023-01-08T20:30:00.814922Z","shell.execute_reply":"2023-01-08T20:30:00.921401Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"In train_data we have **float64(16), int64(16), object(1)**","metadata":{}},{"cell_type":"code","source":"test_data.info()","metadata":{"execution":{"iopub.status.busy":"2023-01-08T20:30:00.924275Z","iopub.execute_input":"2023-01-08T20:30:00.924675Z","iopub.status.idle":"2023-01-08T20:30:01.012437Z","shell.execute_reply.started":"2023-01-08T20:30:00.924629Z","shell.execute_reply":"2023-01-08T20:30:01.011189Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"In test_data we have **float64(16), int64(16), object(1)**","metadata":{}},{"cell_type":"markdown","source":"**Detecting missing values**","metadata":{}},{"cell_type":"code","source":"train_data.isna().sum().any()","metadata":{"execution":{"iopub.status.busy":"2023-01-08T20:30:01.014121Z","iopub.execute_input":"2023-01-08T20:30:01.015511Z","iopub.status.idle":"2023-01-08T20:30:01.112821Z","shell.execute_reply.started":"2023-01-08T20:30:01.015459Z","shell.execute_reply":"2023-01-08T20:30:01.111372Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data.isna().sum().any()","metadata":{"execution":{"iopub.status.busy":"2023-01-08T20:30:01.114806Z","iopub.execute_input":"2023-01-08T20:30:01.115361Z","iopub.status.idle":"2023-01-08T20:30:01.194577Z","shell.execute_reply.started":"2023-01-08T20:30:01.115309Z","shell.execute_reply":"2023-01-08T20:30:01.193325Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Modeling","metadata":{}},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestClassifier","metadata":{"execution":{"iopub.status.busy":"2023-01-08T20:30:01.198800Z","iopub.execute_input":"2023-01-08T20:30:01.199249Z","iopub.status.idle":"2023-01-08T20:30:01.205448Z","shell.execute_reply.started":"2023-01-08T20:30:01.199205Z","shell.execute_reply":"2023-01-08T20:30:01.203874Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Selecting data**","metadata":{}},{"cell_type":"code","source":"y = train_data[\"target\"]\n\nX= train_data.drop(columns=[\"id\",\"f_27\", \"target\"])\nX_test = test_data.drop(columns=[\"id\",\"f_27\"])","metadata":{"execution":{"iopub.status.busy":"2023-01-08T20:30:01.207354Z","iopub.execute_input":"2023-01-08T20:30:01.207855Z","iopub.status.idle":"2023-01-08T20:30:01.303473Z","shell.execute_reply.started":"2023-01-08T20:30:01.207807Z","shell.execute_reply":"2023-01-08T20:30:01.302000Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Building model**","metadata":{}},{"cell_type":"code","source":"model = RandomForestClassifier(n_estimators=250, n_jobs=-1, random_state=1)\nmodel.fit(X, y)\npredictions = model.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2023-01-08T20:30:01.304758Z","iopub.execute_input":"2023-01-08T20:30:01.305284Z","iopub.status.idle":"2023-01-08T20:44:02.722808Z","shell.execute_reply.started":"2023-01-08T20:30:01.305236Z","shell.execute_reply":"2023-01-08T20:44:02.721374Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Creating submission file","metadata":{}},{"cell_type":"code","source":"sub = pd.read_csv(\"/kaggle/input/emsi-5iir-ds/sample_submission.csv\")\nsub.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-08T20:44:02.724181Z","iopub.execute_input":"2023-01-08T20:44:02.724566Z","iopub.status.idle":"2023-01-08T20:44:02.955512Z","shell.execute_reply.started":"2023-01-08T20:44:02.724533Z","shell.execute_reply":"2023-01-08T20:44:02.954134Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"output = pd.DataFrame({'id': test_data.id, 'target': predictions})\noutput.to_csv('final_submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2023-01-08T20:44:02.957196Z","iopub.execute_input":"2023-01-08T20:44:02.958490Z","iopub.status.idle":"2023-01-08T20:44:03.696100Z","shell.execute_reply.started":"2023-01-08T20:44:02.958434Z","shell.execute_reply":"2023-01-08T20:44:03.694596Z"},"trusted":true},"execution_count":null,"outputs":[]}]}