{"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":"markdown","source":"## Prediction using model trained with LGBM\n\n[Training Notebook](https://www.kaggle.com/code/bhavesjain/amex-default-pred-train?scriptVersionId=99324580)","metadata":{}},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nfrom tqdm import tqdm \nimport os\n\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.preprocessing import MinMaxScaler\n\n\nimport xgboost as xgb\nimport lightgbm as lgb","metadata":{"_uuid":"e563816f-0437-41d6-a429-66756662d01f","_cell_guid":"1fe20b70-6438-4568-a519-715bc21471e4","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2022-06-26T02:28:34.654976Z","iopub.execute_input":"2022-06-26T02:28:34.655413Z","iopub.status.idle":"2022-06-26T02:28:35.848255Z","shell.execute_reply.started":"2022-06-26T02:28:34.655377Z","shell.execute_reply":"2022-06-26T02:28:35.847025Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv(\"../input/d/datasets/bhavesjain/amex-default-prediction/test-last-rows.csv\")\ndf.fillna(df.mode().iloc[0],inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-06-26T02:25:50.509365Z","iopub.execute_input":"2022-06-26T02:25:50.509778Z","iopub.status.idle":"2022-06-26T02:27:44.923715Z","shell.execute_reply.started":"2022-06-26T02:25:50.509745Z","shell.execute_reply":"2022-06-26T02:27:44.922413Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"scaler = MinMaxScaler()","metadata":{"execution":{"iopub.status.busy":"2022-06-26T02:27:44.925530Z","iopub.execute_input":"2022-06-26T02:27:44.925874Z","iopub.status.idle":"2022-06-26T02:27:44.931901Z","shell.execute_reply.started":"2022-06-26T02:27:44.925843Z","shell.execute_reply":"2022-06-26T02:27:44.930457Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_cols = [col for col in df.columns[2:] if col not in ['D_63','D_64']]","metadata":{"execution":{"iopub.status.busy":"2022-06-26T02:27:44.933553Z","iopub.execute_input":"2022-06-26T02:27:44.933934Z","iopub.status.idle":"2022-06-26T02:27:44.944714Z","shell.execute_reply.started":"2022-06-26T02:27:44.933903Z","shell.execute_reply":"2022-06-26T02:27:44.943781Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[x_cols] = scaler.fit_transform(df[x_cols])","metadata":{"execution":{"iopub.status.busy":"2022-06-26T02:27:44.947409Z","iopub.execute_input":"2022-06-26T02:27:44.948150Z","iopub.status.idle":"2022-06-26T02:27:48.248586Z","shell.execute_reply.started":"2022-06-26T02:27:44.948101Z","shell.execute_reply":"2022-06-26T02:27:48.247321Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# model = xgb.XGBClassifier()\n# model.load_model(\"../input/amex-default-pred-train/model.json\")\n# pred = model.predict_proba(df[x_cols])[:,1]","metadata":{"execution":{"iopub.status.busy":"2022-06-26T02:28:09.292306Z","iopub.execute_input":"2022-06-26T02:28:09.292761Z","iopub.status.idle":"2022-06-26T02:28:09.297956Z","shell.execute_reply.started":"2022-06-26T02:28:09.292702Z","shell.execute_reply":"2022-06-26T02:28:09.296689Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = lgb.Booster(model_file='../input/amex-default-pred-train/lgb_model.json')\npred = model.predict(df[x_cols])","metadata":{"execution":{"iopub.status.busy":"2022-06-26T02:29:21.424618Z","iopub.execute_input":"2022-06-26T02:29:21.425040Z","iopub.status.idle":"2022-06-26T02:31:30.343210Z","shell.execute_reply.started":"2022-06-26T02:29:21.425005Z","shell.execute_reply":"2022-06-26T02:31:30.341665Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[\"prediction\"] = pred","metadata":{"execution":{"iopub.status.busy":"2022-06-26T02:31:30.346238Z","iopub.execute_input":"2022-06-26T02:31:30.347011Z","iopub.status.idle":"2022-06-26T02:31:30.357057Z","shell.execute_reply.started":"2022-06-26T02:31:30.346968Z","shell.execute_reply":"2022-06-26T02:31:30.355760Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df = df[[\"customer_ID\",\"prediction\"]]","metadata":{"execution":{"iopub.status.busy":"2022-06-26T02:31:30.362157Z","iopub.execute_input":"2022-06-26T02:31:30.363438Z","iopub.status.idle":"2022-06-26T02:31:31.392328Z","shell.execute_reply.started":"2022-06-26T02:31:30.363374Z","shell.execute_reply":"2022-06-26T02:31:31.390619Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-06-26T02:31:31.394789Z","iopub.execute_input":"2022-06-26T02:31:31.395186Z","iopub.status.idle":"2022-06-26T02:31:31.413025Z","shell.execute_reply.started":"2022-06-26T02:31:31.395152Z","shell.execute_reply":"2022-06-26T02:31:31.411849Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df.to_csv(\"submission.csv\",index=False)","metadata":{"execution":{"iopub.status.busy":"2022-06-26T02:32:36.155698Z","iopub.execute_input":"2022-06-26T02:32:36.156199Z","iopub.status.idle":"2022-06-26T02:32:41.655901Z","shell.execute_reply.started":"2022-06-26T02:32:36.156158Z","shell.execute_reply":"2022-06-26T02:32:41.654372Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}