{"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        \ndata = pd.read_csv('../input/spaceship-titanic/train.csv')\ntest = pd.read_csv('../input/spaceship-titanic/test.csv')\nimport seaborn as sns\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-15T16:16:26.136690Z","iopub.execute_input":"2022-07-15T16:16:26.137919Z","iopub.status.idle":"2022-07-15T16:16:27.536058Z","shell.execute_reply.started":"2022-07-15T16:16:26.137803Z","shell.execute_reply":"2022-07-15T16:16:27.534620Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test1 = test.copy()","metadata":{"execution":{"iopub.status.busy":"2022-07-15T16:16:27.538272Z","iopub.execute_input":"2022-07-15T16:16:27.538787Z","iopub.status.idle":"2022-07-15T16:16:27.545939Z","shell.execute_reply.started":"2022-07-15T16:16:27.538737Z","shell.execute_reply":"2022-07-15T16:16:27.544491Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"* use of pipelines\n* hyperparameter testing\n* transported stat within categories \n* separate groups?? \n* fill na values according to context\n* standardize numerical values","metadata":{}},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"markdown","source":"EDA","metadata":{}},{"cell_type":"code","source":"data.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-15T16:16:27.547980Z","iopub.execute_input":"2022-07-15T16:16:27.548829Z","iopub.status.idle":"2022-07-15T16:16:27.591108Z","shell.execute_reply.started":"2022-07-15T16:16:27.548780Z","shell.execute_reply":"2022-07-15T16:16:27.589645Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[['group', 'pos']] = (data['PassengerId'].str.split('_', expand = True))\ndata[['deck', 'num', 'side']] = (data['Cabin'].str.split('/', expand = True))\ndata['expenses'] = data['RoomService']+data['FoodCourt']+ data['ShoppingMall']+data['Spa']+data['VRDeck']\ntest[['group', 'pos']] = (test['PassengerId'].str.split('_', expand = True))\ntest[['deck', 'num', 'side']] = (test['Cabin'].str.split('/',\n                                                         expand = True))\ntest['expenses'] = test['RoomService']+test['FoodCourt']+ test['ShoppingMall']+test['Spa']+test['VRDeck']\ndata","metadata":{"execution":{"iopub.status.busy":"2022-07-15T16:16:27.593521Z","iopub.execute_input":"2022-07-15T16:16:27.593921Z","iopub.status.idle":"2022-07-15T16:16:27.710206Z","shell.execute_reply.started":"2022-07-15T16:16:27.593883Z","shell.execute_reply":"2022-07-15T16:16:27.708881Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['group'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-15T16:16:27.712081Z","iopub.execute_input":"2022-07-15T16:16:27.713426Z","iopub.status.idle":"2022-07-15T16:16:27.732770Z","shell.execute_reply.started":"2022-07-15T16:16:27.713370Z","shell.execute_reply":"2022-07-15T16:16:27.731774Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = data.copy()\ndf_y = df.pop(\"Transported\")\n\n# Label encoding for categoricals\nfor colname in df.select_dtypes(\"object\"):\n    df[colname], _ = df[colname].factorize()\n\n# All discrete features should now have integer dtypes (double-check this before using MI!)\ndiscrete_features = df.dtypes == int","metadata":{"execution":{"iopub.status.busy":"2022-07-15T16:21:09.910068Z","iopub.execute_input":"2022-07-15T16:21:09.910487Z","iopub.status.idle":"2022-07-15T16:21:09.962853Z","shell.execute_reply.started":"2022-07-15T16:21:09.910437Z","shell.execute_reply":"2022-07-15T16:21:09.961623Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = df.fillna(df.mean())","metadata":{"execution":{"iopub.status.busy":"2022-07-15T16:22:07.590706Z","iopub.execute_input":"2022-07-15T16:22:07.591066Z","iopub.status.idle":"2022-07-15T16:22:07.605009Z","shell.execute_reply.started":"2022-07-15T16:22:07.591036Z","shell.execute_reply":"2022-07-15T16:22:07.603944Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.feature_selection import mutual_info_classif\n\ndef make_mi_scores(j, k, discrete_features):\n    mi_scores = mutual_info_classif(j, k, discrete_features = discrete_features)\n    mi_scores = pd.Series(mi_scores, name=\"MI Scores\", index=j.columns)\n    mi_scores = mi_scores.sort_values(ascending=False)\n    return mi_scores\n\nmi_scoreeees = make_mi_scores(df, df_y, discrete_features)","metadata":{"execution":{"iopub.status.busy":"2022-07-15T16:22:10.401418Z","iopub.execute_input":"2022-07-15T16:22:10.401847Z","iopub.status.idle":"2022-07-15T16:22:10.720332Z","shell.execute_reply.started":"2022-07-15T16:22:10.401800Z","shell.execute_reply":"2022-07-15T16:22:10.719141Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mi_scoreeees","metadata":{"execution":{"iopub.status.busy":"2022-07-15T16:22:12.666837Z","iopub.execute_input":"2022-07-15T16:22:12.667248Z","iopub.status.idle":"2022-07-15T16:22:12.676746Z","shell.execute_reply.started":"2022-07-15T16:22:12.667212Z","shell.execute_reply":"2022-07-15T16:22:12.675568Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.plot(kind = 'box')","metadata":{"execution":{"iopub.status.busy":"2022-07-15T16:28:29.976724Z","iopub.execute_input":"2022-07-15T16:28:29.977118Z","iopub.status.idle":"2022-07-15T16:28:30.263232Z","shell.execute_reply.started":"2022-07-15T16:28:29.977087Z","shell.execute_reply":"2022-07-15T16:28:30.261973Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"outliers of expenses","metadata":{}},{"cell_type":"code","source":"for n in ['HomePlanet', 'Destination', '']\nsns.countplot(x= 'Transported', hue = , data= train)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.groupby(['Destination'])['Transported'].sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-15T16:44:00.536633Z","iopub.execute_input":"2022-07-15T16:44:00.537090Z","iopub.status.idle":"2022-07-15T16:44:00.550174Z","shell.execute_reply.started":"2022-07-15T16:44:00.537041Z","shell.execute_reply":"2022-07-15T16:44:00.549128Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"related = []\nref = {}\nfor n in ['group', 'num', 'CryoSleep', 'deck','HomePlanet', 'Destination', 'side', 'pos', 'VIP']:\n    if (data.groupby([n])['Transported'].sum()/data[n].value_counts()).std()>= 0.07:\n        related.append(n)\n        ref[n] = (data.groupby([n])['Transported'].sum()/data[n].value_counts()).std()\n    ","metadata":{"execution":{"iopub.status.busy":"2022-07-15T16:53:57.970497Z","iopub.execute_input":"2022-07-15T16:53:57.970930Z","iopub.status.idle":"2022-07-15T16:53:58.097046Z","shell.execute_reply.started":"2022-07-15T16:53:57.970894Z","shell.execute_reply":"2022-07-15T16:53:58.095546Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"related","metadata":{"execution":{"iopub.status.busy":"2022-07-15T16:52:37.388864Z","iopub.execute_input":"2022-07-15T16:52:37.389286Z","iopub.status.idle":"2022-07-15T16:52:37.396388Z","shell.execute_reply.started":"2022-07-15T16:52:37.389249Z","shell.execute_reply":"2022-07-15T16:52:37.395344Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ref","metadata":{"execution":{"iopub.status.busy":"2022-07-15T16:54:03.214749Z","iopub.execute_input":"2022-07-15T16:54:03.215281Z","iopub.status.idle":"2022-07-15T16:54:03.223925Z","shell.execute_reply.started":"2022-07-15T16:54:03.215232Z","shell.execute_reply":"2022-07-15T16:54:03.222484Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.histplot(data= data, x = 'Age', hue= 'Transported')\n","metadata":{"execution":{"iopub.status.busy":"2022-07-15T17:28:01.515760Z","iopub.execute_input":"2022-07-15T17:28:01.516284Z","iopub.status.idle":"2022-07-15T17:28:01.822442Z","shell.execute_reply.started":"2022-07-15T17:28:01.516231Z","shell.execute_reply":"2022-07-15T17:28:01.820991Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.boxplot(data= data, x = 'Age')","metadata":{"execution":{"iopub.status.busy":"2022-07-15T17:27:17.886155Z","iopub.execute_input":"2022-07-15T17:27:17.886558Z","iopub.status.idle":"2022-07-15T17:27:18.054926Z","shell.execute_reply.started":"2022-07-15T17:27:17.886526Z","shell.execute_reply":"2022-07-15T17:27:18.053718Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cols = ['Age', 'expenses']\ndata[cols]= data[cols].clip(lower= data[cols].quantile(0.15), upper= data[cols].quantile(0.85), axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-07-15T17:27:25.373517Z","iopub.execute_input":"2022-07-15T17:27:25.373927Z","iopub.status.idle":"2022-07-15T17:27:25.390907Z","shell.execute_reply.started":"2022-07-15T17:27:25.373892Z","shell.execute_reply":"2022-07-15T17:27:25.389864Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"related.append('Age')","metadata":{"execution":{"iopub.status.busy":"2022-07-15T17:21:26.884312Z","iopub.execute_input":"2022-07-15T17:21:26.884733Z","iopub.status.idle":"2022-07-15T17:21:26.890330Z","shell.execute_reply.started":"2022-07-15T17:21:26.884699Z","shell.execute_reply":"2022-07-15T17:21:26.888956Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.histplot(data= data, x = 'expenses', hue= 'Transported')","metadata":{"execution":{"iopub.status.busy":"2022-07-15T17:27:30.318514Z","iopub.execute_input":"2022-07-15T17:27:30.319764Z","iopub.status.idle":"2022-07-15T17:27:30.635641Z","shell.execute_reply.started":"2022-07-15T17:27:30.319715Z","shell.execute_reply":"2022-07-15T17:27:30.634358Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.histplot(data= data, x = 'expenses', hue= 'VIP')","metadata":{"execution":{"iopub.status.busy":"2022-07-15T17:42:23.137089Z","iopub.execute_input":"2022-07-15T17:42:23.137525Z","iopub.status.idle":"2022-07-15T17:42:23.507707Z","shell.execute_reply.started":"2022-07-15T17:42:23.137457Z","shell.execute_reply":"2022-07-15T17:42:23.506320Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_all_corr = data.corr().abs().unstack().sort_values(kind=\"quicksort\", ascending=False).reset_index()\ndf_all_corr.rename(columns={\"level_0\": \"Feature 1\", \"level_1\": \"Feature 2\", 0: 'Correlation Coefficient'}, inplace=True)\ndf_all_corr[df_all_corr['Feature 1'] == 'expenses']","metadata":{"execution":{"iopub.status.busy":"2022-07-15T17:37:54.061847Z","iopub.execute_input":"2022-07-15T17:37:54.062248Z","iopub.status.idle":"2022-07-15T17:37:54.087535Z","shell.execute_reply.started":"2022-07-15T17:37:54.062215Z","shell.execute_reply":"2022-07-15T17:37:54.086077Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['expenses'].isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-15T17:42:51.269728Z","iopub.execute_input":"2022-07-15T17:42:51.270150Z","iopub.status.idle":"2022-07-15T17:42:51.278891Z","shell.execute_reply.started":"2022-07-15T17:42:51.270112Z","shell.execute_reply":"2022-07-15T17:42:51.277782Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.scatterplot(data = data, x = 'Age', y= 'expenses')","metadata":{"execution":{"iopub.status.busy":"2022-07-15T17:40:32.565920Z","iopub.execute_input":"2022-07-15T17:40:32.566349Z","iopub.status.idle":"2022-07-15T17:40:32.802703Z","shell.execute_reply.started":"2022-07-15T17:40:32.566313Z","shell.execute_reply":"2022-07-15T17:40:32.801638Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"no obvious relationship, fill with 0","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = data[['group', 'num', 'CryoSleep', 'expenses']]\ntest = test[['group', 'num', 'CryoSleep', 'expenses']]\nX","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:35:47.528719Z","iopub.execute_input":"2022-07-14T14:35:47.529404Z","iopub.status.idle":"2022-07-14T14:35:47.560721Z","shell.execute_reply.started":"2022-07-14T14:35:47.529374Z","shell.execute_reply":"2022-07-14T14:35:47.559690Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y = data['Transported']","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:35:47.562578Z","iopub.execute_input":"2022-07-14T14:35:47.563012Z","iopub.status.idle":"2022-07-14T14:35:47.568729Z","shell.execute_reply.started":"2022-07-14T14:35:47.562973Z","shell.execute_reply":"2022-07-14T14:35:47.567544Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:35:47.570245Z","iopub.execute_input":"2022-07-14T14:35:47.571486Z","iopub.status.idle":"2022-07-14T14:35:47.588423Z","shell.execute_reply.started":"2022-07-14T14:35:47.571432Z","shell.execute_reply":"2022-07-14T14:35:47.587353Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"model building","metadata":{}},{"cell_type":"code","source":"def f(x):\n    try:\n        return np.float(x)\n    except:\n        return np.nan\n    \nX['num']= X['num'].apply(f)\nX['group']= X['group'].apply(f)\ntest['num']= test['num'].apply(f)\ntest['group']=test['group'].apply(f)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:35:47.590119Z","iopub.execute_input":"2022-07-14T14:35:47.591122Z","iopub.status.idle":"2022-07-14T14:35:47.691910Z","shell.execute_reply.started":"2022-07-14T14:35:47.591080Z","shell.execute_reply":"2022-07-14T14:35:47.690767Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X.dtypes","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:35:47.693152Z","iopub.execute_input":"2022-07-14T14:35:47.693433Z","iopub.status.idle":"2022-07-14T14:35:47.702390Z","shell.execute_reply.started":"2022-07-14T14:35:47.693405Z","shell.execute_reply":"2022-07-14T14:35:47.701244Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"'''\nX['CryoSleep'].fillna('False')\nX['CryoSleep']= X['CryoSleep'].astype('bool')\n'''","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:35:47.706836Z","iopub.execute_input":"2022-07-14T14:35:47.707519Z","iopub.status.idle":"2022-07-14T14:35:47.717310Z","shell.execute_reply.started":"2022-07-14T14:35:47.707487Z","shell.execute_reply":"2022-07-14T14:35:47.715584Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nfrom sklearn.compose import ColumnTransformer\nfrom sklearn.pipeline import Pipeline\nfrom sklearn.impute import SimpleImputer\nfrom sklearn.preprocessing import OneHotEncoder\nfrom sklearn.metrics import mean_absolute_error\nfrom sklearn.model_selection import train_test_split","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:35:47.719077Z","iopub.execute_input":"2022-07-14T14:35:47.719448Z","iopub.status.idle":"2022-07-14T14:35:47.728273Z","shell.execute_reply.started":"2022-07-14T14:35:47.719415Z","shell.execute_reply":"2022-07-14T14:35:47.727087Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y ","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:35:47.730364Z","iopub.execute_input":"2022-07-14T14:35:47.730821Z","iopub.status.idle":"2022-07-14T14:35:47.744412Z","shell.execute_reply.started":"2022-07-14T14:35:47.730784Z","shell.execute_reply":"2022-07-14T14:35:47.743492Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, X_valid, y_train, y_valid = train_test_split(X, y, \n                                                                train_size=0.8, test_size=0.2,\n                                                                random_state=0)\ncategorical_cols = ['CryoSleep']\nnumerical_cols = [c for c in X.columns if not c=='CryoSleep']","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:35:47.746082Z","iopub.execute_input":"2022-07-14T14:35:47.746467Z","iopub.status.idle":"2022-07-14T14:35:47.761250Z","shell.execute_reply.started":"2022-07-14T14:35:47.746436Z","shell.execute_reply":"2022-07-14T14:35:47.760136Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"raw","source":"","metadata":{}},{"cell_type":"code","source":"X_train['CryoSleep'].fillna(X_train['CryoSleep'].mode()[0], inplace= True)\nX_valid['CryoSleep'].fillna(X_valid['CryoSleep'].mode()[0], inplace= True)\ntest['CryoSleep'].fillna(test['CryoSleep'].mode()[0], inplace= True)\n","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:35:47.762706Z","iopub.execute_input":"2022-07-14T14:35:47.763818Z","iopub.status.idle":"2022-07-14T14:35:47.779093Z","shell.execute_reply.started":"2022-07-14T14:35:47.763779Z","shell.execute_reply":"2022-07-14T14:35:47.778104Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"numerical_cols","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:35:47.780576Z","iopub.execute_input":"2022-07-14T14:35:47.781073Z","iopub.status.idle":"2022-07-14T14:35:47.787803Z","shell.execute_reply.started":"2022-07-14T14:35:47.781045Z","shell.execute_reply":"2022-07-14T14:35:47.786661Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_valid.dtypes","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:35:47.789465Z","iopub.execute_input":"2022-07-14T14:35:47.790127Z","iopub.status.idle":"2022-07-14T14:35:47.801813Z","shell.execute_reply.started":"2022-07-14T14:35:47.790086Z","shell.execute_reply":"2022-07-14T14:35:47.800889Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"numerical_transformer = SimpleImputer(strategy='mean')\n\n# Preprocessing for categorical data\n'''\ncat_imputer = Pipeline(steps = [\n    ('imputer', SimpleImputer(strategy='most_frequent')),\n    ('onehot', OneHotEncoder(handle_unknown='ignore'))]) \n'''\noh= OneHotEncoder(handle_unknown='ignore')\n\n# Bundle preprocessing for numerical and categorical data\npreprocessor = ColumnTransformer(\n    transformers=[\n        ('num', numerical_transformer, numerical_cols), \n        ('cat', oh, categorical_cols)\n    ])","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:35:47.803073Z","iopub.execute_input":"2022-07-14T14:35:47.804069Z","iopub.status.idle":"2022-07-14T14:35:47.816204Z","shell.execute_reply.started":"2022-07-14T14:35:47.804037Z","shell.execute_reply":"2022-07-14T14:35:47.814797Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"categorical_cols","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:35:47.817829Z","iopub.execute_input":"2022-07-14T14:35:47.818166Z","iopub.status.idle":"2022-07-14T14:35:47.833778Z","shell.execute_reply.started":"2022-07-14T14:35:47.818137Z","shell.execute_reply":"2022-07-14T14:35:47.832679Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from xgboost import XGBClassifier","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:35:47.837913Z","iopub.execute_input":"2022-07-14T14:35:47.838459Z","iopub.status.idle":"2022-07-14T14:35:47.845901Z","shell.execute_reply.started":"2022-07-14T14:35:47.838415Z","shell.execute_reply":"2022-07-14T14:35:47.844497Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train.dtypes","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:35:47.847987Z","iopub.execute_input":"2022-07-14T14:35:47.848361Z","iopub.status.idle":"2022-07-14T14:35:47.862756Z","shell.execute_reply.started":"2022-07-14T14:35:47.848332Z","shell.execute_reply":"2022-07-14T14:35:47.861386Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"f = pd.DataFrame()\nf['j'] = X_train['CryoSleep']","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:35:47.864777Z","iopub.execute_input":"2022-07-14T14:35:47.865827Z","iopub.status.idle":"2022-07-14T14:35:47.876325Z","shell.execute_reply.started":"2022-07-14T14:35:47.865795Z","shell.execute_reply":"2022-07-14T14:35:47.875107Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_score(n):\n    p = Pipeline(steps = [('preprocessor', preprocessor),\n                        ('model', XGBClassifier(n_estimators=n, early_stopping_rounds = 5))])\n    p.fit(X_train, y_train, model__eval_set=[(X_valid.to_numpy(), y_valid)],\n             )\n    pred= p.predict(X_valid)\n    score = mean_absolute_error(y_valid, pred)\n    return score","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:35:47.912128Z","iopub.execute_input":"2022-07-14T14:35:47.912740Z","iopub.status.idle":"2022-07-14T14:35:47.919557Z","shell.execute_reply.started":"2022-07-14T14:35:47.912699Z","shell.execute_reply":"2022-07-14T14:35:47.918392Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:35:47.955134Z","iopub.execute_input":"2022-07-14T14:35:47.955894Z","iopub.status.idle":"2022-07-14T14:35:47.974552Z","shell.execute_reply.started":"2022-07-14T14:35:47.955862Z","shell.execute_reply":"2022-07-14T14:35:47.973787Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = XGBClassifier(n_estimators=500, early_stopping_rounds = 5)\npa = Pipeline(steps = [('preprocessor', preprocessor),\n                        ('model', model)])\npa.fit(X_train, y_train, model__eval_set=[(X_valid.to_numpy(), y_valid)],\n             )\npred= pa.predict(X_valid)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:35:47.990560Z","iopub.execute_input":"2022-07-14T14:35:47.991868Z","iopub.status.idle":"2022-07-14T14:35:48.111302Z","shell.execute_reply.started":"2022-07-14T14:35:47.991835Z","shell.execute_reply":"2022-07-14T14:35:48.110401Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:35:48.113106Z","iopub.execute_input":"2022-07-14T14:35:48.113673Z","iopub.status.idle":"2022-07-14T14:35:48.120875Z","shell.execute_reply.started":"2022-07-14T14:35:48.113639Z","shell.execute_reply":"2022-07-14T14:35:48.119510Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:35:48.124466Z","iopub.execute_input":"2022-07-14T14:35:48.124817Z","iopub.status.idle":"2022-07-14T14:35:48.149711Z","shell.execute_reply.started":"2022-07-14T14:35:48.124786Z","shell.execute_reply":"2022-07-14T14:35:48.147714Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"get_score(500)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:35:48.151849Z","iopub.execute_input":"2022-07-14T14:35:48.152397Z","iopub.status.idle":"2022-07-14T14:35:48.274480Z","shell.execute_reply.started":"2022-07-14T14:35:48.152367Z","shell.execute_reply":"2022-07-14T14:35:48.273591Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"p = Pipeline(steps = [('preprocessor', preprocessor),\n                        ('model', XGBClassifier(n_estimators=300, early_stopping_rounds = 5))])\np.fit(X_train, y_train, model__eval_set=[(X_valid.to_numpy(), y_valid)],\n             )","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:35:48.276047Z","iopub.execute_input":"2022-07-14T14:35:48.276602Z","iopub.status.idle":"2022-07-14T14:35:48.411961Z","shell.execute_reply.started":"2022-07-14T14:35:48.276567Z","shell.execute_reply":"2022-07-14T14:35:48.411126Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub = p.predict(test)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:35:48.413085Z","iopub.execute_input":"2022-07-14T14:35:48.414567Z","iopub.status.idle":"2022-07-14T14:35:48.431135Z","shell.execute_reply.started":"2022-07-14T14:35:48.414511Z","shell.execute_reply":"2022-07-14T14:35:48.430122Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:35:48.434096Z","iopub.execute_input":"2022-07-14T14:35:48.436894Z","iopub.status.idle":"2022-07-14T14:35:48.455281Z","shell.execute_reply.started":"2022-07-14T14:35:48.436854Z","shell.execute_reply":"2022-07-14T14:35:48.454232Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df= pd.DataFrame(sub)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:35:48.456668Z","iopub.execute_input":"2022-07-14T14:35:48.457155Z","iopub.status.idle":"2022-07-14T14:35:48.462089Z","shell.execute_reply.started":"2022-07-14T14:35:48.457126Z","shell.execute_reply":"2022-07-14T14:35:48.460564Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def num2bool(x):\n    if x==0:\n        return False\n    else: \n        return True\n    \n\ndf['Transported']= df[0].apply(num2bool)","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:35:48.464032Z","iopub.execute_input":"2022-07-14T14:35:48.464454Z","iopub.status.idle":"2022-07-14T14:35:48.478933Z","shell.execute_reply.started":"2022-07-14T14:35:48.464423Z","shell.execute_reply":"2022-07-14T14:35:48.477696Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = df.drop([0], axis =1)\ndf = df.set_index(test1['PassengerId'])","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:36:25.514551Z","iopub.execute_input":"2022-07-14T14:36:25.514952Z","iopub.status.idle":"2022-07-14T14:36:25.519901Z","shell.execute_reply.started":"2022-07-14T14:36:25.514922Z","shell.execute_reply":"2022-07-14T14:36:25.519045Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:37:28.110315Z","iopub.execute_input":"2022-07-14T14:37:28.110713Z","iopub.status.idle":"2022-07-14T14:37:28.123769Z","shell.execute_reply.started":"2022-07-14T14:37:28.110684Z","shell.execute_reply":"2022-07-14T14:37:28.122875Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.to_csv('sub.csv')","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:37:32.694187Z","iopub.execute_input":"2022-07-14T14:37:32.694536Z","iopub.status.idle":"2022-07-14T14:37:32.705136Z","shell.execute_reply.started":"2022-07-14T14:37:32.694507Z","shell.execute_reply":"2022-07-14T14:37:32.704113Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_valid.dtypes","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:35:48.526079Z","iopub.execute_input":"2022-07-14T14:35:48.526688Z","iopub.status.idle":"2022-07-14T14:35:48.536149Z","shell.execute_reply.started":"2022-07-14T14:35:48.526649Z","shell.execute_reply":"2022-07-14T14:35:48.534823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"d = {}\ni =300\nwhile i < 1100:\n    d[i] = get_score(i)\n    i += 100","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:35:48.540697Z","iopub.execute_input":"2022-07-14T14:35:48.542106Z","iopub.status.idle":"2022-07-14T14:35:49.371054Z","shell.execute_reply.started":"2022-07-14T14:35:48.542048Z","shell.execute_reply":"2022-07-14T14:35:49.370155Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"d","metadata":{"execution":{"iopub.status.busy":"2022-07-14T14:35:49.372321Z","iopub.execute_input":"2022-07-14T14:35:49.375170Z","iopub.status.idle":"2022-07-14T14:35:49.381656Z","shell.execute_reply.started":"2022-07-14T14:35:49.375113Z","shell.execute_reply":"2022-07-14T14:35:49.380807Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}