{"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","trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import catboost as cb\nimport optuna\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import accuracy_score","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:26:53.849168Z","iopub.execute_input":"2022-07-12T05:26:53.849608Z","iopub.status.idle":"2022-07-12T05:26:55.667207Z","shell.execute_reply.started":"2022-07-12T05:26:53.849572Z","shell.execute_reply":"2022-07-12T05:26:55.666205Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport plotly.graph_objects as go\nimport gc","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:26:55.669100Z","iopub.execute_input":"2022-07-12T05:26:55.669465Z","iopub.status.idle":"2022-07-12T05:26:55.746935Z","shell.execute_reply.started":"2022-07-12T05:26:55.669432Z","shell.execute_reply":"2022-07-12T05:26:55.745747Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nfrom sklearn.preprocessing import  OrdinalEncoder","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:26:55.749641Z","iopub.execute_input":"2022-07-12T05:26:55.750375Z","iopub.status.idle":"2022-07-12T05:26:55.755780Z","shell.execute_reply.started":"2022-07-12T05:26:55.750306Z","shell.execute_reply":"2022-07-12T05:26:55.754675Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\ndf=pd.read_parquet(\"../input/amex-data-integer-dtypes-parquet-format/train.parquet\")","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:26:55.758836Z","iopub.execute_input":"2022-07-12T05:26:55.759208Z","iopub.status.idle":"2022-07-12T05:27:21.024084Z","shell.execute_reply.started":"2022-07-12T05:26:55.759174Z","shell.execute_reply":"2022-07-12T05:27:21.022687Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels = pd.read_csv(\"../input/amex-default-prediction/train_labels.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:27:21.026562Z","iopub.execute_input":"2022-07-12T05:27:21.028014Z","iopub.status.idle":"2022-07-12T05:27:23.153758Z","shell.execute_reply.started":"2022-07-12T05:27:21.027947Z","shell.execute_reply":"2022-07-12T05:27:23.151154Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df=df.merge(labels,left_on='customer_ID',right_on='customer_ID')","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:27:23.158530Z","iopub.execute_input":"2022-07-12T05:27:23.160081Z","iopub.status.idle":"2022-07-12T05:29:04.665993Z","shell.execute_reply.started":"2022-07-12T05:27:23.159823Z","shell.execute_reply":"2022-07-12T05:29:04.664480Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"del labels\ngc.collect()","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:29:04.667991Z","iopub.execute_input":"2022-07-12T05:29:04.668407Z","iopub.status.idle":"2022-07-12T05:29:04.956119Z","shell.execute_reply.started":"2022-07-12T05:29:04.668353Z","shell.execute_reply":"2022-07-12T05:29:04.955145Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"null_val=df.isna().sum().sort_values(ascending=False)\nplt.title(\"Distribution of null values\")\nnull_val[null_val>0].plot(kind=\"hist\")","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:29:04.957432Z","iopub.execute_input":"2022-07-12T05:29:04.958979Z","iopub.status.idle":"2022-07-12T05:29:08.258251Z","shell.execute_reply.started":"2022-07-12T05:29:04.958925Z","shell.execute_reply":"2022-07-12T05:29:08.256429Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df=df.groupby('customer_ID').tail(1)","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:29:08.259873Z","iopub.execute_input":"2022-07-12T05:29:08.260196Z","iopub.status.idle":"2022-07-12T05:29:13.493761Z","shell.execute_reply.started":"2022-07-12T05:29:08.260168Z","shell.execute_reply":"2022-07-12T05:29:13.492545Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tmp=df.isna().sum().mul(100).div(len(df)).sort_values(ascending=False)\nmssing_df=pd.DataFrame(tmp).reset_index()\ndrop_colm=mssing_df[mssing_df[0]>70][\"index\"].values\nprint(drop_colm)\n","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:29:13.497975Z","iopub.execute_input":"2022-07-12T05:29:13.498392Z","iopub.status.idle":"2022-07-12T05:29:13.739936Z","shell.execute_reply.started":"2022-07-12T05:29:13.498346Z","shell.execute_reply":"2022-07-12T05:29:13.738624Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"null_val=df.isna().sum().sort_values(ascending=False)\nprint(null_val)","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:29:13.741480Z","iopub.execute_input":"2022-07-12T05:29:13.742074Z","iopub.status.idle":"2022-07-12T05:29:13.978657Z","shell.execute_reply.started":"2022-07-12T05:29:13.742037Z","shell.execute_reply":"2022-07-12T05:29:13.977219Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.title(\"Distribution of null values\")\nnull_val[null_val>0].plot(kind=\"hist\")","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:29:13.979923Z","iopub.execute_input":"2022-07-12T05:29:13.980276Z","iopub.status.idle":"2022-07-12T05:29:14.185553Z","shell.execute_reply.started":"2022-07-12T05:29:13.980245Z","shell.execute_reply":"2022-07-12T05:29:14.184264Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for col in drop_colm:\n    print(col,df[col].nunique())","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:29:14.186890Z","iopub.execute_input":"2022-07-12T05:29:14.187215Z","iopub.status.idle":"2022-07-12T05:29:14.245472Z","shell.execute_reply.started":"2022-07-12T05:29:14.187187Z","shell.execute_reply":"2022-07-12T05:29:14.244221Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop(columns=drop_colm,axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:29:14.247416Z","iopub.execute_input":"2022-07-12T05:29:14.248485Z","iopub.status.idle":"2022-07-12T05:29:14.367588Z","shell.execute_reply.started":"2022-07-12T05:29:14.248447Z","shell.execute_reply":"2022-07-12T05:29:14.366384Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat=['B_30', 'B_38', 'D_114', 'D_116', 'D_117', 'D_120', 'D_126', 'D_63', 'D_64', 'D_66', 'D_68']\ncols = df.columns\nnum_cols = df._get_numeric_data().columns\nprint(num_cols)","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:29:14.370285Z","iopub.execute_input":"2022-07-12T05:29:14.371286Z","iopub.status.idle":"2022-07-12T05:29:14.378769Z","shell.execute_reply.started":"2022-07-12T05:29:14.371231Z","shell.execute_reply":"2022-07-12T05:29:14.377502Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"numerical_columns = list(set(cols) - set(cat))\nfiltered_numerical_columns = list(set(df[numerical_columns])-{\"S_2\",\"customer_ID\"})","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:29:14.380212Z","iopub.execute_input":"2022-07-12T05:29:14.380713Z","iopub.status.idle":"2022-07-12T05:29:14.502618Z","shell.execute_reply.started":"2022-07-12T05:29:14.380679Z","shell.execute_reply":"2022-07-12T05:29:14.501392Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gc.collect()","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:29:14.504065Z","iopub.execute_input":"2022-07-12T05:29:14.504565Z","iopub.status.idle":"2022-07-12T05:29:14.683192Z","shell.execute_reply.started":"2022-07-12T05:29:14.504527Z","shell.execute_reply":"2022-07-12T05:29:14.681987Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:29:14.684810Z","iopub.execute_input":"2022-07-12T05:29:14.685382Z","iopub.status.idle":"2022-07-12T05:29:14.694644Z","shell.execute_reply.started":"2022-07-12T05:29:14.685324Z","shell.execute_reply":"2022-07-12T05:29:14.693617Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in cat:\n    print(i + \" Attribute is  of Data Type : \"+ str(df[i].dtypes))\n#converting into object\nfor i in cat:\n    df[i] = df[i].astype(\"object\")\n    print(i + \" Attribute is  of Data Type : \"+ str(df[i].dtypes))","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:29:14.697647Z","iopub.execute_input":"2022-07-12T05:29:14.698727Z","iopub.status.idle":"2022-07-12T05:29:14.993254Z","shell.execute_reply.started":"2022-07-12T05:29:14.698676Z","shell.execute_reply":"2022-07-12T05:29:14.991919Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#filtered_numerical_columns = df.select_dtypes(np.number).columns\ndf[filtered_numerical_columns] = df[filtered_numerical_columns].fillna(df[filtered_numerical_columns].mean())","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:29:14.995285Z","iopub.execute_input":"2022-07-12T05:29:14.995933Z","iopub.status.idle":"2022-07-12T05:29:15.902538Z","shell.execute_reply.started":"2022-07-12T05:29:14.995890Z","shell.execute_reply":"2022-07-12T05:29:15.901504Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"enc = OrdinalEncoder()\ndf[cat] = enc.fit_transform(df[cat])\n_ = gc.collect","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:29:15.903789Z","iopub.execute_input":"2022-07-12T05:29:15.904098Z","iopub.status.idle":"2022-07-12T05:29:18.275895Z","shell.execute_reply.started":"2022-07-12T05:29:15.904069Z","shell.execute_reply":"2022-07-12T05:29:18.274887Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"FEATURES=df.columns.drop([\"target\",\"customer_ID\",\"S_2\"])","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:29:18.277532Z","iopub.execute_input":"2022-07-12T05:29:18.278069Z","iopub.status.idle":"2022-07-12T05:29:18.284469Z","shell.execute_reply.started":"2022-07-12T05:29:18.278023Z","shell.execute_reply":"2022-07-12T05:29:18.283255Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gc.collect()","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:29:18.286303Z","iopub.execute_input":"2022-07-12T05:29:18.287271Z","iopub.status.idle":"2022-07-12T05:29:18.460977Z","shell.execute_reply.started":"2022-07-12T05:29:18.287235Z","shell.execute_reply":"2022-07-12T05:29:18.460049Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"null_val=df.isna().sum().sort_values(ascending=False)\nprint(null_val)","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:29:18.462466Z","iopub.execute_input":"2022-07-12T05:29:18.463511Z","iopub.status.idle":"2022-07-12T05:29:18.701684Z","shell.execute_reply.started":"2022-07-12T05:29:18.463455Z","shell.execute_reply":"2022-07-12T05:29:18.700530Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target=df['target']","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:29:18.703032Z","iopub.execute_input":"2022-07-12T05:29:18.703462Z","iopub.status.idle":"2022-07-12T05:29:18.708278Z","shell.execute_reply.started":"2022-07-12T05:29:18.703427Z","shell.execute_reply":"2022-07-12T05:29:18.707409Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop(columns=['target'],axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:29:18.709505Z","iopub.execute_input":"2022-07-12T05:29:18.710378Z","iopub.status.idle":"2022-07-12T05:29:18.855088Z","shell.execute_reply.started":"2022-07-12T05:29:18.710326Z","shell.execute_reply":"2022-07-12T05:29:18.853808Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gc.collect()","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:43:06.729143Z","iopub.execute_input":"2022-07-12T05:43:06.729584Z","iopub.status.idle":"2022-07-12T05:43:06.910598Z","shell.execute_reply.started":"2022-07-12T05:43:06.729548Z","shell.execute_reply":"2022-07-12T05:43:06.909325Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = np.array(df[FEATURES])\ny = np.array(target)","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:29:19.042135Z","iopub.execute_input":"2022-07-12T05:29:19.042618Z","iopub.status.idle":"2022-07-12T05:29:19.739543Z","shell.execute_reply.started":"2022-07-12T05:29:19.042581Z","shell.execute_reply":"2022-07-12T05:29:19.738274Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def objective(trial):\n    train_x, valid_x, train_y, valid_y = train_test_split(X,y, test_size=0.3)\n\n    param = {\n        \"objective\": trial.suggest_categorical(\"objective\", [\"Logloss\", \"CrossEntropy\"]),\n        \"colsample_bylevel\": trial.suggest_float(\"colsample_bylevel\", 0.01, 0.1),\n        \"depth\": trial.suggest_int(\"depth\", 1, 12),\n        \"boosting_type\": trial.suggest_categorical(\"boosting_type\", [\"Ordered\", \"Plain\"]),\n        \"bootstrap_type\": trial.suggest_categorical(\n            \"bootstrap_type\", [\"Bayesian\", \"Bernoulli\", \"MVS\"]\n        ),\n        \"used_ram_limit\": \"3gb\",\n    }\n\n    if param[\"bootstrap_type\"] == \"Bayesian\":\n        param[\"bagging_temperature\"] = trial.suggest_float(\"bagging_temperature\", 0, 10)\n    elif param[\"bootstrap_type\"] == \"Bernoulli\":\n        param[\"subsample\"] = trial.suggest_float(\"subsample\", 0.1, 1)\n\n    gbm = cb.CatBoostClassifier(**param)\n    gbm = cb.CatBoostClassifier(**param)\n\n    gbm.fit(train_x, train_y, eval_set=[(valid_x, valid_y)], verbose=0, early_stopping_rounds=100)\n\n    preds = gbm.predict(valid_x)\n    pred_labels = np.rint(preds)\n    accuracy = accuracy_score(valid_y, pred_labels)\n    return accuracy","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:29:19.741236Z","iopub.execute_input":"2022-07-12T05:29:19.741699Z","iopub.status.idle":"2022-07-12T05:29:19.753275Z","shell.execute_reply.started":"2022-07-12T05:29:19.741654Z","shell.execute_reply":"2022-07-12T05:29:19.752477Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"study = optuna.create_study(direction=\"maximize\")\nstudy.optimize(objective, n_trials=50, timeout=600)","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:29:19.754632Z","iopub.execute_input":"2022-07-12T05:29:19.754948Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Number of finished trials: {}\".format(len(study.trials)))\n\nprint(\"Best trial:\")\ntrial = study.best_trial\n\nprint(\"  Value: {}\".format(trial.value))\n\nprint(\"  Params: \")\nfor key, value in trial.params.items():\n    print(\"    {}: {}\".format(key, value))\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"param_dist = { }\nfor key, value in trial.params.items():\n    param_dist[key]=value\nparam_dist","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:43:16.918844Z","iopub.execute_input":"2022-07-12T05:43:16.919912Z","iopub.status.idle":"2022-07-12T05:43:16.927101Z","shell.execute_reply.started":"2022-07-12T05:43:16.919868Z","shell.execute_reply":"2022-07-12T05:43:16.926032Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gbm = cb.CatBoostClassifier(**param_dist,iterations=1000)","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:43:20.189292Z","iopub.execute_input":"2022-07-12T05:43:20.190023Z","iopub.status.idle":"2022-07-12T05:43:20.195596Z","shell.execute_reply.started":"2022-07-12T05:43:20.189983Z","shell.execute_reply":"2022-07-12T05:43:20.194370Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gbm.fit(X,y)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"del(df)\ngc.collect()","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:46:41.992855Z","iopub.execute_input":"2022-07-12T05:46:41.993253Z","iopub.status.idle":"2022-07-12T05:46:42.016431Z","shell.execute_reply.started":"2022-07-12T05:46:41.993220Z","shell.execute_reply":"2022-07-12T05:46:42.015007Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"d_test=pd.read_parquet(\"../input/amex-data-integer-dtypes-parquet-format/test.parquet\")","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:46:46.987235Z","iopub.execute_input":"2022-07-12T05:46:46.988645Z","iopub.status.idle":"2022-07-12T05:46:58.455227Z","shell.execute_reply.started":"2022-07-12T05:46:46.988602Z","shell.execute_reply":"2022-07-12T05:46:58.449125Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"d_test.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:47:19.864119Z","iopub.execute_input":"2022-07-12T05:47:19.865661Z","iopub.status.idle":"2022-07-12T05:47:19.872777Z","shell.execute_reply.started":"2022-07-12T05:47:19.865599Z","shell.execute_reply":"2022-07-12T05:47:19.871199Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"d_test.drop([\"S_2\"],axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:47:25.464426Z","iopub.execute_input":"2022-07-12T05:47:25.465215Z","iopub.status.idle":"2022-07-12T05:47:28.742198Z","shell.execute_reply.started":"2022-07-12T05:47:25.465172Z","shell.execute_reply":"2022-07-12T05:47:28.740853Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gc.collect()","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:47:35.531296Z","iopub.execute_input":"2022-07-12T05:47:35.531753Z","iopub.status.idle":"2022-07-12T05:47:35.712471Z","shell.execute_reply.started":"2022-07-12T05:47:35.531716Z","shell.execute_reply":"2022-07-12T05:47:35.710891Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in cat:\n    print(i + \" Attribute is  of Data Type : \"+ str(d_test[i].dtypes))\n#converting into object\nfor i in cat:\n    d_test[i] = d_test[i].astype(\"object\")\n    print(i + \" Attribute is  of Data Type : \"+ str(d_test[i].dtypes))","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:47:42.490195Z","iopub.execute_input":"2022-07-12T05:47:42.490649Z","iopub.status.idle":"2022-07-12T05:47:59.034145Z","shell.execute_reply.started":"2022-07-12T05:47:42.490611Z","shell.execute_reply":"2022-07-12T05:47:59.032426Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"enc = OrdinalEncoder()\nd_test[cat] = enc.fit_transform(d_test[cat])\n_ = gc.collect","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:48:21.746717Z","iopub.execute_input":"2022-07-12T05:48:21.747308Z","iopub.status.idle":"2022-07-12T05:49:24.193893Z","shell.execute_reply.started":"2022-07-12T05:48:21.747265Z","shell.execute_reply":"2022-07-12T05:49:24.192564Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"d_test.drop(columns=drop_colm,axis=1,inplace=True)\n","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:49:42.440289Z","iopub.execute_input":"2022-07-12T05:49:42.440771Z","iopub.status.idle":"2022-07-12T05:49:49.147743Z","shell.execute_reply.started":"2022-07-12T05:49:42.440733Z","shell.execute_reply":"2022-07-12T05:49:49.146208Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"d_test = d_test.groupby('customer_ID').tail(2).set_index('customer_ID', drop=True).sort_index()","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:51:24.148891Z","iopub.execute_input":"2022-07-12T05:51:24.150211Z","iopub.status.idle":"2022-07-12T05:51:31.156958Z","shell.execute_reply.started":"2022-07-12T05:51:24.150160Z","shell.execute_reply":"2022-07-12T05:51:31.155696Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"filtered_numerical_columns = d_test.select_dtypes(np.number).columns\nfor col in filtered_numerical_columns:\n    d_test[col] = d_test[col].fillna(d_test[col].mean())","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:51:46.377577Z","iopub.execute_input":"2022-07-12T05:51:46.378762Z","iopub.status.idle":"2022-07-12T05:51:48.503632Z","shell.execute_reply.started":"2022-07-12T05:51:46.378711Z","shell.execute_reply":"2022-07-12T05:51:48.502387Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_final=d_test.reset_index()","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:52:05.229632Z","iopub.execute_input":"2022-07-12T05:52:05.230025Z","iopub.status.idle":"2022-07-12T05:52:05.659572Z","shell.execute_reply.started":"2022-07-12T05:52:05.229994Z","shell.execute_reply":"2022-07-12T05:52:05.658205Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gc.collect()","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:52:08.747999Z","iopub.execute_input":"2022-07-12T05:52:08.748443Z","iopub.status.idle":"2022-07-12T05:52:08.947677Z","shell.execute_reply.started":"2022-07-12T05:52:08.748398Z","shell.execute_reply":"2022-07-12T05:52:08.946445Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_final.drop_duplicates(\"customer_ID\",inplace=True)\ncolumns_final=[col for col in df_final.columns if col!='customer_ID']\ntest_data=df_final[columns_final]\ntest_data.head(3)","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:52:18.857216Z","iopub.execute_input":"2022-07-12T05:52:18.857877Z","iopub.status.idle":"2022-07-12T05:52:20.120575Z","shell.execute_reply.started":"2022-07-12T05:52:18.857830Z","shell.execute_reply":"2022-07-12T05:52:20.119601Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_final.head(3)","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:52:27.461694Z","iopub.execute_input":"2022-07-12T05:52:27.462137Z","iopub.status.idle":"2022-07-12T05:52:27.504038Z","shell.execute_reply.started":"2022-07-12T05:52:27.462103Z","shell.execute_reply":"2022-07-12T05:52:27.502688Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = np.array(test_data)\ndf_final[\"prediction\"]=gbm .predict(test_data)","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:54:03.423684Z","iopub.execute_input":"2022-07-12T05:54:03.424172Z","iopub.status.idle":"2022-07-12T05:54:06.099348Z","shell.execute_reply.started":"2022-07-12T05:54:03.424132Z","shell.execute_reply":"2022-07-12T05:54:06.098085Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_final.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:54:16.776465Z","iopub.execute_input":"2022-07-12T05:54:16.777012Z","iopub.status.idle":"2022-07-12T05:54:16.785429Z","shell.execute_reply.started":"2022-07-12T05:54:16.776969Z","shell.execute_reply":"2022-07-12T05:54:16.784445Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_final.drop(columns_final,inplace=True,axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:54:41.115577Z","iopub.execute_input":"2022-07-12T05:54:41.116348Z","iopub.status.idle":"2022-07-12T05:54:41.158848Z","shell.execute_reply.started":"2022-07-12T05:54:41.116296Z","shell.execute_reply":"2022-07-12T05:54:41.157946Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_final.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:54:48.310583Z","iopub.execute_input":"2022-07-12T05:54:48.311345Z","iopub.status.idle":"2022-07-12T05:54:48.322113Z","shell.execute_reply.started":"2022-07-12T05:54:48.311308Z","shell.execute_reply":"2022-07-12T05:54:48.320811Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_final.to_csv(\"Submission_v4.csv\",index=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-12T05:54:56.618433Z","iopub.execute_input":"2022-07-12T05:54:56.618976Z","iopub.status.idle":"2022-07-12T05:55:00.310905Z","shell.execute_reply.started":"2022-07-12T05:54:56.618930Z","shell.execute_reply":"2022-07-12T05:55:00.309723Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}