{"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\ntrain_df=pd.read_csv('../input/titanic/train.csv')\ntest_df=pd.read_csv('../input/titanic/test.csv')\nsub_df=pd.read_csv('../input/titanic/gender_submission.csv')","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:36.645293Z","iopub.execute_input":"2022-07-26T16:09:36.645873Z","iopub.status.idle":"2022-07-26T16:09:36.665866Z","shell.execute_reply.started":"2022-07-26T16:09:36.645835Z","shell.execute_reply":"2022-07-26T16:09:36.665003Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:36.667287Z","iopub.execute_input":"2022-07-26T16:09:36.671329Z","iopub.status.idle":"2022-07-26T16:09:36.696058Z","shell.execute_reply.started":"2022-07-26T16:09:36.671297Z","shell.execute_reply":"2022-07-26T16:09:36.694615Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:36.697558Z","iopub.execute_input":"2022-07-26T16:09:36.697973Z","iopub.status.idle":"2022-07-26T16:09:36.722519Z","shell.execute_reply.started":"2022-07-26T16:09:36.697934Z","shell.execute_reply":"2022-07-26T16:09:36.721362Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_df","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:36.725224Z","iopub.execute_input":"2022-07-26T16:09:36.725642Z","iopub.status.idle":"2022-07-26T16:09:36.736444Z","shell.execute_reply.started":"2022-07-26T16:09:36.725607Z","shell.execute_reply":"2022-07-26T16:09:36.735207Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:36.738258Z","iopub.execute_input":"2022-07-26T16:09:36.739096Z","iopub.status.idle":"2022-07-26T16:09:36.749846Z","shell.execute_reply.started":"2022-07-26T16:09:36.739058Z","shell.execute_reply":"2022-07-26T16:09:36.748453Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df=train_df.drop(columns=['PassengerId','Name','Ticket','Cabin'],axis=1)\ntrain_df","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:36.751487Z","iopub.execute_input":"2022-07-26T16:09:36.751833Z","iopub.status.idle":"2022-07-26T16:09:36.774924Z","shell.execute_reply.started":"2022-07-26T16:09:36.751799Z","shell.execute_reply":"2022-07-26T16:09:36.774009Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['Embarked'].mode()[0]","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:36.777811Z","iopub.execute_input":"2022-07-26T16:09:36.778050Z","iopub.status.idle":"2022-07-26T16:09:36.787824Z","shell.execute_reply.started":"2022-07-26T16:09:36.778028Z","shell.execute_reply":"2022-07-26T16:09:36.786731Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['Embarked'].fillna(train_df['Embarked'].mode()[0],inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:36.790787Z","iopub.execute_input":"2022-07-26T16:09:36.791018Z","iopub.status.idle":"2022-07-26T16:09:36.796652Z","shell.execute_reply.started":"2022-07-26T16:09:36.790996Z","shell.execute_reply":"2022-07-26T16:09:36.795108Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:36.798654Z","iopub.execute_input":"2022-07-26T16:09:36.799201Z","iopub.status.idle":"2022-07-26T16:09:36.811196Z","shell.execute_reply.started":"2022-07-26T16:09:36.799123Z","shell.execute_reply":"2022-07-26T16:09:36.810364Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"s=pd.get_dummies(train_df['Sex'],drop_first=True)\ns","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:36.814204Z","iopub.execute_input":"2022-07-26T16:09:36.814505Z","iopub.status.idle":"2022-07-26T16:09:36.828673Z","shell.execute_reply.started":"2022-07-26T16:09:36.814482Z","shell.execute_reply":"2022-07-26T16:09:36.827838Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df=pd.merge(train_df,s,left_index=True,right_index=True)\ntrain_df","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:36.896958Z","iopub.execute_input":"2022-07-26T16:09:36.897276Z","iopub.status.idle":"2022-07-26T16:09:36.922720Z","shell.execute_reply.started":"2022-07-26T16:09:36.897249Z","shell.execute_reply":"2022-07-26T16:09:36.921543Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"e=pd.get_dummies(train_df['Embarked'],drop_first=True)\ne","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:36.925122Z","iopub.execute_input":"2022-07-26T16:09:36.925567Z","iopub.status.idle":"2022-07-26T16:09:36.941174Z","shell.execute_reply.started":"2022-07-26T16:09:36.925531Z","shell.execute_reply":"2022-07-26T16:09:36.940299Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df=pd.merge(train_df,e,left_index=True,right_index=True)\ntrain_df","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:36.942480Z","iopub.execute_input":"2022-07-26T16:09:36.943211Z","iopub.status.idle":"2022-07-26T16:09:36.966937Z","shell.execute_reply.started":"2022-07-26T16:09:36.943152Z","shell.execute_reply":"2022-07-26T16:09:36.966119Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df=train_df.drop(columns=['Sex','Embarked'],axis=1)\ntrain_df","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:36.968153Z","iopub.execute_input":"2022-07-26T16:09:36.968582Z","iopub.status.idle":"2022-07-26T16:09:36.988952Z","shell.execute_reply.started":"2022-07-26T16:09:36.968546Z","shell.execute_reply":"2022-07-26T16:09:36.988128Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:36.991930Z","iopub.execute_input":"2022-07-26T16:09:36.992261Z","iopub.status.idle":"2022-07-26T16:09:37.004093Z","shell.execute_reply.started":"2022-07-26T16:09:36.992237Z","shell.execute_reply":"2022-07-26T16:09:37.003196Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.impute import KNNImputer\nknn=KNNImputer()","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:37.005797Z","iopub.execute_input":"2022-07-26T16:09:37.006294Z","iopub.status.idle":"2022-07-26T16:09:37.010941Z","shell.execute_reply.started":"2022-07-26T16:09:37.006258Z","shell.execute_reply":"2022-07-26T16:09:37.009958Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df_impute=knn.fit_transform(train_df)\ntrain_df_impute","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:37.012784Z","iopub.execute_input":"2022-07-26T16:09:37.013367Z","iopub.status.idle":"2022-07-26T16:09:37.042492Z","shell.execute_reply.started":"2022-07-26T16:09:37.013331Z","shell.execute_reply":"2022-07-26T16:09:37.041517Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df=pd.DataFrame(train_df_impute,columns=train_df.columns)\ntrain_df","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:37.045586Z","iopub.execute_input":"2022-07-26T16:09:37.048970Z","iopub.status.idle":"2022-07-26T16:09:37.084986Z","shell.execute_reply.started":"2022-07-26T16:09:37.048927Z","shell.execute_reply":"2022-07-26T16:09:37.084051Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:37.086113Z","iopub.execute_input":"2022-07-26T16:09:37.086641Z","iopub.status.idle":"2022-07-26T16:09:37.100913Z","shell.execute_reply.started":"2022-07-26T16:09:37.086608Z","shell.execute_reply":"2022-07-26T16:09:37.099980Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.corr()","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:37.102276Z","iopub.execute_input":"2022-07-26T16:09:37.102840Z","iopub.status.idle":"2022-07-26T16:09:37.125599Z","shell.execute_reply.started":"2022-07-26T16:09:37.102806Z","shell.execute_reply":"2022-07-26T16:09:37.124591Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x=train_df.drop(columns='Survived',axis=1)\ny=train_df['Survived']","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:37.126981Z","iopub.execute_input":"2022-07-26T16:09:37.127573Z","iopub.status.idle":"2022-07-26T16:09:37.145680Z","shell.execute_reply.started":"2022-07-26T16:09:37.127539Z","shell.execute_reply":"2022-07-26T16:09:37.144434Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:37.147153Z","iopub.execute_input":"2022-07-26T16:09:37.147524Z","iopub.status.idle":"2022-07-26T16:09:37.191860Z","shell.execute_reply.started":"2022-07-26T16:09:37.147450Z","shell.execute_reply":"2022-07-26T16:09:37.190926Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:37.196446Z","iopub.execute_input":"2022-07-26T16:09:37.197284Z","iopub.status.idle":"2022-07-26T16:09:37.209875Z","shell.execute_reply.started":"2022-07-26T16:09:37.197247Z","shell.execute_reply":"2022-07-26T16:09:37.208664Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:37.219341Z","iopub.execute_input":"2022-07-26T16:09:37.219673Z","iopub.status.idle":"2022-07-26T16:09:37.254253Z","shell.execute_reply.started":"2022-07-26T16:09:37.219640Z","shell.execute_reply":"2022-07-26T16:09:37.253225Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:37.258611Z","iopub.execute_input":"2022-07-26T16:09:37.258956Z","iopub.status.idle":"2022-07-26T16:09:37.275167Z","shell.execute_reply.started":"2022-07-26T16:09:37.258921Z","shell.execute_reply":"2022-07-26T16:09:37.273875Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df=test_df.drop(columns=['PassengerId','Name','Ticket','Cabin'],axis=1)\ntest_df","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:37.279480Z","iopub.execute_input":"2022-07-26T16:09:37.280127Z","iopub.status.idle":"2022-07-26T16:09:37.311495Z","shell.execute_reply.started":"2022-07-26T16:09:37.280091Z","shell.execute_reply":"2022-07-26T16:09:37.310612Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:37.315640Z","iopub.execute_input":"2022-07-26T16:09:37.318246Z","iopub.status.idle":"2022-07-26T16:09:37.332212Z","shell.execute_reply.started":"2022-07-26T16:09:37.318209Z","shell.execute_reply":"2022-07-26T16:09:37.331060Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"s=pd.get_dummies(test_df['Sex'],drop_first=True)\ns","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:37.337063Z","iopub.execute_input":"2022-07-26T16:09:37.337807Z","iopub.status.idle":"2022-07-26T16:09:37.356616Z","shell.execute_reply.started":"2022-07-26T16:09:37.337772Z","shell.execute_reply":"2022-07-26T16:09:37.355686Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df=pd.merge(test_df,s,left_index=True,right_index=True)\ntest_df","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:37.360665Z","iopub.execute_input":"2022-07-26T16:09:37.363609Z","iopub.status.idle":"2022-07-26T16:09:37.391835Z","shell.execute_reply.started":"2022-07-26T16:09:37.363572Z","shell.execute_reply":"2022-07-26T16:09:37.390929Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"e=pd.get_dummies(test_df['Embarked'],drop_first=True)\ne","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:37.396464Z","iopub.execute_input":"2022-07-26T16:09:37.399040Z","iopub.status.idle":"2022-07-26T16:09:37.417783Z","shell.execute_reply.started":"2022-07-26T16:09:37.398998Z","shell.execute_reply":"2022-07-26T16:09:37.416882Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df=pd.merge(test_df,e,left_index=True,right_index=True)\ntest_df","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:37.421671Z","iopub.execute_input":"2022-07-26T16:09:37.424604Z","iopub.status.idle":"2022-07-26T16:09:37.454889Z","shell.execute_reply.started":"2022-07-26T16:09:37.424556Z","shell.execute_reply":"2022-07-26T16:09:37.453869Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.drop(columns=['Sex','Embarked'],axis=1,inplace=True)\ntest_df","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:37.459281Z","iopub.execute_input":"2022-07-26T16:09:37.461812Z","iopub.status.idle":"2022-07-26T16:09:37.488603Z","shell.execute_reply.started":"2022-07-26T16:09:37.461776Z","shell.execute_reply":"2022-07-26T16:09:37.487784Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:37.492703Z","iopub.execute_input":"2022-07-26T16:09:37.495346Z","iopub.status.idle":"2022-07-26T16:09:37.508872Z","shell.execute_reply.started":"2022-07-26T16:09:37.495298Z","shell.execute_reply":"2022-07-26T16:09:37.507725Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df_impute=knn.fit_transform(test_df)\ntest_df_impute","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:37.512853Z","iopub.execute_input":"2022-07-26T16:09:37.513361Z","iopub.status.idle":"2022-07-26T16:09:37.546434Z","shell.execute_reply.started":"2022-07-26T16:09:37.513325Z","shell.execute_reply":"2022-07-26T16:09:37.545552Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df=pd.DataFrame(test_df_impute,columns=test_df.columns)\ntest_df","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:37.550687Z","iopub.execute_input":"2022-07-26T16:09:37.554060Z","iopub.status.idle":"2022-07-26T16:09:37.613388Z","shell.execute_reply.started":"2022-07-26T16:09:37.554022Z","shell.execute_reply":"2022-07-26T16:09:37.612485Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from catboost import CatBoostClassifier\ncat=CatBoostClassifier()","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:37.618002Z","iopub.execute_input":"2022-07-26T16:09:37.621518Z","iopub.status.idle":"2022-07-26T16:09:37.630138Z","shell.execute_reply.started":"2022-07-26T16:09:37.621481Z","shell.execute_reply":"2022-07-26T16:09:37.629050Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import RandomizedSearchCV\nfrom sklearn.model_selection import GridSearchCV","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:37.636607Z","iopub.execute_input":"2022-07-26T16:09:37.639341Z","iopub.status.idle":"2022-07-26T16:09:37.647388Z","shell.execute_reply.started":"2022-07-26T16:09:37.639304Z","shell.execute_reply":"2022-07-26T16:09:37.646382Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"iterations=[500,1000]\nlearning_rate=[0.03,0.001]\ndepth=[6,8,11]\nloss_function=['LogLoss','CrossEntropy']\nborder_count=[12,10]","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:37.653385Z","iopub.execute_input":"2022-07-26T16:09:37.656017Z","iopub.status.idle":"2022-07-26T16:09:37.667111Z","shell.execute_reply.started":"2022-07-26T16:09:37.655664Z","shell.execute_reply":"2022-07-26T16:09:37.665533Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"param_grid={'iterations':iterations,\n           'learning_rate':learning_rate,\n           'depth':depth,\n           'loss_function':loss_function,\n           'border_count':border_count\n           }","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:37.670338Z","iopub.execute_input":"2022-07-26T16:09:37.671412Z","iopub.status.idle":"2022-07-26T16:09:37.680986Z","shell.execute_reply.started":"2022-07-26T16:09:37.671386Z","shell.execute_reply":"2022-07-26T16:09:37.679701Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(param_grid)","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:37.682697Z","iopub.execute_input":"2022-07-26T16:09:37.683033Z","iopub.status.idle":"2022-07-26T16:09:37.694371Z","shell.execute_reply.started":"2022-07-26T16:09:37.682999Z","shell.execute_reply":"2022-07-26T16:09:37.693145Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"num_combinations=1\nfor k in param_grid.keys():\n    num_combinations*=len(param_grid[k])\n    \nprint('No. of combinations',num_combinations)","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:37.696082Z","iopub.execute_input":"2022-07-26T16:09:37.696492Z","iopub.status.idle":"2022-07-26T16:09:37.704578Z","shell.execute_reply.started":"2022-07-26T16:09:37.696456Z","shell.execute_reply":"2022-07-26T16:09:37.703323Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_random_grid=RandomizedSearchCV(estimator=cat,param_distributions=param_grid)","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:37.706296Z","iopub.execute_input":"2022-07-26T16:09:37.706642Z","iopub.status.idle":"2022-07-26T16:09:37.711891Z","shell.execute_reply.started":"2022-07-26T16:09:37.706609Z","shell.execute_reply":"2022-07-26T16:09:37.710862Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_random_grid.fit(x,y)","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:37.713637Z","iopub.execute_input":"2022-07-26T16:09:37.714024Z","iopub.status.idle":"2022-07-26T16:09:48.986995Z","shell.execute_reply.started":"2022-07-26T16:09:37.713988Z","shell.execute_reply":"2022-07-26T16:09:48.986016Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_random_grid.best_params_","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:48.988499Z","iopub.execute_input":"2022-07-26T16:09:48.989081Z","iopub.status.idle":"2022-07-26T16:09:48.995636Z","shell.execute_reply.started":"2022-07-26T16:09:48.989043Z","shell.execute_reply":"2022-07-26T16:09:48.994724Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_random_grid.best_score_","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:48.997178Z","iopub.execute_input":"2022-07-26T16:09:48.997992Z","iopub.status.idle":"2022-07-26T16:09:49.006837Z","shell.execute_reply.started":"2022-07-26T16:09:48.997955Z","shell.execute_reply":"2022-07-26T16:09:49.005830Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"best_random=cat_random_grid.best_estimator_\nbest_random","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:49.008297Z","iopub.execute_input":"2022-07-26T16:09:49.008713Z","iopub.status.idle":"2022-07-26T16:09:49.016597Z","shell.execute_reply.started":"2022-07-26T16:09:49.008666Z","shell.execute_reply":"2022-07-26T16:09:49.015117Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred=best_random.predict(test_df)\ny_pred","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:49.018090Z","iopub.execute_input":"2022-07-26T16:09:49.018520Z","iopub.status.idle":"2022-07-26T16:09:49.032508Z","shell.execute_reply.started":"2022-07-26T16:09:49.018484Z","shell.execute_reply":"2022-07-26T16:09:49.031548Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_df","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:49.035038Z","iopub.execute_input":"2022-07-26T16:09:49.035541Z","iopub.status.idle":"2022-07-26T16:09:49.047126Z","shell.execute_reply.started":"2022-07-26T16:09:49.035505Z","shell.execute_reply":"2022-07-26T16:09:49.045998Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub1=pd.DataFrame({'PassengerId':sub_df['PassengerId'],'Survived':y_pred})\nsub1","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:49.048686Z","iopub.execute_input":"2022-07-26T16:09:49.049025Z","iopub.status.idle":"2022-07-26T16:09:49.060843Z","shell.execute_reply.started":"2022-07-26T16:09:49.048991Z","shell.execute_reply":"2022-07-26T16:09:49.059850Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub1['Survived'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:49.062187Z","iopub.execute_input":"2022-07-26T16:09:49.062856Z","iopub.status.idle":"2022-07-26T16:09:49.072309Z","shell.execute_reply.started":"2022-07-26T16:09:49.062820Z","shell.execute_reply":"2022-07-26T16:09:49.071144Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub1.to_csv('tianic1.csv',index=None)","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:49.079381Z","iopub.execute_input":"2022-07-26T16:09:49.079621Z","iopub.status.idle":"2022-07-26T16:09:49.086477Z","shell.execute_reply.started":"2022-07-26T16:09:49.079598Z","shell.execute_reply":"2022-07-26T16:09:49.085411Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(param_grid)","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:49.088389Z","iopub.execute_input":"2022-07-26T16:09:49.089031Z","iopub.status.idle":"2022-07-26T16:09:49.095268Z","shell.execute_reply.started":"2022-07-26T16:09:49.088995Z","shell.execute_reply":"2022-07-26T16:09:49.094198Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_grid=GridSearchCV(estimator=cat,param_grid=param_grid)\ncat_grid","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:49.096694Z","iopub.execute_input":"2022-07-26T16:09:49.097783Z","iopub.status.idle":"2022-07-26T16:09:49.106810Z","shell.execute_reply.started":"2022-07-26T16:09:49.097706Z","shell.execute_reply":"2022-07-26T16:09:49.105733Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_grid.fit(x,y)","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:09:49.108324Z","iopub.execute_input":"2022-07-26T16:09:49.108775Z","iopub.status.idle":"2022-07-26T16:11:10.422616Z","shell.execute_reply.started":"2022-07-26T16:09:49.108740Z","shell.execute_reply":"2022-07-26T16:11:10.421555Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_grid.best_score_","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:11:10.424058Z","iopub.execute_input":"2022-07-26T16:11:10.424435Z","iopub.status.idle":"2022-07-26T16:11:10.430565Z","shell.execute_reply.started":"2022-07-26T16:11:10.424398Z","shell.execute_reply":"2022-07-26T16:11:10.429606Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_grid.best_params_","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:11:10.431986Z","iopub.execute_input":"2022-07-26T16:11:10.432582Z","iopub.status.idle":"2022-07-26T16:11:10.442128Z","shell.execute_reply.started":"2022-07-26T16:11:10.432544Z","shell.execute_reply":"2022-07-26T16:11:10.441211Z"},"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-26T16:11:10.443680Z","iopub.execute_input":"2022-07-26T16:11:10.444047Z","iopub.status.idle":"2022-07-26T16:11:10.451985Z","shell.execute_reply.started":"2022-07-26T16:11:10.444011Z","shell.execute_reply":"2022-07-26T16:11:10.450933Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred2=best_grid.predict(test_df)","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:11:10.453694Z","iopub.execute_input":"2022-07-26T16:11:10.454028Z","iopub.status.idle":"2022-07-26T16:11:10.464076Z","shell.execute_reply.started":"2022-07-26T16:11:10.453993Z","shell.execute_reply":"2022-07-26T16:11:10.462997Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred2","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:11:10.465792Z","iopub.execute_input":"2022-07-26T16:11:10.466218Z","iopub.status.idle":"2022-07-26T16:11:10.475314Z","shell.execute_reply.started":"2022-07-26T16:11:10.466180Z","shell.execute_reply":"2022-07-26T16:11:10.474222Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub2=pd.DataFrame({'PassengerId':sub_df['PassengerId'],'Survived':y_pred2})\nsub2","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:11:10.477091Z","iopub.execute_input":"2022-07-26T16:11:10.477586Z","iopub.status.idle":"2022-07-26T16:11:10.491443Z","shell.execute_reply.started":"2022-07-26T16:11:10.477416Z","shell.execute_reply":"2022-07-26T16:11:10.490373Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub2['Survived'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:11:10.492980Z","iopub.execute_input":"2022-07-26T16:11:10.494387Z","iopub.status.idle":"2022-07-26T16:11:10.503310Z","shell.execute_reply.started":"2022-07-26T16:11:10.494351Z","shell.execute_reply":"2022-07-26T16:11:10.502248Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub2.to_csv('titanic2.csv',index=None)","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:11:10.504866Z","iopub.execute_input":"2022-07-26T16:11:10.506875Z","iopub.status.idle":"2022-07-26T16:11:10.513074Z","shell.execute_reply.started":"2022-07-26T16:11:10.506840Z","shell.execute_reply":"2022-07-26T16:11:10.512096Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:11:52.256023Z","iopub.execute_input":"2022-07-26T16:11:52.256970Z","iopub.status.idle":"2022-07-26T16:11:52.281251Z","shell.execute_reply.started":"2022-07-26T16:11:52.256918Z","shell.execute_reply":"2022-07-26T16:11:52.280306Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:17:05.764111Z","iopub.execute_input":"2022-07-26T16:17:05.764730Z","iopub.status.idle":"2022-07-26T16:17:05.796436Z","shell.execute_reply.started":"2022-07-26T16:17:05.764684Z","shell.execute_reply":"2022-07-26T16:17:05.795341Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import MinMaxScaler\nmmc=MinMaxScaler(feature_range=(0,1))\nx_scale=mmc.fit_transform(x)\nx_scale","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:17:08.763704Z","iopub.execute_input":"2022-07-26T16:17:08.764065Z","iopub.status.idle":"2022-07-26T16:17:08.775405Z","shell.execute_reply.started":"2022-07-26T16:17:08.764034Z","shell.execute_reply":"2022-07-26T16:17:08.774221Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x=pd.DataFrame(x_scale,columns=x.columns)\nx","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:17:30.754296Z","iopub.execute_input":"2022-07-26T16:17:30.754658Z","iopub.status.idle":"2022-07-26T16:17:30.778452Z","shell.execute_reply.started":"2022-07-26T16:17:30.754629Z","shell.execute_reply":"2022-07-26T16:17:30.777212Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import PowerTransformer\ntransformer = PowerTransformer()\nx_transform=transformer.fit_transform(x)\nx=pd.DataFrame(x_transform,columns=x.columns)\nx","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:18:46.119439Z","iopub.execute_input":"2022-07-26T16:18:46.119794Z","iopub.status.idle":"2022-07-26T16:18:46.166238Z","shell.execute_reply.started":"2022-07-26T16:18:46.119765Z","shell.execute_reply":"2022-07-26T16:18:46.165185Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x.mean()","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:18:56.429625Z","iopub.execute_input":"2022-07-26T16:18:56.429985Z","iopub.status.idle":"2022-07-26T16:18:56.440389Z","shell.execute_reply.started":"2022-07-26T16:18:56.429954Z","shell.execute_reply":"2022-07-26T16:18:56.439280Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x.std()","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:19:04.043888Z","iopub.execute_input":"2022-07-26T16:19:04.044721Z","iopub.status.idle":"2022-07-26T16:19:04.055396Z","shell.execute_reply.started":"2022-07-26T16:19:04.044664Z","shell.execute_reply":"2022-07-26T16:19:04.053874Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:19:09.693588Z","iopub.execute_input":"2022-07-26T16:19:09.693951Z","iopub.status.idle":"2022-07-26T16:19:09.718291Z","shell.execute_reply.started":"2022-07-26T16:19:09.693921Z","shell.execute_reply":"2022-07-26T16:19:09.717235Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_scale=mmc.transform(test_df)\ntest_scale","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:20:36.623388Z","iopub.execute_input":"2022-07-26T16:20:36.623740Z","iopub.status.idle":"2022-07-26T16:20:36.632501Z","shell.execute_reply.started":"2022-07-26T16:20:36.623704Z","shell.execute_reply":"2022-07-26T16:20:36.631226Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df=pd.DataFrame(test_scale,columns=test_df.columns)\ntest_df","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:21:02.324303Z","iopub.execute_input":"2022-07-26T16:21:02.324650Z","iopub.status.idle":"2022-07-26T16:21:02.344854Z","shell.execute_reply.started":"2022-07-26T16:21:02.324620Z","shell.execute_reply":"2022-07-26T16:21:02.342887Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_transform=transformer.transform(test_df)\ntest_df=pd.DataFrame(test_transform,columns=test_df.columns)\ntest_df","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:21:59.964249Z","iopub.execute_input":"2022-07-26T16:21:59.964899Z","iopub.status.idle":"2022-07-26T16:21:59.986926Z","shell.execute_reply.started":"2022-07-26T16:21:59.964862Z","shell.execute_reply":"2022-07-26T16:21:59.985930Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.mean()","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:22:10.194471Z","iopub.execute_input":"2022-07-26T16:22:10.195467Z","iopub.status.idle":"2022-07-26T16:22:10.205278Z","shell.execute_reply.started":"2022-07-26T16:22:10.195427Z","shell.execute_reply":"2022-07-26T16:22:10.204048Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.std()","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:22:52.744330Z","iopub.execute_input":"2022-07-26T16:22:52.744770Z","iopub.status.idle":"2022-07-26T16:22:52.755555Z","shell.execute_reply.started":"2022-07-26T16:22:52.744732Z","shell.execute_reply":"2022-07-26T16:22:52.754401Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_random_grid=RandomizedSearchCV(estimator=cat,param_distributions=param_grid)\ncat_random_grid","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:24:21.185402Z","iopub.execute_input":"2022-07-26T16:24:21.185757Z","iopub.status.idle":"2022-07-26T16:24:21.196206Z","shell.execute_reply.started":"2022-07-26T16:24:21.185728Z","shell.execute_reply":"2022-07-26T16:24:21.195235Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:24:42.584832Z","iopub.execute_input":"2022-07-26T16:24:42.585215Z","iopub.status.idle":"2022-07-26T16:24:42.606050Z","shell.execute_reply.started":"2022-07-26T16:24:42.585152Z","shell.execute_reply":"2022-07-26T16:24:42.605134Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_random_grid.fit(x,y)","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:24:47.803797Z","iopub.execute_input":"2022-07-26T16:24:47.804248Z"},"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":"best_grid=cat_random_grid.best_estimator_\nbest_grid","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:33:01.057038Z","iopub.execute_input":"2022-07-26T16:33:01.057970Z","iopub.status.idle":"2022-07-26T16:33:01.064644Z","shell.execute_reply.started":"2022-07-26T16:33:01.057927Z","shell.execute_reply":"2022-07-26T16:33:01.063559Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:33:12.956937Z","iopub.execute_input":"2022-07-26T16:33:12.957315Z","iopub.status.idle":"2022-07-26T16:33:12.974181Z","shell.execute_reply.started":"2022-07-26T16:33:12.957282Z","shell.execute_reply":"2022-07-26T16:33:12.972940Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred3=best_grid.predict(test_df)\ny_pred3","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:33:17.135707Z","iopub.execute_input":"2022-07-26T16:33:17.136058Z","iopub.status.idle":"2022-07-26T16:33:17.151645Z","shell.execute_reply.started":"2022-07-26T16:33:17.136027Z","shell.execute_reply":"2022-07-26T16:33:17.150462Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub3=pd.DataFrame({'PassengerId':sub_df['PassengerId'],'Survived':y_pred3})\nsub3","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:33:20.615778Z","iopub.execute_input":"2022-07-26T16:33:20.616797Z","iopub.status.idle":"2022-07-26T16:33:20.628521Z","shell.execute_reply.started":"2022-07-26T16:33:20.616748Z","shell.execute_reply":"2022-07-26T16:33:20.627408Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub3.to_csv('titanic3.csv',index=None)","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:33:24.515656Z","iopub.execute_input":"2022-07-26T16:33:24.516005Z","iopub.status.idle":"2022-07-26T16:33:24.526506Z","shell.execute_reply.started":"2022-07-26T16:33:24.515975Z","shell.execute_reply":"2022-07-26T16:33:24.525515Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}