{"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":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-07-15T11:46:30.686771Z","iopub.execute_input":"2022-07-15T11:46:30.687309Z","iopub.status.idle":"2022-07-15T11:46:30.724330Z","shell.execute_reply.started":"2022-07-15T11:46:30.687200Z","shell.execute_reply":"2022-07-15T11:46:30.723321Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data=pd.read_csv('/kaggle/input/titanic/train.csv')","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:30.726062Z","iopub.execute_input":"2022-07-15T11:46:30.726287Z","iopub.status.idle":"2022-07-15T11:46:30.745577Z","shell.execute_reply.started":"2022-07-15T11:46:30.726260Z","shell.execute_reply":"2022-07-15T11:46:30.744898Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:30.746950Z","iopub.execute_input":"2022-07-15T11:46:30.747985Z","iopub.status.idle":"2022-07-15T11:46:30.784675Z","shell.execute_reply.started":"2022-07-15T11:46:30.747902Z","shell.execute_reply":"2022-07-15T11:46:30.784012Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.head(8)","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:30.786254Z","iopub.execute_input":"2022-07-15T11:46:30.786580Z","iopub.status.idle":"2022-07-15T11:46:30.804739Z","shell.execute_reply.started":"2022-07-15T11:46:30.786552Z","shell.execute_reply":"2022-07-15T11:46:30.804115Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#display the removed column\nx=data.drop(columns=['Survived'])\nx","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:30.806178Z","iopub.execute_input":"2022-07-15T11:46:30.806696Z","iopub.status.idle":"2022-07-15T11:46:30.836201Z","shell.execute_reply.started":"2022-07-15T11:46:30.806662Z","shell.execute_reply":"2022-07-15T11:46:30.835310Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y=data.Survived\ny.head(8)","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:30.837265Z","iopub.execute_input":"2022-07-15T11:46:30.837482Z","iopub.status.idle":"2022-07-15T11:46:30.846936Z","shell.execute_reply.started":"2022-07-15T11:46:30.837457Z","shell.execute_reply":"2022-07-15T11:46:30.845999Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y = data.iloc[:,10]","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:30.848082Z","iopub.execute_input":"2022-07-15T11:46:30.848835Z","iopub.status.idle":"2022-07-15T11:46:30.857595Z","shell.execute_reply.started":"2022-07-15T11:46:30.848802Z","shell.execute_reply":"2022-07-15T11:46:30.856853Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:30.858493Z","iopub.execute_input":"2022-07-15T11:46:30.859042Z","iopub.status.idle":"2022-07-15T11:46:30.873591Z","shell.execute_reply.started":"2022-07-15T11:46:30.859007Z","shell.execute_reply":"2022-07-15T11:46:30.872471Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split #sklean is a library and importing the modelselection and train_test_split\nx_train,x_test,y_train,y_test = train_test_split(x,y,test_size = 0.3) #x and y are variables, y is the heart disease and for x_test and y_test will be test size by 30% data will be assigned \n#x_train and y_train will be 70% data.","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:30.874699Z","iopub.execute_input":"2022-07-15T11:46:30.874979Z","iopub.status.idle":"2022-07-15T11:46:32.000814Z","shell.execute_reply.started":"2022-07-15T11:46:30.874943Z","shell.execute_reply":"2022-07-15T11:46:31.999982Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:32.003998Z","iopub.execute_input":"2022-07-15T11:46:32.004234Z","iopub.status.idle":"2022-07-15T11:46:32.029611Z","shell.execute_reply.started":"2022-07-15T11:46:32.004205Z","shell.execute_reply":"2022-07-15T11:46:32.028998Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.Embarked.unique()\ndata['Embarked_s']=data['Embarked'].replace('Q',0).replace('C',0).replace('S',1)\ndata['Embarked_c']=data['Embarked'].replace('S',0).replace('Q',0).replace('C',1)\ndata['Embarked_q']=data['Embarked'].replace('C',0).replace('S',0).replace('Q',1)","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:32.030513Z","iopub.execute_input":"2022-07-15T11:46:32.031066Z","iopub.status.idle":"2022-07-15T11:46:32.045353Z","shell.execute_reply.started":"2022-07-15T11:46:32.031034Z","shell.execute_reply":"2022-07-15T11:46:32.044693Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#data.Sex= data.Sex.map( {'M': 1, 'F': 0, 'O': 3} )\ndata['Sex'].replace( 'female', 0, inplace=True )\ndata['Sex'].replace( 'male', 1, inplace=True )\ndata","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:32.046462Z","iopub.execute_input":"2022-07-15T11:46:32.047255Z","iopub.status.idle":"2022-07-15T11:46:32.081363Z","shell.execute_reply.started":"2022-07-15T11:46:32.047211Z","shell.execute_reply":"2022-07-15T11:46:32.080712Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#data=data[data.Embarked!=0]\n#data=data[data[('Embarked')].map(data['Embarked'].value_counts())>0]*\n#data","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:32.082652Z","iopub.execute_input":"2022-07-15T11:46:32.083088Z","iopub.status.idle":"2022-07-15T11:46:32.085755Z","shell.execute_reply.started":"2022-07-15T11:46:32.083055Z","shell.execute_reply":"2022-07-15T11:46:32.085188Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:32.087312Z","iopub.execute_input":"2022-07-15T11:46:32.087718Z","iopub.status.idle":"2022-07-15T11:46:32.108806Z","shell.execute_reply.started":"2022-07-15T11:46:32.087686Z","shell.execute_reply":"2022-07-15T11:46:32.108182Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#data.Sex=data.Sex.fillna(0)\n#data.Age=data.Age.fillna(0)\n#data.Cabin=data.Cabin.fillna(0)\n#data.Embarked_s=data.Embarked_s.fillna(0)\n#data.Embarked_c=data.Embarked_c.fillna(0)\n#data.Embarked_q=data.Embarked_q.fillna(0)","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:32.110051Z","iopub.execute_input":"2022-07-15T11:46:32.110691Z","iopub.status.idle":"2022-07-15T11:46:32.113856Z","shell.execute_reply.started":"2022-07-15T11:46:32.110649Z","shell.execute_reply":"2022-07-15T11:46:32.113244Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['Survived']","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:32.115090Z","iopub.execute_input":"2022-07-15T11:46:32.115849Z","iopub.status.idle":"2022-07-15T11:46:32.130154Z","shell.execute_reply.started":"2022-07-15T11:46:32.115812Z","shell.execute_reply":"2022-07-15T11:46:32.129348Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:32.133038Z","iopub.execute_input":"2022-07-15T11:46:32.133722Z","iopub.status.idle":"2022-07-15T11:46:32.145937Z","shell.execute_reply.started":"2022-07-15T11:46:32.133684Z","shell.execute_reply":"2022-07-15T11:46:32.145305Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.dtypes","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:32.147192Z","iopub.execute_input":"2022-07-15T11:46:32.148038Z","iopub.status.idle":"2022-07-15T11:46:32.156617Z","shell.execute_reply.started":"2022-07-15T11:46:32.147994Z","shell.execute_reply":"2022-07-15T11:46:32.155626Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x = data.drop(columns = ['Survived','Ticket','Cabin','PassengerId','Name','Embarked'])","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:32.157659Z","iopub.execute_input":"2022-07-15T11:46:32.158329Z","iopub.status.idle":"2022-07-15T11:46:32.169452Z","shell.execute_reply.started":"2022-07-15T11:46:32.158293Z","shell.execute_reply":"2022-07-15T11:46:32.168795Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y = data[['Survived']]","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:32.170687Z","iopub.execute_input":"2022-07-15T11:46:32.171075Z","iopub.status.idle":"2022-07-15T11:46:32.180218Z","shell.execute_reply.started":"2022-07-15T11:46:32.171030Z","shell.execute_reply":"2022-07-15T11:46:32.179485Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nx_train,x_test,y_train,y_test = train_test_split(x,y,test_size=0.25)","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:32.181397Z","iopub.execute_input":"2022-07-15T11:46:32.181826Z","iopub.status.idle":"2022-07-15T11:46:32.193378Z","shell.execute_reply.started":"2022-07-15T11:46:32.181782Z","shell.execute_reply":"2022-07-15T11:46:32.192633Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:32.197770Z","iopub.execute_input":"2022-07-15T11:46:32.198405Z","iopub.status.idle":"2022-07-15T11:46:32.213999Z","shell.execute_reply.started":"2022-07-15T11:46:32.198351Z","shell.execute_reply":"2022-07-15T11:46:32.213003Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x.dtypes","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:32.215425Z","iopub.execute_input":"2022-07-15T11:46:32.215652Z","iopub.status.idle":"2022-07-15T11:46:32.228084Z","shell.execute_reply.started":"2022-07-15T11:46:32.215626Z","shell.execute_reply":"2022-07-15T11:46:32.226874Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:32.229261Z","iopub.execute_input":"2022-07-15T11:46:32.230020Z","iopub.status.idle":"2022-07-15T11:46:32.254576Z","shell.execute_reply.started":"2022-07-15T11:46:32.229974Z","shell.execute_reply":"2022-07-15T11:46:32.253729Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x.Embarked_q.unique()","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:32.255987Z","iopub.execute_input":"2022-07-15T11:46:32.256678Z","iopub.status.idle":"2022-07-15T11:46:32.264317Z","shell.execute_reply.started":"2022-07-15T11:46:32.256640Z","shell.execute_reply":"2022-07-15T11:46:32.263480Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nom_cols =[]\nord_cols = []\nnum_cols=[0,4,5]\nnull_cols=[1,2,6,7,8]\n#Kbin_cols=[0,1,4],\nbinarizer_cols=[3]","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:32.265629Z","iopub.execute_input":"2022-07-15T11:46:32.265829Z","iopub.status.idle":"2022-07-15T11:46:32.275370Z","shell.execute_reply.started":"2022-07-15T11:46:32.265803Z","shell.execute_reply":"2022-07-15T11:46:32.274767Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import OneHotEncoder, OrdinalEncoder,KBinsDiscretizer,Binarizer\nfrom sklearn.impute import SimpleImputer,KNNImputer\nfrom sklearn.compose import make_column_transformer\nfrom sklearn import set_config\nfrom sklearn.preprocessing import StandardScaler\n\ntrans = make_column_transformer((OneHotEncoder(sparse=False),nom_cols),\n                                (KNNImputer(n_neighbors=45),null_cols),\n                                (OrdinalEncoder(), ord_cols),(StandardScaler(),num_cols)\n                                 ,(Binarizer(threshold=55),binarizer_cols),remainder= 'passthrough')\nset_config(display= 'diagram')\ntrans\n#trans = make_column_transformer((OneHotEncoder(sparse=False),nom_cols),(SimpleImputer(strategy='mean'),null_cols),\n                                 #(OrdinalEncoder(), ord_cols),(StandardScaler(),num_cols),(KBinsDiscretizer(),Kbins_cols)\n                                 #,(Binarizer(threshold=55),binarizer_cols),remainder= 'passthrough')\n#set_config(display= 'diagram')\n#trans","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:32.276570Z","iopub.execute_input":"2022-07-15T11:46:32.277183Z","iopub.status.idle":"2022-07-15T11:46:32.454703Z","shell.execute_reply.started":"2022-07-15T11:46:32.277137Z","shell.execute_reply":"2022-07-15T11:46:32.453897Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.tree import DecisionTreeClassifier \nalgorithm_x=DecisionTreeClassifier(criterion='entropy')","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:32.456247Z","iopub.execute_input":"2022-07-15T11:46:32.456725Z","iopub.status.idle":"2022-07-15T11:46:32.486985Z","shell.execute_reply.started":"2022-07-15T11:46:32.456682Z","shell.execute_reply":"2022-07-15T11:46:32.486335Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.neighbors import KNeighborsClassifier\nalgorithm = KNeighborsClassifier(15) #\nalgorithm","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:32.488387Z","iopub.execute_input":"2022-07-15T11:46:32.488855Z","iopub.status.idle":"2022-07-15T11:46:32.497776Z","shell.execute_reply.started":"2022-07-15T11:46:32.488812Z","shell.execute_reply":"2022-07-15T11:46:32.496999Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.pipeline import make_pipeline\npipe = make_pipeline(trans,algorithm)\npipe_x=make_pipeline(trans,algorithm_x)\npipe","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:32.499279Z","iopub.execute_input":"2022-07-15T11:46:32.500208Z","iopub.status.idle":"2022-07-15T11:46:32.570712Z","shell.execute_reply.started":"2022-07-15T11:46:32.500165Z","shell.execute_reply":"2022-07-15T11:46:32.570053Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pipe_x","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:32.571655Z","iopub.execute_input":"2022-07-15T11:46:32.572446Z","iopub.status.idle":"2022-07-15T11:46:32.636687Z","shell.execute_reply.started":"2022-07-15T11:46:32.572405Z","shell.execute_reply":"2022-07-15T11:46:32.636015Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pipe.fit(x_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:32.637610Z","iopub.execute_input":"2022-07-15T11:46:32.638120Z","iopub.status.idle":"2022-07-15T11:46:32.783904Z","shell.execute_reply.started":"2022-07-15T11:46:32.638086Z","shell.execute_reply":"2022-07-15T11:46:32.783273Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pipe_x.fit(x_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:32.785002Z","iopub.execute_input":"2022-07-15T11:46:32.785382Z","iopub.status.idle":"2022-07-15T11:46:32.926442Z","shell.execute_reply.started":"2022-07-15T11:46:32.785351Z","shell.execute_reply":"2022-07-15T11:46:32.925720Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred_x=pipe_x.predict(x_test)\npred_x","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:32.927675Z","iopub.execute_input":"2022-07-15T11:46:32.928600Z","iopub.status.idle":"2022-07-15T11:46:32.947338Z","shell.execute_reply.started":"2022-07-15T11:46:32.928552Z","shell.execute_reply":"2022-07-15T11:46:32.946405Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import accuracy_score, plot_confusion_matrix\naccuracy_score(pred_x,y_test)*100","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:32.948440Z","iopub.execute_input":"2022-07-15T11:46:32.948667Z","iopub.status.idle":"2022-07-15T11:46:32.955238Z","shell.execute_reply.started":"2022-07-15T11:46:32.948636Z","shell.execute_reply":"2022-07-15T11:46:32.954407Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred=pipe.predict(x_test)\npred","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:32.956676Z","iopub.execute_input":"2022-07-15T11:46:32.957324Z","iopub.status.idle":"2022-07-15T11:46:32.986976Z","shell.execute_reply.started":"2022-07-15T11:46:32.957282Z","shell.execute_reply":"2022-07-15T11:46:32.986119Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import accuracy_score, plot_confusion_matrix\naccuracy_score(pred,y_test)*100","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:32.988161Z","iopub.execute_input":"2022-07-15T11:46:32.988393Z","iopub.status.idle":"2022-07-15T11:46:32.995237Z","shell.execute_reply.started":"2022-07-15T11:46:32.988365Z","shell.execute_reply":"2022-07-15T11:46:32.994263Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib as plt \nplot_confusion_matrix(pipe,x_test,y_test)","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:32.996539Z","iopub.execute_input":"2022-07-15T11:46:32.997108Z","iopub.status.idle":"2022-07-15T11:46:33.293859Z","shell.execute_reply.started":"2022-07-15T11:46:32.997066Z","shell.execute_reply":"2022-07-15T11:46:33.292983Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from imblearn.over_sampling import RandomOverSampler\nover= RandomOverSampler()\no_x , o_y = over.fit_resample(x,y)\no_y.value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:33.295899Z","iopub.execute_input":"2022-07-15T11:46:33.296385Z","iopub.status.idle":"2022-07-15T11:46:33.458361Z","shell.execute_reply.started":"2022-07-15T11:46:33.296341Z","shell.execute_reply":"2022-07-15T11:46:33.457564Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from imblearn.over_sampling import SMOTE\nover= RandomOverSampler()\n_x , o_y = over.fit_resample(x,y)\no_y.value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:33.459497Z","iopub.execute_input":"2022-07-15T11:46:33.459808Z","iopub.status.idle":"2022-07-15T11:46:33.477681Z","shell.execute_reply.started":"2022-07-15T11:46:33.459758Z","shell.execute_reply":"2022-07-15T11:46:33.476804Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from imblearn.pipeline import make_pipeline\ns = SMOTE()\nn_pipe = make_pipeline(trans,s,algorithm)\nn_pipe","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:33.479017Z","iopub.execute_input":"2022-07-15T11:46:33.479221Z","iopub.status.idle":"2022-07-15T11:46:33.551521Z","shell.execute_reply.started":"2022-07-15T11:46:33.479196Z","shell.execute_reply":"2022-07-15T11:46:33.550876Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"accuracy_score(pred,y_test)*100","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:33.552858Z","iopub.execute_input":"2022-07-15T11:46:33.553186Z","iopub.status.idle":"2022-07-15T11:46:33.564700Z","shell.execute_reply.started":"2022-07-15T11:46:33.553147Z","shell.execute_reply":"2022-07-15T11:46:33.562990Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.linear_model import LogisticRegression as lr\nalgorithm_2 = lr(solver='liblinear')\npipe_2 = make_pipeline(trans,algorithm_2)\npipe_2","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:33.566901Z","iopub.execute_input":"2022-07-15T11:46:33.567237Z","iopub.status.idle":"2022-07-15T11:46:33.649584Z","shell.execute_reply.started":"2022-07-15T11:46:33.567199Z","shell.execute_reply":"2022-07-15T11:46:33.648575Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pipe_2.fit(x_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:33.650735Z","iopub.execute_input":"2022-07-15T11:46:33.651529Z","iopub.status.idle":"2022-07-15T11:46:33.793634Z","shell.execute_reply.started":"2022-07-15T11:46:33.651487Z","shell.execute_reply":"2022-07-15T11:46:33.792857Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred_2 = pipe_2.predict(x_test)\npred_2","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:33.794714Z","iopub.execute_input":"2022-07-15T11:46:33.794946Z","iopub.status.idle":"2022-07-15T11:46:33.812666Z","shell.execute_reply.started":"2022-07-15T11:46:33.794908Z","shell.execute_reply":"2022-07-15T11:46:33.811722Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"accuracy_score(pred_2,y_test)*100","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:33.814288Z","iopub.execute_input":"2022-07-15T11:46:33.814715Z","iopub.status.idle":"2022-07-15T11:46:33.821202Z","shell.execute_reply.started":"2022-07-15T11:46:33.814681Z","shell.execute_reply":"2022-07-15T11:46:33.820245Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import KFold, cross_val_score,StratifiedKFold\nkf=StratifiedKFold(n_splits=4)\nnp.mean(cross_val_score(pipe,x,y,cv=kf,scoring='accuracy')*100) ","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:33.822225Z","iopub.execute_input":"2022-07-15T11:46:33.822867Z","iopub.status.idle":"2022-07-15T11:46:34.134913Z","shell.execute_reply.started":"2022-07-15T11:46:33.822831Z","shell.execute_reply":"2022-07-15T11:46:34.133977Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.svm import SVC\nmodel1=SVC(kernel='linear')\npipe_1 = make_pipeline(trans,algorithm)\npipe_1\npipe_1.fit(x_train,y_train)\npred_1=pipe.predict(x_test)\naccuracy_score(pred_1,y_test)*100","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:34.140015Z","iopub.execute_input":"2022-07-15T11:46:34.142696Z","iopub.status.idle":"2022-07-15T11:46:34.230794Z","shell.execute_reply.started":"2022-07-15T11:46:34.142628Z","shell.execute_reply":"2022-07-15T11:46:34.229879Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.ensemble import BaggingClassifier\nmodel2=BaggingClassifier(base_estimator=SVC(3))\nmodel2","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:34.235872Z","iopub.execute_input":"2022-07-15T11:46:34.238515Z","iopub.status.idle":"2022-07-15T11:46:34.258418Z","shell.execute_reply.started":"2022-07-15T11:46:34.238452Z","shell.execute_reply":"2022-07-15T11:46:34.257497Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_test.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:34.263510Z","iopub.execute_input":"2022-07-15T11:46:34.266127Z","iopub.status.idle":"2022-07-15T11:46:34.276776Z","shell.execute_reply.started":"2022-07-15T11:46:34.266064Z","shell.execute_reply":"2022-07-15T11:46:34.275896Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pipe5=make_pipeline(trans,model2)\npipe5","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:34.281554Z","iopub.execute_input":"2022-07-15T11:46:34.282103Z","iopub.status.idle":"2022-07-15T11:46:34.354729Z","shell.execute_reply.started":"2022-07-15T11:46:34.282056Z","shell.execute_reply":"2022-07-15T11:46:34.353912Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pipe5.fit(x_train,y_train)\npred5=pipe5.predict(x_test)\npred5.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:34.356236Z","iopub.execute_input":"2022-07-15T11:46:34.356685Z","iopub.status.idle":"2022-07-15T11:46:34.547062Z","shell.execute_reply.started":"2022-07-15T11:46:34.356644Z","shell.execute_reply":"2022-07-15T11:46:34.546159Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"accuracy_score(pred5,y_test)*100","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:34.548486Z","iopub.execute_input":"2022-07-15T11:46:34.548786Z","iopub.status.idle":"2022-07-15T11:46:34.556558Z","shell.execute_reply.started":"2022-07-15T11:46:34.548745Z","shell.execute_reply":"2022-07-15T11:46:34.555711Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data1=pd.read_csv('/kaggle/input/titanic/test.csv')\ndata1","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:34.557989Z","iopub.execute_input":"2022-07-15T11:46:34.558464Z","iopub.status.idle":"2022-07-15T11:46:34.594952Z","shell.execute_reply.started":"2022-07-15T11:46:34.558421Z","shell.execute_reply":"2022-07-15T11:46:34.594136Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data1['Sex'].replace( 'female', 0, inplace=True )\ndata1['Sex'].replace( 'male', 1, inplace=True )","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:34.596473Z","iopub.execute_input":"2022-07-15T11:46:34.596918Z","iopub.status.idle":"2022-07-15T11:46:34.603884Z","shell.execute_reply.started":"2022-07-15T11:46:34.596877Z","shell.execute_reply":"2022-07-15T11:46:34.603143Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data1.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:34.604901Z","iopub.execute_input":"2022-07-15T11:46:34.605246Z","iopub.status.idle":"2022-07-15T11:46:34.617918Z","shell.execute_reply.started":"2022-07-15T11:46:34.605218Z","shell.execute_reply":"2022-07-15T11:46:34.617269Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#data1.Age=data1.Age.fillna(0)\ndata1.Cabin=data1.Cabin.fillna(0)\ndata1.Fare=data1.Fare.fillna(0)","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:34.618985Z","iopub.execute_input":"2022-07-15T11:46:34.619296Z","iopub.status.idle":"2022-07-15T11:46:34.631525Z","shell.execute_reply.started":"2022-07-15T11:46:34.619269Z","shell.execute_reply":"2022-07-15T11:46:34.630947Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data1.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:34.636550Z","iopub.execute_input":"2022-07-15T11:46:34.637215Z","iopub.status.idle":"2022-07-15T11:46:34.647829Z","shell.execute_reply.started":"2022-07-15T11:46:34.637169Z","shell.execute_reply":"2022-07-15T11:46:34.647019Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#data1=data1[data1.Embarked!=0]\n#data1=data1[data1[('Embarked')].map(data1['Embarked'].value_counts())>0]\n#data1","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:34.649065Z","iopub.execute_input":"2022-07-15T11:46:34.649536Z","iopub.status.idle":"2022-07-15T11:46:34.655040Z","shell.execute_reply.started":"2022-07-15T11:46:34.649501Z","shell.execute_reply":"2022-07-15T11:46:34.654200Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#data1.loc[data1['Sex']=='male']=1\n#data1.loc[data1['Sex']=='female']=0","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:34.655905Z","iopub.execute_input":"2022-07-15T11:46:34.656369Z","iopub.status.idle":"2022-07-15T11:46:34.665881Z","shell.execute_reply.started":"2022-07-15T11:46:34.656337Z","shell.execute_reply":"2022-07-15T11:46:34.665019Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data1['Embarked_s']=data1['Embarked'].replace('Q',0).replace('C',0).replace('S',1)\ndata1['Embarked_c']=data1['Embarked'].replace('S',0).replace('Q',0).replace('C',1)\ndata1['Embarked_q']=data1['Embarked'].replace('C',0).replace('S',0).replace('Q',1)","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:34.667158Z","iopub.execute_input":"2022-07-15T11:46:34.667385Z","iopub.status.idle":"2022-07-15T11:46:34.682907Z","shell.execute_reply.started":"2022-07-15T11:46:34.667356Z","shell.execute_reply":"2022-07-15T11:46:34.682262Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data1.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:34.684054Z","iopub.execute_input":"2022-07-15T11:46:34.684663Z","iopub.status.idle":"2022-07-15T11:46:34.707176Z","shell.execute_reply.started":"2022-07-15T11:46:34.684628Z","shell.execute_reply":"2022-07-15T11:46:34.706357Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x1 = data1.drop(columns = ['Ticket','Cabin','PassengerId','Name','Embarked'])\nx1","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:34.708498Z","iopub.execute_input":"2022-07-15T11:46:34.709151Z","iopub.status.idle":"2022-07-15T11:46:34.729450Z","shell.execute_reply.started":"2022-07-15T11:46:34.709105Z","shell.execute_reply":"2022-07-15T11:46:34.728820Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x1.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:34.730468Z","iopub.execute_input":"2022-07-15T11:46:34.730772Z","iopub.status.idle":"2022-07-15T11:46:34.743682Z","shell.execute_reply.started":"2022-07-15T11:46:34.730745Z","shell.execute_reply":"2022-07-15T11:46:34.743053Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import OneHotEncoder, OrdinalEncoder,KBinsDiscretizer,Binarizer\nfrom sklearn.impute import SimpleImputer,KNNImputer\nfrom sklearn.compose import make_column_transformer\nfrom sklearn import set_config\nfrom sklearn.preprocessing import StandardScaler\n\ntrans = make_column_transformer((OneHotEncoder(sparse=False),nom_cols),\n                                (KNNImputer(n_neighbors=45),null_cols),\n                                (OrdinalEncoder(), ord_cols),(StandardScaler(),num_cols)\n                                 ,(Binarizer(threshold=55),binarizer_cols),remainder= 'passthrough')\nset_config(display= 'diagram')\ntrans","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:34.744735Z","iopub.execute_input":"2022-07-15T11:46:34.745016Z","iopub.status.idle":"2022-07-15T11:46:34.765786Z","shell.execute_reply.started":"2022-07-15T11:46:34.744984Z","shell.execute_reply":"2022-07-15T11:46:34.765144Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred123=pipe_x.predict(x1)\npred123","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:34.766708Z","iopub.execute_input":"2022-07-15T11:46:34.767313Z","iopub.status.idle":"2022-07-15T11:46:34.797190Z","shell.execute_reply.started":"2022-07-15T11:46:34.767284Z","shell.execute_reply":"2022-07-15T11:46:34.796322Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#survival_prediction=algorithm.predict(x1)\n#survival_prediction","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:34.798801Z","iopub.execute_input":"2022-07-15T11:46:34.799355Z","iopub.status.idle":"2022-07-15T11:46:34.803636Z","shell.execute_reply.started":"2022-07-15T11:46:34.799310Z","shell.execute_reply":"2022-07-15T11:46:34.802806Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submit=pd.read_csv('/kaggle/input/titanic/gender_submission.csv')","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:34.805607Z","iopub.execute_input":"2022-07-15T11:46:34.807029Z","iopub.status.idle":"2022-07-15T11:46:34.823686Z","shell.execute_reply.started":"2022-07-15T11:46:34.806981Z","shell.execute_reply":"2022-07-15T11:46:34.822478Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submit['Survived']=pred123\nsubmit.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:34.825423Z","iopub.execute_input":"2022-07-15T11:46:34.825919Z","iopub.status.idle":"2022-07-15T11:46:34.839077Z","shell.execute_reply.started":"2022-07-15T11:46:34.825875Z","shell.execute_reply":"2022-07-15T11:46:34.837957Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submit.Survived.value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-15T11:46:34.844337Z","iopub.execute_input":"2022-07-15T11:46:34.845048Z","iopub.status.idle":"2022-07-15T11:46:34.861296Z","shell.execute_reply.started":"2022-07-15T11:46:34.844998Z","shell.execute_reply":"2022-07-15T11:46:34.860286Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}