{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceId":50160,"databundleVersionId":7921029,"sourceType":"competition"}],"dockerImageVersionId":30665,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))","metadata":{"execution":{"iopub.status.busy":"2024-04-04T13:59:16.653191Z","iopub.execute_input":"2024-04-04T13:59:16.653548Z","iopub.status.idle":"2024-04-04T13:59:17.686043Z","shell.execute_reply.started":"2024-04-04T13:59:16.653518Z","shell.execute_reply":"2024-04-04T13:59:17.684851Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import sys\nfrom pathlib import Path\nimport subprocess\nimport os\nimport gc\nfrom glob import glob\n\nimport numpy as np\nimport pandas as pd\nimport polars as pl\nfrom datetime import datetime\nimport seaborn as sns\nimport matplotlib.pyplot as plt\n\nimport warnings\nwarnings.filterwarnings('ignore')\n\nROOT = '/kaggle/input/home-credit-credit-risk-model-stability'","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-04-04T13:59:17.688138Z","iopub.execute_input":"2024-04-04T13:59:17.688681Z","iopub.status.idle":"2024-04-04T13:59:19.373246Z","shell.execute_reply.started":"2024-04-04T13:59:17.688624Z","shell.execute_reply":"2024-04-04T13:59:19.372190Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import TimeSeriesSplit, GroupKFold, StratifiedGroupKFold\nfrom sklearn.base import BaseEstimator, RegressorMixin\nfrom sklearn.metrics import roc_auc_score\nimport lightgbm as lgb\n\nfrom imblearn.over_sampling import SMOTE\nfrom sklearn.preprocessing import OrdinalEncoder\nfrom sklearn.impute import KNNImputer","metadata":{"execution":{"iopub.status.busy":"2024-04-04T13:59:19.374800Z","iopub.execute_input":"2024-04-04T13:59:19.375537Z","iopub.status.idle":"2024-04-04T13:59:23.810649Z","shell.execute_reply.started":"2024-04-04T13:59:19.375502Z","shell.execute_reply":"2024-04-04T13:59:23.809873Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class Pipeline:\n\n    def set_table_dtypes(df):\n        for col in df.columns:\n            if col in [\"case_id\", \"WEEK_NUM\", \"num_group1\", \"num_group2\"]:\n                df = df.with_columns(pl.col(col).cast(pl.Int64))\n            elif col in [\"date_decision\"]:\n                df = df.with_columns(pl.col(col).cast(pl.Date))\n            elif col[-1] in (\"P\", \"A\"):\n                df = df.with_columns(pl.col(col).cast(pl.Float64))\n            elif col[-1] in (\"M\",):\n                df = df.with_columns(pl.col(col).cast(pl.String))\n            elif col[-1] in (\"D\",):\n                df = df.with_columns(pl.col(col).cast(pl.Date))\n        return df\n\n    def handle_dates(df):\n        for col in df.columns:\n            if col[-1] in (\"D\",):\n                df = df.with_columns(pl.col(col) - pl.col(\"date_decision\"))  #!!?\n                df = df.with_columns(pl.col(col).dt.total_days()) # t - t-1\n        df = df.drop(\"date_decision\", \"MONTH\")\n        return df\n\n    def filter_cols(df):\n        for col in df.columns:\n            if col not in [\"target\", \"case_id\", \"WEEK_NUM\"]:\n                isnull = df[col].is_null().mean()\n                if isnull > 0.7:\n                    df = df.drop(col)\n        \n        for col in df.columns:\n            if (col not in [\"target\", \"case_id\", \"WEEK_NUM\"]) & (df[col].dtype == pl.String):\n                freq = df[col].n_unique()\n                if (freq == 1) | (freq > 200):\n                    df = df.drop(col)\n        \n        return df","metadata":{"execution":{"iopub.status.busy":"2024-04-04T13:59:23.813247Z","iopub.execute_input":"2024-04-04T13:59:23.814444Z","iopub.status.idle":"2024-04-04T13:59:23.826384Z","shell.execute_reply.started":"2024-04-04T13:59:23.814406Z","shell.execute_reply":"2024-04-04T13:59:23.825524Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class Aggregator:\n    \n    def num_expr(df):\n        cols = [col for col in df.columns if col[-1] in (\"P\", \"A\")]\n        expr_max = [pl.max(col).alias(f\"max_{col}\") for col in cols]\n        return expr_max\n    \n    def date_expr(df):\n        cols = [col for col in df.columns if col[-1] in (\"D\")]\n        expr_max = [pl.max(col).alias(f\"max_{col}\") for col in cols]\n        return expr_max\n    \n    def str_expr(df):\n        cols = [col for col in df.columns if col[-1] in (\"M\",)]\n        expr_max = [pl.max(col).alias(f\"max_{col}\") for col in cols]\n        return expr_max\n    \n    def other_expr(df):\n        cols = [col for col in df.columns if col[-1] in (\"T\", \"L\")]\n        expr_max = [pl.max(col).alias(f\"max_{col}\") for col in cols]\n        return expr_max\n    \n    def count_expr(df):\n        cols = [col for col in df.columns if \"num_group\" in col]\n        expr_max = [pl.max(col).alias(f\"max_{col}\") for col in cols]  # max & replace col name\n        return expr_max\n    \n    def get_exprs(df):\n        exprs = Aggregator.num_expr(df) + \\\n                Aggregator.date_expr(df) + \\\n                Aggregator.str_expr(df) + \\\n                Aggregator.other_expr(df) + \\\n                Aggregator.count_expr(df)\n\n        return exprs","metadata":{"execution":{"iopub.status.busy":"2024-04-04T13:59:23.828094Z","iopub.execute_input":"2024-04-04T13:59:23.828445Z","iopub.status.idle":"2024-04-04T13:59:23.847565Z","shell.execute_reply.started":"2024-04-04T13:59:23.828421Z","shell.execute_reply":"2024-04-04T13:59:23.846585Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def read_file(path, depth=None):\n    df = pl.read_parquet(path)\n    df = df.pipe(Pipeline.set_table_dtypes)\n    if depth in [1,2]:\n        df = df.group_by(\"case_id\").agg(Aggregator.get_exprs(df)) \n    return df\n\ndef read_files(regex_path, depth=None):\n    chunks = []\n    \n    for path in glob(str(regex_path)):\n        df = pl.read_parquet(path)\n        df = df.pipe(Pipeline.set_table_dtypes)\n        if depth in [1, 2]:\n            df = df.group_by(\"case_id\").agg(Aggregator.get_exprs(df))\n        chunks.append(df)\n    \n    df = pl.concat(chunks, how=\"vertical_relaxed\")\n    df = df.unique(subset=[\"case_id\"])\n    return df","metadata":{"execution":{"iopub.status.busy":"2024-04-04T13:59:23.848651Z","iopub.execute_input":"2024-04-04T13:59:23.848909Z","iopub.status.idle":"2024-04-04T13:59:23.862167Z","shell.execute_reply.started":"2024-04-04T13:59:23.848886Z","shell.execute_reply":"2024-04-04T13:59:23.861392Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def feature_eng(df_base, depth_0, depth_1, depth_2):\n    df_base = (\n        df_base\n        .with_columns(\n            month_decision = pl.col(\"date_decision\").dt.month(),\n            weekday_decision = pl.col(\"date_decision\").dt.weekday(),\n        )\n    )\n    for i, df in enumerate(depth_0 + depth_1 + depth_2):\n        df_base = df_base.join(df, how=\"left\", on=\"case_id\", suffix=f\"_{i}\")\n    df_base = df_base.pipe(Pipeline.handle_dates)\n    return df_base","metadata":{"execution":{"iopub.status.busy":"2024-04-04T13:59:23.863481Z","iopub.execute_input":"2024-04-04T13:59:23.864019Z","iopub.status.idle":"2024-04-04T13:59:23.872892Z","shell.execute_reply.started":"2024-04-04T13:59:23.863994Z","shell.execute_reply":"2024-04-04T13:59:23.872145Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def to_pandas(df_data, cat_cols=None):\n    df_data = df_data.to_pandas()\n    if cat_cols is None:\n        cat_cols = list(df_data.select_dtypes(\"object\").columns)\n    df_data[cat_cols] = df_data[cat_cols].astype(\"category\")\n    return df_data, cat_cols","metadata":{"execution":{"iopub.status.busy":"2024-04-04T13:59:23.873899Z","iopub.execute_input":"2024-04-04T13:59:23.874220Z","iopub.status.idle":"2024-04-04T13:59:23.884923Z","shell.execute_reply.started":"2024-04-04T13:59:23.874196Z","shell.execute_reply":"2024-04-04T13:59:23.884236Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ROOT            = Path(\"/kaggle/input/home-credit-credit-risk-model-stability\")\n\nTRAIN_DIR       = ROOT / \"parquet_files\" / \"train\"\nTEST_DIR        = ROOT / \"parquet_files\" / \"test\"","metadata":{"execution":{"iopub.status.busy":"2024-04-04T13:59:23.885820Z","iopub.execute_input":"2024-04-04T13:59:23.886092Z","iopub.status.idle":"2024-04-04T13:59:23.893855Z","shell.execute_reply.started":"2024-04-04T13:59:23.886058Z","shell.execute_reply":"2024-04-04T13:59:23.892986Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_store = {\n    \"df_base\": read_file(TRAIN_DIR / \"train_base.parquet\"),\n    \"depth_0\": [\n        read_file(TRAIN_DIR / \"train_static_cb_0.parquet\"),\n        read_files(TRAIN_DIR / \"train_static_0_*.parquet\"),\n    ],\n    \"depth_1\": [\n        read_files(TRAIN_DIR / \"train_applprev_1_*.parquet\", 1),\n        read_file(TRAIN_DIR / \"train_tax_registry_a_1.parquet\", 1),\n        read_file(TRAIN_DIR / \"train_tax_registry_b_1.parquet\", 1),\n        read_file(TRAIN_DIR / \"train_tax_registry_c_1.parquet\", 1),\n        read_files(TRAIN_DIR / \"train_credit_bureau_a_1_*.parquet\", 1),\n        read_file(TRAIN_DIR / \"train_credit_bureau_b_1.parquet\", 1),\n        read_file(TRAIN_DIR / \"train_other_1.parquet\", 1),\n        read_file(TRAIN_DIR / \"train_person_1.parquet\", 1),\n        read_file(TRAIN_DIR / \"train_deposit_1.parquet\", 1),\n        read_file(TRAIN_DIR / \"train_debitcard_1.parquet\", 1),\n    ],\n    \"depth_2\": [\n        read_file(TRAIN_DIR / \"train_credit_bureau_b_2.parquet\", 2),\n        read_files(TRAIN_DIR / \"train_credit_bureau_a_2_*.parquet\", 2),\n        read_file(TRAIN_DIR / \"train_applprev_2.parquet\", 2),\n        read_file(TRAIN_DIR / \"train_person_2.parquet\", 2)\n    ]\n}","metadata":{"execution":{"iopub.status.busy":"2024-04-04T13:59:23.897308Z","iopub.execute_input":"2024-04-04T13:59:23.897572Z","iopub.status.idle":"2024-04-04T14:01:28.825615Z","shell.execute_reply.started":"2024-04-04T13:59:23.897550Z","shell.execute_reply":"2024-04-04T14:01:28.824553Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train = feature_eng(**data_store)\nprint(\"train data shape:\\t\", df_train.shape)","metadata":{"execution":{"iopub.status.busy":"2024-04-04T14:01:28.826951Z","iopub.execute_input":"2024-04-04T14:01:28.827362Z","iopub.status.idle":"2024-04-04T14:01:38.195521Z","shell.execute_reply.started":"2024-04-04T14:01:28.827327Z","shell.execute_reply":"2024-04-04T14:01:38.194631Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_store = {\n    \"df_base\": read_file(TEST_DIR / \"test_base.parquet\"),\n    \"depth_0\": [\n        read_file(TEST_DIR / \"test_static_cb_0.parquet\"),\n        read_files(TEST_DIR / \"test_static_0_*.parquet\"),\n    ],\n    \"depth_1\": [\n        read_files(TEST_DIR / \"test_applprev_1_*.parquet\", 1),\n        read_file(TEST_DIR / \"test_tax_registry_a_1.parquet\", 1),\n        read_file(TEST_DIR / \"test_tax_registry_b_1.parquet\", 1),\n        read_file(TEST_DIR / \"test_tax_registry_c_1.parquet\", 1),\n        read_files(TEST_DIR / \"test_credit_bureau_a_1_*.parquet\", 1),\n        read_file(TEST_DIR / \"test_credit_bureau_b_1.parquet\", 1),\n        read_file(TEST_DIR / \"test_other_1.parquet\", 1),\n        read_file(TEST_DIR / \"test_person_1.parquet\", 1),\n        read_file(TEST_DIR / \"test_deposit_1.parquet\", 1),\n        read_file(TEST_DIR / \"test_debitcard_1.parquet\", 1),\n    ],\n    \"depth_2\": [\n        read_file(TEST_DIR / \"test_credit_bureau_b_2.parquet\", 2),\n        read_files(TEST_DIR / \"test_credit_bureau_a_2_*.parquet\", 2),\n        read_file(TEST_DIR / \"test_applprev_2.parquet\", 2),\n        read_file(TEST_DIR / \"test_person_2.parquet\", 2)\n    ]\n}","metadata":{"execution":{"iopub.status.busy":"2024-04-04T14:01:38.196573Z","iopub.execute_input":"2024-04-04T14:01:38.196825Z","iopub.status.idle":"2024-04-04T14:01:38.837784Z","shell.execute_reply.started":"2024-04-04T14:01:38.196803Z","shell.execute_reply":"2024-04-04T14:01:38.836781Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test = feature_eng(**data_store)\nprint(\"test data shape:\\t\", df_test.shape)","metadata":{"execution":{"iopub.status.busy":"2024-04-04T14:01:38.838946Z","iopub.execute_input":"2024-04-04T14:01:38.839247Z","iopub.status.idle":"2024-04-04T14:01:38.875599Z","shell.execute_reply.started":"2024-04-04T14:01:38.839222Z","shell.execute_reply":"2024-04-04T14:01:38.874712Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Feature Selection","metadata":{}},{"cell_type":"code","source":"# Drop the insignificant features\ndf_train = df_train.pipe(Pipeline.filter_cols)\ndf_test = df_test.select([col for col in df_train.columns if col != \"target\"])\n\nprint(\"train data shape:\\t\", df_train.shape)\nprint(\"test data shape:\\t\", df_test.shape)","metadata":{"execution":{"iopub.status.busy":"2024-04-04T14:01:38.899423Z","iopub.execute_input":"2024-04-04T14:01:38.899663Z","iopub.status.idle":"2024-04-04T14:01:41.904033Z","shell.execute_reply.started":"2024-04-04T14:01:38.899642Z","shell.execute_reply":"2024-04-04T14:01:41.903027Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train, cat_cols = to_pandas(df_train)\ndf_test, cat_cols = to_pandas(df_test, cat_cols)","metadata":{"execution":{"iopub.status.busy":"2024-04-04T14:01:41.905161Z","iopub.execute_input":"2024-04-04T14:01:41.906653Z","iopub.status.idle":"2024-04-04T14:02:02.867485Z","shell.execute_reply.started":"2024-04-04T14:01:41.906626Z","shell.execute_reply":"2024-04-04T14:02:02.866581Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"del data_store\ngc.collect()","metadata":{"execution":{"iopub.status.busy":"2024-04-04T14:02:02.868662Z","iopub.execute_input":"2024-04-04T14:02:02.868968Z","iopub.status.idle":"2024-04-04T14:02:03.001488Z","shell.execute_reply.started":"2024-04-04T14:02:02.868943Z","shell.execute_reply":"2024-04-04T14:02:03.000670Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"display(df_train.head())\ndisplay(df_test.head())","metadata":{"execution":{"iopub.status.busy":"2024-04-04T14:02:03.002693Z","iopub.execute_input":"2024-04-04T14:02:03.002971Z","iopub.status.idle":"2024-04-04T14:02:03.062270Z","shell.execute_reply.started":"2024-04-04T14:02:03.002942Z","shell.execute_reply":"2024-04-04T14:02:03.061453Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = df_train.drop(columns=[\"target\", \"case_id\", \"WEEK_NUM\"])\ny = df_train[\"target\"]\nweeks = df_train[\"WEEK_NUM\"]\n\ncv = StratifiedGroupKFold(n_splits=5, shuffle=False)\n\nparams = {\n    \"boosting_type\": \"gbdt\",\n    \"objective\": \"binary\",\n    \"metric\": \"auc\",\n    \"max_depth\": 10,  \n    \"learning_rate\": 0.05,\n    \"n_estimators\": 2000,  \n    \"colsample_bytree\": 0.8,\n    \"colsample_bynode\": 0.8,\n    \"verbose\": -1,\n    \"random_state\": 42,\n    \"reg_alpha\": 0.1,\n    \"reg_lambda\": 10,\n    \"extra_trees\":True,\n    'num_leaves':64,\n    \"device\": \"gpu\", \n    \"verbose\": -1,\n}\n\nfitted_models = []\ncv_scores = []\n\nfor idx_train, idx_valid in cv.split(X, y, groups=weeks):\n    X_train, y_train = X.iloc[idx_train], y.iloc[idx_train]\n    X_valid, y_valid = X.iloc[idx_valid], y.iloc[idx_valid]\n    \n    model = lgb.LGBMClassifier(**params)\n    model.fit(\n        X_train, y_train,\n        eval_set = [(X_valid, y_valid)],\n        callbacks = [lgb.log_evaluation(200), lgb.early_stopping(60)] )\n    fitted_models.append(model)\n    \n    y_pred_valid = model.predict_proba(X_valid)[:,1]\n    auc_score = roc_auc_score(y_valid, y_pred_valid)\n    cv_scores.append(auc_score)\n    \nprint(\"CV AUC scores: \", cv_scores)\nprint(\"Maximum CV AUC score: \", max(cv_scores))","metadata":{"execution":{"iopub.status.busy":"2024-04-04T14:02:03.107733Z","iopub.execute_input":"2024-04-04T14:02:03.107979Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class VotingModel(BaseEstimator, RegressorMixin):\n    def __init__(self, estimators):\n        super().__init__()\n        self.estimators = estimators\n        \n    def fit(self, X, y=None):\n        return self\n    \n    def predict(self, X):\n        y_preds = [estimator.predict(X) for estimator in self.estimators]\n        return np.mean(y_preds, axis=0)\n    \n    def predict_proba(self, X):\n        y_preds = [estimator.predict_proba(X) for estimator in self.estimators]\n        return np.mean(y_preds, axis=0)\n\nmodel = VotingModel(fitted_models)","metadata":{"execution":{"iopub.status.busy":"2024-04-04T14:33:25.121412Z","iopub.execute_input":"2024-04-04T14:33:25.122100Z","iopub.status.idle":"2024-04-04T14:33:25.129255Z","shell.execute_reply.started":"2024-04-04T14:33:25.122069Z","shell.execute_reply":"2024-04-04T14:33:25.128279Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lgb.plot_importance(fitted_models[2], importance_type=\"split\", figsize=(10,50))\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-04-04T14:33:34.834093Z","iopub.execute_input":"2024-04-04T14:33:34.834751Z","iopub.status.idle":"2024-04-04T14:33:39.283486Z","shell.execute_reply.started":"2024-04-04T14:33:34.834718Z","shell.execute_reply":"2024-04-04T14:33:39.281881Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"features = X_train.columns\nimportances = fitted_models[2].feature_importances_\nfeature_importance = pd.DataFrame({'importance':importances,'features':features}).sort_values('importance', ascending=False).reset_index(drop=True)\nfeature_importance","metadata":{"execution":{"iopub.status.busy":"2024-04-04T14:35:46.814884Z","iopub.execute_input":"2024-04-04T14:35:46.815508Z","iopub.status.idle":"2024-04-04T14:35:46.829679Z","shell.execute_reply.started":"2024-04-04T14:35:46.815478Z","shell.execute_reply":"2024-04-04T14:35:46.828630Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"drop_list = []\nfor i, f in feature_importance.iterrows():\n    if f['importance']<80:\n        drop_list.append(f['features'])\nprint(f\"Number of features which are not important: {len(drop_list)} \")","metadata":{"execution":{"iopub.status.busy":"2024-04-04T14:35:57.900010Z","iopub.execute_input":"2024-04-04T14:35:57.900794Z","iopub.status.idle":"2024-04-04T14:35:57.925478Z","shell.execute_reply.started":"2024-04-04T14:35:57.900762Z","shell.execute_reply":"2024-04-04T14:35:57.924383Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(drop_list)","metadata":{"execution":{"iopub.status.busy":"2024-04-04T14:36:07.349360Z","iopub.execute_input":"2024-04-04T14:36:07.349740Z","iopub.status.idle":"2024-04-04T14:36:07.354861Z","shell.execute_reply.started":"2024-04-04T14:36:07.349715Z","shell.execute_reply":"2024-04-04T14:36:07.353891Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Submission","metadata":{}},{"cell_type":"code","source":"X_test = df_test.drop(columns=[\"WEEK_NUM\"])\nX_test = X_test.set_index(\"case_id\")\n\nlgb_pred = pd.Series(model.predict_proba(X_test)[:, 1], index=X_test.index)","metadata":{"execution":{"iopub.status.busy":"2024-04-04T14:36:17.613036Z","iopub.execute_input":"2024-04-04T14:36:17.613727Z","iopub.status.idle":"2024-04-04T14:36:17.924646Z","shell.execute_reply.started":"2024-04-04T14:36:17.613696Z","shell.execute_reply":"2024-04-04T14:36:17.923747Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_subm = pd.read_csv(ROOT / \"sample_submission.csv\")\ndf_subm = df_subm.set_index(\"case_id\")\n\ndf_subm[\"score\"] = lgb_pred","metadata":{"execution":{"iopub.status.busy":"2024-04-04T14:36:28.634403Z","iopub.execute_input":"2024-04-04T14:36:28.635050Z","iopub.status.idle":"2024-04-04T14:36:28.668301Z","shell.execute_reply.started":"2024-04-04T14:36:28.635021Z","shell.execute_reply":"2024-04-04T14:36:28.667439Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_subm.head()","metadata":{"execution":{"iopub.status.busy":"2024-04-04T14:36:34.918779Z","iopub.execute_input":"2024-04-04T14:36:34.919537Z","iopub.status.idle":"2024-04-04T14:36:34.928293Z","shell.execute_reply.started":"2024-04-04T14:36:34.919504Z","shell.execute_reply":"2024-04-04T14:36:34.927389Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_subm.to_csv(\"submission.csv\")","metadata":{"execution":{"iopub.status.busy":"2024-04-04T14:36:44.518680Z","iopub.execute_input":"2024-04-04T14:36:44.519316Z","iopub.status.idle":"2024-04-04T14:36:44.525092Z","shell.execute_reply.started":"2024-04-04T14:36:44.519287Z","shell.execute_reply":"2024-04-04T14:36:44.524098Z"},"trusted":true},"execution_count":null,"outputs":[]}]}