{"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":7602123,"sourceType":"competition"},{"sourceId":7487967,"sourceType":"datasetVersion","datasetId":3933894}],"dockerImageVersionId":30646,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import os, glob\nimport pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom pathlib import Path\n\nPATH_DATASET = Path(\"/kaggle/input/home-credit-credit-risk-model-stability\")\nPATH_PARQUETS = PATH_DATASET / \"parquet_files\"\nPATH_TRAIN = PATH_PARQUETS / \"train\"\nPATH_TEST = PATH_PARQUETS / \"test\"\npd.set_option('display.max_columns', None)\npd.set_option('display.max_rows', None)","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-02-07T05:59:39.397380Z","iopub.execute_input":"2024-02-07T05:59:39.398012Z","iopub.status.idle":"2024-02-07T05:59:41.345117Z","shell.execute_reply.started":"2024-02-07T05:59:39.397978Z","shell.execute_reply":"2024-02-07T05:59:41.344092Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Explore the training data\n\n**Borrowed from the competition describtion:**\n\nTable Description\nThis dataset contains a large number of tables as a result of utilizing diverse data sources and the varying levels of data aggregation used while preparing the dataset. Note: All files listed below are found in both .csv and .parquet formats.\n\n### Depth values\n\n- **depth=0** - These are static features directly tied to a specific case_id.\n- **depth=1** - Each case_id has an associated historical record, indexed by num_group1.\n- **depth=2** - Each case_id has an associated historical record, indexed by both num_group1 and num_group2.\n\nYou can read more about Credit bureau (CB) here https://en.wikipedia.org/wiki/Credit_bureau.","metadata":{}},{"cell_type":"code","source":"!cat /kaggle/input/home-credit-credit-risk-model-stability/feature_definitions.csv","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2024-02-07T05:59:52.252508Z","iopub.execute_input":"2024-02-07T05:59:52.253015Z","iopub.status.idle":"2024-02-07T05:59:53.237621Z","shell.execute_reply.started":"2024-02-07T05:59:52.252981Z","shell.execute_reply":"2024-02-07T05:59:53.236361Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def convert_dtypes(df):\n    for col, dtype in dict(df.dtypes).items():\n        if str(dtype).startswith(\"int\"):\n            df[col] = df[col].astype(\"int32\")\n        elif str(dtype).startswith(\"float\"):\n            df[col] = df[col].astype(\"float32\")\n        else:\n            print(f'{col} -> {df[col].nunique()}')\n            df[col] = df[col].astype(\"category\")","metadata":{"execution":{"iopub.status.busy":"2024-02-07T06:00:15.851904Z","iopub.execute_input":"2024-02-07T06:00:15.852798Z","iopub.status.idle":"2024-02-07T06:00:15.859851Z","shell.execute_reply.started":"2024-02-07T06:00:15.852767Z","shell.execute_reply":"2024-02-07T06:00:15.858297Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Base tables\n\nBase tables store the basic information about the observation and case_id. This is a unique identification of every observation and you need to use it to join the other tables to base tables.\n\ntrain_base.csv","metadata":{}},{"cell_type":"code","source":"df_train = pd.read_parquet(PATH_TRAIN / \"train_base.parquet\")\nprint(f\"size: {len(df_train)}\")\ndisplay(df_train.head())","metadata":{"execution":{"iopub.status.busy":"2024-02-07T06:00:23.468806Z","iopub.execute_input":"2024-02-07T06:00:23.469527Z","iopub.status.idle":"2024-02-07T06:00:23.877358Z","shell.execute_reply.started":"2024-02-07T06:00:23.469482Z","shell.execute_reply":"2024-02-07T06:00:23.876437Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train[\"date_decision\"] = pd.to_datetime(df_train[\"date_decision\"]).dt.date\n# delete redundat cols\ndel df_train[\"MONTH\"], df_train[\"WEEK_NUM\"]","metadata":{"execution":{"iopub.status.busy":"2024-02-07T06:00:28.092174Z","iopub.execute_input":"2024-02-07T06:00:28.092521Z","iopub.status.idle":"2024-02-07T06:00:28.848357Z","shell.execute_reply.started":"2024-02-07T06:00:28.092494Z","shell.execute_reply":"2024-02-07T06:00:28.847552Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def merge_table(df, name, folder=PATH_TRAIN, prefix=\"train\"):\n    dft_ = pd.read_parquet(folder / f\"{prefix}_{name}.parquet\")\n    print(f\"size: {len(dft_)} with features: {len(dft_.columns)}\")\n    display(dft_.head())\n    convert_dtypes(dft_)\n    df = df.merge(dft_, how=\"left\", on=\"case_id\")\n    return df","metadata":{"execution":{"iopub.status.busy":"2024-02-07T06:00:34.637192Z","iopub.execute_input":"2024-02-07T06:00:34.637948Z","iopub.status.idle":"2024-02-07T06:00:34.643629Z","shell.execute_reply.started":"2024-02-07T06:00:34.637911Z","shell.execute_reply":"2024-02-07T06:00:34.642589Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def merge_tables(df, name, folder=PATH_TRAIN, prefix=\"train\"):\n    dft_ = pd.concat(\n        [pd.read_parquet(p) for p in glob.glob(str(folder / f\"{prefix}_{name}_*\"))],\n    )\n    print(f\"size: {len(dft_)} with features: {len(dft_.columns)}\")\n    display(dft_.head())\n    convert_dtypes(dft_)\n    df = df.merge(dft_, how=\"left\", on=\"case_id\")\n    return df","metadata":{"execution":{"iopub.status.busy":"2024-02-07T06:00:39.712226Z","iopub.execute_input":"2024-02-07T06:00:39.712652Z","iopub.status.idle":"2024-02-07T06:00:39.719938Z","shell.execute_reply.started":"2024-02-07T06:00:39.712624Z","shell.execute_reply":"2024-02-07T06:00:39.718904Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Depth 0\n\n### static_0 | Properties: depth=0, internal data source\n\n- train_static_0_0.csv\n- train_static_0_1.csv\n\n### static_cb_0 | Properties: depth=0, external data source\n\n- train_static_cb_0.csv","metadata":{}},{"cell_type":"code","source":"df_train = merge_tables(df_train, \"static_0\")","metadata":{"execution":{"iopub.status.busy":"2024-02-07T06:00:48.012011Z","iopub.execute_input":"2024-02-07T06:00:48.012816Z","iopub.status.idle":"2024-02-07T06:01:06.154446Z","shell.execute_reply.started":"2024-02-07T06:00:48.012771Z","shell.execute_reply":"2024-02-07T06:01:06.153436Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train = merge_table(df_train, \"static_cb_0\")","metadata":{"execution":{"iopub.status.busy":"2024-02-07T06:01:06.631712Z","iopub.execute_input":"2024-02-07T06:01:06.632603Z","iopub.status.idle":"2024-02-07T06:01:11.729572Z","shell.execute_reply.started":"2024-02-07T06:01:06.632571Z","shell.execute_reply":"2024-02-07T06:01:11.728558Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Depth 1\n\n### applprev_1 | Properties: depth=1, internal data source\n\n- train_applprev_1_0.csv\n- train_applprev_1_1.csv\n\n### other_1 | Properties: depth=1, internal data source\n\n- train_other_1.csv\n\n### tax_registry_a_1 | Properties: depth=1, external data source, Tax registry provider A\n\n- train_tax_registry_a_1.csv\n\n### tax_registry_b_1 | Properties: depth=1, external data source, Tax registry provider B\n\n- train_tax_registry_b_1.csv\n\n### tax_registry_c_1 | Properties: depth=1, external data source, Tax registry provider C\n\n- train_tax_registry_c_1.csv\n\n### credit_bureau_a_1 | Properties: depth=1, external data source, Credit bureau provider A\n\n- train_credit_bureau_a_1_0.csv\n- train_credit_bureau_a_1_1.csv\n- train_credit_bureau_a_1_2.csv\n- train_credit_bureau_a_1_3.csv\n\n### credit_bureau_b_1 | Properties: depth=1, external data source, Credit bureau provider B\n\n- train_credit_bureau_b_1.csv\n\n### deposit_1 | Properties: depth=1, internal data source\n\n- train_deposit_1.csv\n\n### person_1 | Properties: depth=1, internal data source\n\n- train_person_1.csv\n\n### debitcard_1 | Properties: depth=1, internal data source\n\n- train_debitcard_1.csv","metadata":{}},{"cell_type":"code","source":"# df_train = merge_tables(df_train, \"applprev_1\")","metadata":{"execution":{"iopub.status.busy":"2024-02-07T06:01:17.241756Z","iopub.execute_input":"2024-02-07T06:01:17.242583Z","iopub.status.idle":"2024-02-07T06:01:17.246386Z","shell.execute_reply.started":"2024-02-07T06:01:17.242550Z","shell.execute_reply":"2024-02-07T06:01:17.245422Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train = merge_table(df_train, \"other_1\")","metadata":{"execution":{"iopub.status.busy":"2024-02-07T06:01:20.307136Z","iopub.execute_input":"2024-02-07T06:01:20.307484Z","iopub.status.idle":"2024-02-07T06:01:21.320231Z","shell.execute_reply.started":"2024-02-07T06:01:20.307457Z","shell.execute_reply":"2024-02-07T06:01:21.319434Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train = merge_table(df_train, \"deposit_1\")","metadata":{"execution":{"iopub.status.busy":"2024-02-07T06:01:23.531988Z","iopub.execute_input":"2024-02-07T06:01:23.532345Z","iopub.status.idle":"2024-02-07T06:01:25.278757Z","shell.execute_reply.started":"2024-02-07T06:01:23.532316Z","shell.execute_reply":"2024-02-07T06:01:25.277970Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train = merge_table(df_train, \"person_1\")","metadata":{"execution":{"iopub.status.busy":"2024-02-07T06:01:27.246944Z","iopub.execute_input":"2024-02-07T06:01:27.247299Z","iopub.status.idle":"2024-02-07T06:01:45.943880Z","shell.execute_reply.started":"2024-02-07T06:01:27.247272Z","shell.execute_reply":"2024-02-07T06:01:45.942856Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# TODO","metadata":{"execution":{"iopub.status.busy":"2024-02-07T06:01:45.945980Z","iopub.execute_input":"2024-02-07T06:01:45.946319Z","iopub.status.idle":"2024-02-07T06:01:45.950384Z","shell.execute_reply.started":"2024-02-07T06:01:45.946289Z","shell.execute_reply":"2024-02-07T06:01:45.949387Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Depth 2\n\n### applprev_2 | Properties: depth=2, internal data source\n\n- train_applprev_2.csv\n\n### person_2 | Properties: depth=2, internal data source\n\n- train_person_2.csv\n\n### redit_bureau_a_2 | Properties: depth=2, external data source, Credit bureau provider A\n\n- train_credit_bureau_a_2_0.csv\n- train_credit_bureau_a_2_1.csv\n- train_credit_bureau_a_2_2.csv\n- train_credit_bureau_a_2_3.csv\n- train_credit_bureau_a_2_4.csv\n- train_credit_bureau_a_2_5.csv\n- train_credit_bureau_a_2_6.csv\n- train_credit_bureau_a_2_7.csv\n- train_credit_bureau_a_2_8.csv\n- train_credit_bureau_a_2_9.csv\n- train_credit_bureau_a_2_10.csv\n\n### credit_bureau_b_2 | Properties: depth=2, external data source, Credit bureau provider B\n\n- train_credit_bureau_b_2.csv","metadata":{}},{"cell_type":"code","source":"# TODO","metadata":{"execution":{"iopub.status.busy":"2024-02-07T06:01:48.702149Z","iopub.execute_input":"2024-02-07T06:01:48.702876Z","iopub.status.idle":"2024-02-07T06:01:48.706743Z","shell.execute_reply.started":"2024-02-07T06:01:48.702844Z","shell.execute_reply":"2024-02-07T06:01:48.705708Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Brows the data","metadata":{}},{"cell_type":"code","source":"print(f\"data size: {len(df_train)}\")\nprint(f\"unique: {len(df_train['case_id'].unique())}\")","metadata":{"execution":{"iopub.status.busy":"2024-02-07T06:01:51.161663Z","iopub.execute_input":"2024-02-07T06:01:51.162317Z","iopub.status.idle":"2024-02-07T06:01:51.215325Z","shell.execute_reply.started":"2024-02-07T06:01:51.162286Z","shell.execute_reply":"2024-02-07T06:01:51.214397Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"display(df_train.head().T)","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2024-02-07T06:01:54.191852Z","iopub.execute_input":"2024-02-07T06:01:54.192665Z","iopub.status.idle":"2024-02-07T06:01:54.310290Z","shell.execute_reply.started":"2024-02-07T06:01:54.192632Z","shell.execute_reply":"2024-02-07T06:01:54.309360Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"t = df_train.groupby('date_decision')['target'].value_counts(normalize=True).mul(100)\nt.unstack().plot.bar(stacked=True, figsize=(14, 2), legend=True)","metadata":{"execution":{"iopub.status.busy":"2024-02-07T06:02:03.796984Z","iopub.execute_input":"2024-02-07T06:02:03.797365Z","iopub.status.idle":"2024-02-07T06:02:11.882600Z","shell.execute_reply.started":"2024-02-07T06:02:03.797334Z","shell.execute_reply":"2024-02-07T06:02:11.881697Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.groupby('date_decision')['target'].mean().plot(\n    figsize=(14, 2), grid=True,\n    xlabel=\"date of decision\",\n    ylabel=\"day mean / proxi ratio\",\n)","metadata":{"execution":{"iopub.status.busy":"2024-02-07T06:02:16.616968Z","iopub.execute_input":"2024-02-07T06:02:16.617850Z","iopub.status.idle":"2024-02-07T06:02:17.493632Z","shell.execute_reply.started":"2024-02-07T06:02:16.617815Z","shell.execute_reply":"2024-02-07T06:02:17.492766Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"display(df_train.dtypes)","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2024-02-07T06:02:21.463463Z","iopub.execute_input":"2024-02-07T06:02:21.463819Z","iopub.status.idle":"2024-02-07T06:02:21.478252Z","shell.execute_reply.started":"2024-02-07T06:02:21.463793Z","shell.execute_reply":"2024-02-07T06:02:21.477314Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# convert_dtypes(df_train)\n# display(df_train.head().T)","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2024-02-07T06:02:28.491695Z","iopub.execute_input":"2024-02-07T06:02:28.492348Z","iopub.status.idle":"2024-02-07T06:02:28.496115Z","shell.execute_reply.started":"2024-02-07T06:02:28.492316Z","shell.execute_reply":"2024-02-07T06:02:28.495092Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Train simple XGBoost","metadata":{}},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\n\ndf_train.replace([np.inf, -np.inf], np.nan, inplace=True)\ntrain_cols = [c for c in df_train.columns if c not in (\"case_id\", \"date_decision\", \"target\")]\nX_train, X_valid, y_train, y_valid = train_test_split(\n    df_train[train_cols], df_train['target'], test_size=0.2)","metadata":{"execution":{"iopub.status.busy":"2024-02-07T06:02:33.158110Z","iopub.execute_input":"2024-02-07T06:02:33.158813Z","iopub.status.idle":"2024-02-07T06:02:42.633493Z","shell.execute_reply.started":"2024-02-07T06:02:33.158782Z","shell.execute_reply":"2024-02-07T06:02:42.632659Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install -U xgboost -f /kaggle/input/xgboost-python-package/ --no-index","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2024-02-07T06:02:47.541694Z","iopub.execute_input":"2024-02-07T06:02:47.542801Z","iopub.status.idle":"2024-02-07T06:03:00.332210Z","shell.execute_reply.started":"2024-02-07T06:02:47.542765Z","shell.execute_reply":"2024-02-07T06:03:00.331229Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import xgboost as xgb\n\nprint(xgb.__version__)","metadata":{"execution":{"iopub.status.busy":"2024-02-07T06:03:07.577767Z","iopub.execute_input":"2024-02-07T06:03:07.578126Z","iopub.status.idle":"2024-02-07T06:03:07.583438Z","shell.execute_reply.started":"2024-02-07T06:03:07.578098Z","shell.execute_reply":"2024-02-07T06:03:07.582506Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = xgb.XGBClassifier(\n    device=\"cuda\",\n    objective='binary:logistic',\n    tree_method=\"hist\",\n    enable_categorical=True,\n    eval_metric='auc',\n    #learning_rate=0.05,\n    subsample=1,\n    colsample_bytree=1,\n    min_child_weight=1,\n    #gamma=0.7,\n    #reg_alpha=0.7,\n    max_depth=20,\n    n_estimators=800,\n    random_state=42,\n)\n\n# Training the model on the training data\nmodel.fit(\n    X_train, y_train,\n    eval_set=[(X_valid, y_valid)],\n    # early_stopping_rounds=100,\n    verbose=True,\n)\n\nprint(model)","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2024-02-07T06:03:11.342190Z","iopub.execute_input":"2024-02-07T06:03:11.342554Z","iopub.status.idle":"2024-02-07T06:14:21.847797Z","shell.execute_reply.started":"2024-02-07T06:03:11.342526Z","shell.execute_reply":"2024-02-07T06:14:21.846794Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"del df_train","metadata":{"execution":{"iopub.status.busy":"2024-02-07T06:14:39.417385Z","iopub.execute_input":"2024-02-07T06:14:39.418369Z","iopub.status.idle":"2024-02-07T06:14:39.490753Z","shell.execute_reply.started":"2024-02-07T06:14:39.418331Z","shell.execute_reply":"2024-02-07T06:14:39.489754Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Loading test data","metadata":{}},{"cell_type":"code","source":"## base data","metadata":{"execution":{"iopub.status.busy":"2024-02-07T06:15:20.789292Z","iopub.execute_input":"2024-02-07T06:15:20.789994Z","iopub.status.idle":"2024-02-07T06:15:20.793813Z","shell.execute_reply.started":"2024-02-07T06:15:20.789960Z","shell.execute_reply":"2024-02-07T06:15:20.792924Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test = pd.read_parquet(PATH_TEST / \"test_base.parquet\")\nprint(f\"size: {len(df_test)}\")\ndisplay(df_test.head())","metadata":{"execution":{"iopub.status.busy":"2024-02-07T06:15:20.800479Z","iopub.execute_input":"2024-02-07T06:15:20.801232Z","iopub.status.idle":"2024-02-07T06:15:20.815460Z","shell.execute_reply.started":"2024-02-07T06:15:20.801206Z","shell.execute_reply":"2024-02-07T06:15:20.814617Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test[\"date_decision\"] = pd.to_datetime(df_test[\"date_decision\"]).dt.date\n# delete redundat cols\ndel df_test[\"MONTH\"], df_test[\"WEEK_NUM\"]","metadata":{"execution":{"iopub.status.busy":"2024-02-07T06:15:30.528532Z","iopub.execute_input":"2024-02-07T06:15:30.528933Z","iopub.status.idle":"2024-02-07T06:15:30.536519Z","shell.execute_reply.started":"2024-02-07T06:15:30.528899Z","shell.execute_reply":"2024-02-07T06:15:30.535574Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Depth 0","metadata":{}},{"cell_type":"code","source":"df_test = merge_tables(df_test, \"static_0\", PATH_TEST, \"test\")","metadata":{"execution":{"iopub.status.busy":"2024-02-07T06:15:49.593131Z","iopub.execute_input":"2024-02-07T06:15:49.593522Z","iopub.status.idle":"2024-02-07T06:15:49.870711Z","shell.execute_reply.started":"2024-02-07T06:15:49.593490Z","shell.execute_reply":"2024-02-07T06:15:49.869816Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test = merge_table(df_test, \"static_cb_0\", PATH_TEST, \"test\")","metadata":{"execution":{"iopub.status.busy":"2024-02-07T06:15:54.347056Z","iopub.execute_input":"2024-02-07T06:15:54.347705Z","iopub.status.idle":"2024-02-07T06:15:54.441007Z","shell.execute_reply.started":"2024-02-07T06:15:54.347672Z","shell.execute_reply":"2024-02-07T06:15:54.440030Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Depth 1","metadata":{}},{"cell_type":"code","source":"# df_test = merge_tables(df_test, \"applprev_1\", PATH_TEST, \"test\")","metadata":{"execution":{"iopub.status.busy":"2024-02-07T06:16:00.572681Z","iopub.execute_input":"2024-02-07T06:16:00.573148Z","iopub.status.idle":"2024-02-07T06:16:00.577356Z","shell.execute_reply.started":"2024-02-07T06:16:00.573114Z","shell.execute_reply":"2024-02-07T06:16:00.576401Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test = merge_table(df_test, \"other_1\", PATH_TEST, \"test\")","metadata":{"execution":{"iopub.status.busy":"2024-02-07T06:16:08.630774Z","iopub.execute_input":"2024-02-07T06:16:08.631638Z","iopub.status.idle":"2024-02-07T06:16:08.661404Z","shell.execute_reply.started":"2024-02-07T06:16:08.631598Z","shell.execute_reply":"2024-02-07T06:16:08.660634Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test = merge_table(df_test, \"deposit_1\", PATH_TEST, \"test\")","metadata":{"execution":{"iopub.status.busy":"2024-02-07T06:16:14.355138Z","iopub.execute_input":"2024-02-07T06:16:14.355504Z","iopub.status.idle":"2024-02-07T06:16:14.386295Z","shell.execute_reply.started":"2024-02-07T06:16:14.355475Z","shell.execute_reply":"2024-02-07T06:16:14.385469Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test = merge_table(df_test, \"person_1\", PATH_TEST, \"test\")","metadata":{"execution":{"iopub.status.busy":"2024-02-07T06:16:17.568844Z","iopub.execute_input":"2024-02-07T06:16:17.569497Z","iopub.status.idle":"2024-02-07T06:16:17.640998Z","shell.execute_reply.started":"2024-02-07T06:16:17.569464Z","shell.execute_reply":"2024-02-07T06:16:17.640107Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Overview","metadata":{}},{"cell_type":"code","source":"display(df_test.head().T)","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2024-02-07T06:16:21.825762Z","iopub.execute_input":"2024-02-07T06:16:21.826272Z","iopub.status.idle":"2024-02-07T06:16:21.904253Z","shell.execute_reply.started":"2024-02-07T06:16:21.826240Z","shell.execute_reply":"2024-02-07T06:16:21.903172Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"display(df_test.dtypes)","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2024-02-07T06:16:33.138030Z","iopub.execute_input":"2024-02-07T06:16:33.138413Z","iopub.status.idle":"2024-02-07T06:16:33.153217Z","shell.execute_reply.started":"2024-02-07T06:16:33.138383Z","shell.execute_reply":"2024-02-07T06:16:33.152192Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# convert_dtypes(df_test)\n# display(df_test.head().T)","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2024-02-07T06:16:43.936929Z","iopub.execute_input":"2024-02-07T06:16:43.937607Z","iopub.status.idle":"2024-02-07T06:16:43.941531Z","shell.execute_reply.started":"2024-02-07T06:16:43.937575Z","shell.execute_reply":"2024-02-07T06:16:43.940628Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Predict and submit","metadata":{}},{"cell_type":"code","source":"!head /kaggle/input/home-credit-credit-risk-model-stability/sample_submission.csv","metadata":{"execution":{"iopub.status.busy":"2024-02-07T06:16:48.722537Z","iopub.execute_input":"2024-02-07T06:16:48.723562Z","iopub.status.idle":"2024-02-07T06:16:49.722106Z","shell.execute_reply.started":"2024-02-07T06:16:48.723525Z","shell.execute_reply":"2024-02-07T06:16:49.720753Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test.replace([np.inf, -np.inf], np.nan, inplace=True)\npreds_proba = model.predict_proba(df_test[train_cols])\ndf_test[\"score\"] = np.clip(preds_proba[:, 1], 0, 1).round(4).astype(\"float32\")\ndisplay(df_test.head())","metadata":{"execution":{"iopub.status.busy":"2024-02-07T06:16:54.057368Z","iopub.execute_input":"2024-02-07T06:16:54.057812Z","iopub.status.idle":"2024-02-07T06:16:54.633437Z","shell.execute_reply.started":"2024-02-07T06:16:54.057760Z","shell.execute_reply":"2024-02-07T06:16:54.632419Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test[[\"case_id\", \"score\"]].to_csv(\"submission.csv\", index=False)\n\n!head submission.csv","metadata":{"execution":{"iopub.status.busy":"2024-02-07T06:17:04.438402Z","iopub.execute_input":"2024-02-07T06:17:04.439176Z","iopub.status.idle":"2024-02-07T06:17:05.462329Z","shell.execute_reply.started":"2024-02-07T06:17:04.439137Z","shell.execute_reply":"2024-02-07T06:17:05.460925Z"},"trusted":true},"execution_count":null,"outputs":[]}]}