{"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\nimport numpy as np\nfrom matplotlib import pyplot as plt\nimport seaborn as sns\ntrain_df=pd.read_csv('../input/railofy-challenge/Railofy_training_data_for_model.csv')\ntest_df=pd.read_csv('../input/railofy-challenge/Railofy_testing_data_for_model.csv')\nsub_df=pd.read_csv('../input/railofy-challenge/sample_submission.csv')","metadata":{"execution":{"iopub.status.busy":"2022-07-10T18:49:25.190952Z","iopub.execute_input":"2022-07-10T18:49:25.191521Z","iopub.status.idle":"2022-07-10T18:49:26.279691Z","shell.execute_reply.started":"2022-07-10T18:49:25.191405Z","shell.execute_reply":"2022-07-10T18:49:26.278619Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.set_option('display.max_columns',None)","metadata":{"execution":{"iopub.status.busy":"2022-07-10T18:49:26.282010Z","iopub.execute_input":"2022-07-10T18:49:26.282348Z","iopub.status.idle":"2022-07-10T18:49:26.287637Z","shell.execute_reply.started":"2022-07-10T18:49:26.282318Z","shell.execute_reply":"2022-07-10T18:49:26.285919Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-10T18:49:26.289631Z","iopub.execute_input":"2022-07-10T18:49:26.290397Z","iopub.status.idle":"2022-07-10T18:49:26.322577Z","shell.execute_reply.started":"2022-07-10T18:49:26.290296Z","shell.execute_reply":"2022-07-10T18:49:26.321605Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-10T18:49:26.324128Z","iopub.execute_input":"2022-07-10T18:49:26.324465Z","iopub.status.idle":"2022-07-10T18:49:26.332871Z","shell.execute_reply.started":"2022-07-10T18:49:26.324431Z","shell.execute_reply":"2022-07-10T18:49:26.331884Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-10T18:49:26.335908Z","iopub.execute_input":"2022-07-10T18:49:26.336334Z","iopub.status.idle":"2022-07-10T18:49:26.360775Z","shell.execute_reply.started":"2022-07-10T18:49:26.336297Z","shell.execute_reply":"2022-07-10T18:49:26.359918Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-10T18:49:26.362207Z","iopub.execute_input":"2022-07-10T18:49:26.362554Z","iopub.status.idle":"2022-07-10T18:49:26.368729Z","shell.execute_reply.started":"2022-07-10T18:49:26.362521Z","shell.execute_reply":"2022-07-10T18:49:26.367676Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_df.tail()","metadata":{"execution":{"iopub.status.busy":"2022-07-10T18:49:26.370273Z","iopub.execute_input":"2022-07-10T18:49:26.370869Z","iopub.status.idle":"2022-07-10T18:49:26.382503Z","shell.execute_reply.started":"2022-07-10T18:49:26.370832Z","shell.execute_reply":"2022-07-10T18:49:26.380707Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_df.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-10T18:49:26.383580Z","iopub.execute_input":"2022-07-10T18:49:26.383996Z","iopub.status.idle":"2022-07-10T18:49:26.390530Z","shell.execute_reply.started":"2022-07-10T18:49:26.383960Z","shell.execute_reply":"2022-07-10T18:49:26.389325Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df=train_df.drop(columns='pk',axis=1)\ntrain_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-10T18:51:07.645927Z","iopub.execute_input":"2022-07-10T18:51:07.646430Z","iopub.status.idle":"2022-07-10T18:51:07.697664Z","shell.execute_reply.started":"2022-07-10T18:51:07.646382Z","shell.execute_reply":"2022-07-10T18:51:07.696738Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['QT'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-10T18:51:26.564436Z","iopub.execute_input":"2022-07-10T18:51:26.564980Z","iopub.status.idle":"2022-07-10T18:51:26.599671Z","shell.execute_reply.started":"2022-07-10T18:51:26.564934Z","shell.execute_reply":"2022-07-10T18:51:26.598760Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['target'].value_counts(normalize=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-10T18:54:36.955409Z","iopub.execute_input":"2022-07-10T18:54:36.955876Z","iopub.status.idle":"2022-07-10T18:54:36.964994Z","shell.execute_reply.started":"2022-07-10T18:54:36.955839Z","shell.execute_reply":"2022-07-10T18:54:36.964011Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x=train_df.drop(columns='target',axis=1)\ny=train_df['target']","metadata":{"execution":{"iopub.status.busy":"2022-07-10T18:55:03.996168Z","iopub.execute_input":"2022-07-10T18:55:03.996537Z","iopub.status.idle":"2022-07-10T18:55:04.007168Z","shell.execute_reply.started":"2022-07-10T18:55:03.996504Z","shell.execute_reply":"2022-07-10T18:55:04.006203Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_features=[0]","metadata":{"execution":{"iopub.status.busy":"2022-07-10T18:56:49.255601Z","iopub.execute_input":"2022-07-10T18:56:49.255966Z","iopub.status.idle":"2022-07-10T18:56:49.260246Z","shell.execute_reply.started":"2022-07-10T18:56:49.255934Z","shell.execute_reply":"2022-07-10T18:56:49.259358Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from catboost import CatBoostClassifier\ncat=CatBoostClassifier(cat_features=cat_features)","metadata":{"execution":{"iopub.status.busy":"2022-07-10T18:56:51.174689Z","iopub.execute_input":"2022-07-10T18:56:51.175034Z","iopub.status.idle":"2022-07-10T18:56:51.527643Z","shell.execute_reply.started":"2022-07-10T18:56:51.175000Z","shell.execute_reply":"2022-07-10T18:56:51.526734Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"iterations=[500]\nlearning_rate=[0.01,0.03,0.001]\ndepth=[int(x) for x in np.linspace(4,12,3)]\nl2_leaf_reg=[3,6]\nloss_function=['LogLoss','CrossEntropy']","metadata":{"execution":{"iopub.status.busy":"2022-07-10T19:05:21.775733Z","iopub.execute_input":"2022-07-10T19:05:21.776085Z","iopub.status.idle":"2022-07-10T19:05:21.782272Z","shell.execute_reply.started":"2022-07-10T19:05:21.776055Z","shell.execute_reply":"2022-07-10T19:05:21.781291Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"grid={\n    \n    'iterations':iterations,\n    'learning_rate':learning_rate,\n    'depth':depth,\n    'l2_leaf_reg':l2_leaf_reg,\n    'loss_function':loss_function\n    \n    }","metadata":{"execution":{"iopub.status.busy":"2022-07-10T19:05:23.577635Z","iopub.execute_input":"2022-07-10T19:05:23.577976Z","iopub.status.idle":"2022-07-10T19:05:23.583638Z","shell.execute_reply.started":"2022-07-10T19:05:23.577946Z","shell.execute_reply":"2022-07-10T19:05:23.582662Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import GridSearchCV\ncat_grid=GridSearchCV(estimator=cat,param_grid=grid)","metadata":{"execution":{"iopub.status.busy":"2022-07-10T19:05:25.847755Z","iopub.execute_input":"2022-07-10T19:05:25.848339Z","iopub.status.idle":"2022-07-10T19:05:25.853604Z","shell.execute_reply.started":"2022-07-10T19:05:25.848293Z","shell.execute_reply":"2022-07-10T19:05:25.852511Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_grid.fit(x,y)","metadata":{"execution":{"iopub.status.busy":"2022-07-10T19:05:28.497723Z","iopub.execute_input":"2022-07-10T19:05:28.498419Z","iopub.status.idle":"2022-07-10T20:39:29.719262Z","shell.execute_reply.started":"2022-07-10T19:05:28.498380Z","shell.execute_reply":"2022-07-10T20:39:29.718317Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_grid.best_score_","metadata":{"execution":{"iopub.status.busy":"2022-07-10T20:44:52.604640Z","iopub.execute_input":"2022-07-10T20:44:52.604989Z","iopub.status.idle":"2022-07-10T20:44:52.611359Z","shell.execute_reply.started":"2022-07-10T20:44:52.604959Z","shell.execute_reply":"2022-07-10T20:44:52.610183Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_grid.best_params_","metadata":{"execution":{"iopub.status.busy":"2022-07-10T20:46:21.945169Z","iopub.execute_input":"2022-07-10T20:46:21.945792Z","iopub.status.idle":"2022-07-10T20:46:21.952548Z","shell.execute_reply.started":"2022-07-10T20:46:21.945753Z","shell.execute_reply":"2022-07-10T20:46:21.951609Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"best_grid=cat_grid.best_estimator_\nbest_grid","metadata":{"execution":{"iopub.status.busy":"2022-07-10T20:45:46.246467Z","iopub.execute_input":"2022-07-10T20:45:46.246810Z","iopub.status.idle":"2022-07-10T20:45:46.253286Z","shell.execute_reply.started":"2022-07-10T20:45:46.246780Z","shell.execute_reply":"2022-07-10T20:45:46.252263Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-10T20:47:16.745744Z","iopub.execute_input":"2022-07-10T20:47:16.746131Z","iopub.status.idle":"2022-07-10T20:47:16.769814Z","shell.execute_reply.started":"2022-07-10T20:47:16.746096Z","shell.execute_reply":"2022-07-10T20:47:16.768791Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test=test_df.copy()","metadata":{"execution":{"iopub.status.busy":"2022-07-10T20:47:33.218210Z","iopub.execute_input":"2022-07-10T20:47:33.219158Z","iopub.status.idle":"2022-07-10T20:47:33.224324Z","shell.execute_reply.started":"2022-07-10T20:47:33.219118Z","shell.execute_reply":"2022-07-10T20:47:33.223134Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df=test_df.drop(columns='pk',axis=1)\ntest_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-10T20:48:06.445556Z","iopub.execute_input":"2022-07-10T20:48:06.445907Z","iopub.status.idle":"2022-07-10T20:48:06.470310Z","shell.execute_reply.started":"2022-07-10T20:48:06.445875Z","shell.execute_reply":"2022-07-10T20:48:06.469263Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred=best_grid.predict(test_df)\ny_pred","metadata":{"execution":{"iopub.status.busy":"2022-07-10T20:48:26.395207Z","iopub.execute_input":"2022-07-10T20:48:26.395812Z","iopub.status.idle":"2022-07-10T20:48:26.413055Z","shell.execute_reply.started":"2022-07-10T20:48:26.395774Z","shell.execute_reply":"2022-07-10T20:48:26.412030Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-10T20:48:42.068998Z","iopub.execute_input":"2022-07-10T20:48:42.069515Z","iopub.status.idle":"2022-07-10T20:48:42.089877Z","shell.execute_reply.started":"2022-07-10T20:48:42.069468Z","shell.execute_reply":"2022-07-10T20:48:42.088970Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub=pd.DataFrame({'pk':test['pk'],'target':y_pred})\nsub.sample(10)","metadata":{"execution":{"iopub.status.busy":"2022-07-10T20:50:00.659724Z","iopub.execute_input":"2022-07-10T20:50:00.660068Z","iopub.status.idle":"2022-07-10T20:50:00.670836Z","shell.execute_reply.started":"2022-07-10T20:50:00.660036Z","shell.execute_reply":"2022-07-10T20:50:00.669914Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub.to_csv('subbbb.csv',index=None)","metadata":{"execution":{"iopub.status.busy":"2022-07-10T20:50:24.201735Z","iopub.execute_input":"2022-07-10T20:50:24.202080Z","iopub.status.idle":"2022-07-10T20:50:24.216515Z","shell.execute_reply.started":"2022-07-10T20:50:24.202049Z","shell.execute_reply":"2022-07-10T20:50:24.215562Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.read_csv('./subbbb.csv')","metadata":{"execution":{"iopub.status.busy":"2022-07-10T20:50:57.901720Z","iopub.execute_input":"2022-07-10T20:50:57.902066Z","iopub.status.idle":"2022-07-10T20:50:57.917055Z","shell.execute_reply.started":"2022-07-10T20:50:57.902034Z","shell.execute_reply":"2022-07-10T20:50:57.916119Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}