{"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 numpy as np\nimport pandas as pd\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn.metrics import accuracy_score","metadata":{"execution":{"iopub.status.busy":"2022-07-11T22:59:42.672533Z","iopub.execute_input":"2022-07-11T22:59:42.673305Z","iopub.status.idle":"2022-07-11T22:59:44.004013Z","shell.execute_reply.started":"2022-07-11T22:59:42.673200Z","shell.execute_reply":"2022-07-11T22:59:44.002826Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df=pd.read_csv('../input/spaceship-titanic/train.csv')\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-11T22:59:44.005873Z","iopub.execute_input":"2022-07-11T22:59:44.006191Z","iopub.status.idle":"2022-07-11T22:59:44.087847Z","shell.execute_reply.started":"2022-07-11T22:59:44.006164Z","shell.execute_reply":"2022-07-11T22:59:44.086974Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-11T22:59:44.089126Z","iopub.execute_input":"2022-07-11T22:59:44.089517Z","iopub.status.idle":"2022-07-11T22:59:44.123586Z","shell.execute_reply.started":"2022-07-11T22:59:44.089485Z","shell.execute_reply":"2022-07-11T22:59:44.122352Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-11T22:59:44.126279Z","iopub.execute_input":"2022-07-11T22:59:44.127763Z","iopub.status.idle":"2022-07-11T22:59:44.145633Z","shell.execute_reply.started":"2022-07-11T22:59:44.127714Z","shell.execute_reply":"2022-07-11T22:59:44.144218Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['RoomService'].fillna(df['RoomService'].mean(), inplace=True)\ndf['Spa'].fillna(df['Spa'].mean(), inplace=True)\ndf['VRDeck'].fillna(df['VRDeck'].mean(), inplace=True)\ndf['ShoppingMall'].fillna(df['ShoppingMall'].mean(), inplace=True)\ndf['Age'].fillna(df['Age'].mean(), inplace=True)\ndf['FoodCourt'].fillna(df['FoodCourt'].mean(), inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-11T22:59:44.147642Z","iopub.execute_input":"2022-07-11T22:59:44.148313Z","iopub.status.idle":"2022-07-11T22:59:44.159232Z","shell.execute_reply.started":"2022-07-11T22:59:44.148271Z","shell.execute_reply":"2022-07-11T22:59:44.158372Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-11T22:59:44.160558Z","iopub.execute_input":"2022-07-11T22:59:44.161641Z","iopub.status.idle":"2022-07-11T22:59:44.175559Z","shell.execute_reply.started":"2022-07-11T22:59:44.161598Z","shell.execute_reply":"2022-07-11T22:59:44.174328Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['HomePlanet'].fillna(df['HomePlanet'].mode()[0], inplace=True)\ndf['CryoSleep'].fillna(df['CryoSleep'].mode()[0], inplace=True)\ndf['Destination'].fillna(df['Destination'].mode()[0], inplace=True)\ndf['VIP'].fillna(df['VIP'].mode()[0], inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-11T22:59:44.177600Z","iopub.execute_input":"2022-07-11T22:59:44.178290Z","iopub.status.idle":"2022-07-11T22:59:44.194494Z","shell.execute_reply.started":"2022-07-11T22:59:44.178244Z","shell.execute_reply":"2022-07-11T22:59:44.193216Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-11T22:59:44.195936Z","iopub.execute_input":"2022-07-11T22:59:44.199027Z","iopub.status.idle":"2022-07-11T22:59:44.211365Z","shell.execute_reply.started":"2022-07-11T22:59:44.198983Z","shell.execute_reply":"2022-07-11T22:59:44.210180Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(df.Destination.value_counts())\nprint(df.VIP.value_counts())\nprint(df.CryoSleep.value_counts())\nprint(df.HomePlanet.value_counts())\nprint(df.Transported.value_counts())","metadata":{"execution":{"iopub.status.busy":"2022-07-11T22:59:44.213290Z","iopub.execute_input":"2022-07-11T22:59:44.214051Z","iopub.status.idle":"2022-07-11T22:59:44.229747Z","shell.execute_reply.started":"2022-07-11T22:59:44.214007Z","shell.execute_reply":"2022-07-11T22:59:44.228739Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.replace({'Destination':{'TRAPPIST-1e':0, '55 Cancri e':1,'PSO J318.5-22':2}},inplace=True)\ndf.replace({'VIP':{'False':0, 'True':1}},inplace=True)\ndf.replace({'CryoSleep':{'False':0, 'True':1}},inplace=True)\ndf.replace({'HomePlanet':{'Earth':0, 'Europa':1,'Mars':2}},inplace=True)\ndf.replace({'Transported':{'False':0, 'True':1}},inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-11T22:59:44.233807Z","iopub.execute_input":"2022-07-11T22:59:44.234144Z","iopub.status.idle":"2022-07-11T22:59:44.255734Z","shell.execute_reply.started":"2022-07-11T22:59:44.234112Z","shell.execute_reply":"2022-07-11T22:59:44.254603Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-11T22:59:44.259492Z","iopub.execute_input":"2022-07-11T22:59:44.260107Z","iopub.status.idle":"2022-07-11T22:59:44.276013Z","shell.execute_reply.started":"2022-07-11T22:59:44.260062Z","shell.execute_reply":"2022-07-11T22:59:44.274768Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-11T22:59:44.277597Z","iopub.execute_input":"2022-07-11T22:59:44.278047Z","iopub.status.idle":"2022-07-11T22:59:44.305360Z","shell.execute_reply.started":"2022-07-11T22:59:44.278005Z","shell.execute_reply":"2022-07-11T22:59:44.304465Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x=df.drop(['PassengerId','Cabin','Transported','Name'],axis=1)\ny=df['Transported']","metadata":{"execution":{"iopub.status.busy":"2022-07-11T22:59:44.306761Z","iopub.execute_input":"2022-07-11T22:59:44.307530Z","iopub.status.idle":"2022-07-11T22:59:44.317449Z","shell.execute_reply.started":"2022-07-11T22:59:44.307496Z","shell.execute_reply":"2022-07-11T22:59:44.316083Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(x)","metadata":{"execution":{"iopub.status.busy":"2022-07-11T22:59:44.319234Z","iopub.execute_input":"2022-07-11T22:59:44.320007Z","iopub.status.idle":"2022-07-11T22:59:44.340438Z","shell.execute_reply.started":"2022-07-11T22:59:44.319912Z","shell.execute_reply":"2022-07-11T22:59:44.339285Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(y)","metadata":{"execution":{"iopub.status.busy":"2022-07-11T22:59:44.342026Z","iopub.execute_input":"2022-07-11T22:59:44.342698Z","iopub.status.idle":"2022-07-11T22:59:44.350195Z","shell.execute_reply.started":"2022-07-11T22:59:44.342655Z","shell.execute_reply":"2022-07-11T22:59:44.349007Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.2)","metadata":{"execution":{"iopub.status.busy":"2022-07-11T22:59:44.351704Z","iopub.execute_input":"2022-07-11T22:59:44.352975Z","iopub.status.idle":"2022-07-11T22:59:44.363215Z","shell.execute_reply.started":"2022-07-11T22:59:44.352907Z","shell.execute_reply":"2022-07-11T22:59:44.361824Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"reg=LogisticRegression()","metadata":{"execution":{"iopub.status.busy":"2022-07-11T22:59:44.365442Z","iopub.execute_input":"2022-07-11T22:59:44.366201Z","iopub.status.idle":"2022-07-11T22:59:44.371201Z","shell.execute_reply.started":"2022-07-11T22:59:44.366156Z","shell.execute_reply":"2022-07-11T22:59:44.369821Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"reg.fit(x_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2022-07-11T22:59:44.373329Z","iopub.execute_input":"2022-07-11T22:59:44.374342Z","iopub.status.idle":"2022-07-11T22:59:44.553230Z","shell.execute_reply.started":"2022-07-11T22:59:44.374287Z","shell.execute_reply":"2022-07-11T22:59:44.552168Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_predict=reg.predict(x_train)\naccuracy=accuracy_score(y_train,x_predict)\nprint(accuracy)","metadata":{"execution":{"iopub.status.busy":"2022-07-11T22:59:44.554602Z","iopub.execute_input":"2022-07-11T22:59:44.556172Z","iopub.status.idle":"2022-07-11T22:59:44.597813Z","shell.execute_reply.started":"2022-07-11T22:59:44.556127Z","shell.execute_reply":"2022-07-11T22:59:44.596558Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_pred=reg.predict(x_test)\naccuracy=accuracy_score(y_test,x_pred)\nprint(accuracy)","metadata":{"execution":{"iopub.status.busy":"2022-07-11T22:59:44.599588Z","iopub.execute_input":"2022-07-11T22:59:44.601749Z","iopub.status.idle":"2022-07-11T22:59:44.617183Z","shell.execute_reply.started":"2022-07-11T22:59:44.601704Z","shell.execute_reply":"2022-07-11T22:59:44.615613Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}