{"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":"# !kaggle competitions download -c facebook-recruiting-iv-human-or-bot","metadata":{"execution":{"iopub.status.busy":"2022-08-03T18:09:42.931799Z","iopub.execute_input":"2022-08-03T18:09:42.932310Z","iopub.status.idle":"2022-08-03T18:09:42.957405Z","shell.execute_reply.started":"2022-08-03T18:09:42.932212Z","shell.execute_reply":"2022-08-03T18:09:42.956083Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from zipfile import ZipFile","metadata":{"execution":{"iopub.status.busy":"2022-08-03T18:09:42.959191Z","iopub.execute_input":"2022-08-03T18:09:42.959550Z","iopub.status.idle":"2022-08-03T18:09:42.969971Z","shell.execute_reply.started":"2022-08-03T18:09:42.959517Z","shell.execute_reply":"2022-08-03T18:09:42.968936Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# with ZipFile('facebook-recruiting-iv-human-or-bot.zip', 'r') as zipObj:\n#     zipObj.extractall()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T18:09:42.971828Z","iopub.execute_input":"2022-08-03T18:09:42.972173Z","iopub.status.idle":"2022-08-03T18:09:42.981897Z","shell.execute_reply.started":"2022-08-03T18:09:42.972143Z","shell.execute_reply":"2022-08-03T18:09:42.981011Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"with ZipFile('../input/facebook-recruiting-iv-human-or-bot/bids.csv.zip', 'r') as zipObj:\n    zipObj.extractall()\n    \nwith ZipFile('../input/facebook-recruiting-iv-human-or-bot/test.csv.zip', 'r') as zipObj:\n    zipObj.extractall()\n    \nwith ZipFile('../input/facebook-recruiting-iv-human-or-bot/train.csv.zip', 'r') as zipObj:\n    zipObj.extractall()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T18:09:42.983498Z","iopub.execute_input":"2022-08-03T18:09:42.984184Z","iopub.status.idle":"2022-08-03T18:09:52.977630Z","shell.execute_reply.started":"2022-08-03T18:09:42.984135Z","shell.execute_reply":"2022-08-03T18:09:52.976730Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport warnings","metadata":{"execution":{"iopub.status.busy":"2022-08-03T18:09:52.982345Z","iopub.execute_input":"2022-08-03T18:09:52.983601Z","iopub.status.idle":"2022-08-03T18:09:53.779131Z","shell.execute_reply.started":"2022-08-03T18:09:52.983566Z","shell.execute_reply":"2022-08-03T18:09:53.778233Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"warnings.filterwarnings('ignore')\nsns.set_theme()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T18:09:53.780742Z","iopub.execute_input":"2022-08-03T18:09:53.781574Z","iopub.status.idle":"2022-08-03T18:09:53.789536Z","shell.execute_reply.started":"2022-08-03T18:09:53.781527Z","shell.execute_reply":"2022-08-03T18:09:53.787929Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# EDA","metadata":{}},{"cell_type":"code","source":"train_df = pd.read_csv('./train.csv')\ntrain_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T18:11:34.853001Z","iopub.execute_input":"2022-08-03T18:11:34.853933Z","iopub.status.idle":"2022-08-03T18:11:34.876635Z","shell.execute_reply.started":"2022-08-03T18:11:34.853887Z","shell.execute_reply":"2022-08-03T18:11:34.875465Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T18:11:34.881448Z","iopub.execute_input":"2022-08-03T18:11:34.881874Z","iopub.status.idle":"2022-08-03T18:11:34.916500Z","shell.execute_reply.started":"2022-08-03T18:11:34.881811Z","shell.execute_reply":"2022-08-03T18:11:34.915129Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.describe(include=np.number)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T18:11:34.918759Z","iopub.execute_input":"2022-08-03T18:11:34.919922Z","iopub.status.idle":"2022-08-03T18:11:34.944356Z","shell.execute_reply.started":"2022-08-03T18:11:34.919872Z","shell.execute_reply":"2022-08-03T18:11:34.942937Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.describe(include=object)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T18:11:34.946395Z","iopub.execute_input":"2022-08-03T18:11:34.946920Z","iopub.status.idle":"2022-08-03T18:11:34.972176Z","shell.execute_reply.started":"2022-08-03T18:11:34.946870Z","shell.execute_reply":"2022-08-03T18:11:34.970935Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.isna().sum().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T18:11:34.974997Z","iopub.execute_input":"2022-08-03T18:11:34.975861Z","iopub.status.idle":"2022-08-03T18:11:34.986749Z","shell.execute_reply.started":"2022-08-03T18:11:34.975808Z","shell.execute_reply":"2022-08-03T18:11:34.985161Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.shape","metadata":{"execution":{"iopub.status.busy":"2022-08-03T18:11:34.988363Z","iopub.execute_input":"2022-08-03T18:11:34.988740Z","iopub.status.idle":"2022-08-03T18:11:35.000614Z","shell.execute_reply.started":"2022-08-03T18:11:34.988708Z","shell.execute_reply":"2022-08-03T18:11:34.999439Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.countplot(data=train_df, x='outcome')","metadata":{"execution":{"iopub.status.busy":"2022-08-03T18:11:35.002450Z","iopub.execute_input":"2022-08-03T18:11:35.003270Z","iopub.status.idle":"2022-08-03T18:11:35.216933Z","shell.execute_reply.started":"2022-08-03T18:11:35.003222Z","shell.execute_reply":"2022-08-03T18:11:35.215682Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bid_df = pd.read_csv('./bids.csv')\nbid_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T18:11:35.218363Z","iopub.execute_input":"2022-08-03T18:11:35.218709Z","iopub.status.idle":"2022-08-03T18:11:51.632319Z","shell.execute_reply.started":"2022-08-03T18:11:35.218677Z","shell.execute_reply":"2022-08-03T18:11:51.631142Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_sameness(series):\n    \"\"\"\n    Computes sameness. \n    \"\"\"\n    if len(series) == 0:\n        return 0.3\n    vc = series.value_counts()\n    p_vc = vc / len(series)\n    res = np.dot(vc.values, p_vc.values)\n    return res / len(series)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T18:11:51.633808Z","iopub.execute_input":"2022-08-03T18:11:51.634181Z","iopub.status.idle":"2022-08-03T18:11:51.641062Z","shell.execute_reply.started":"2022-08-03T18:11:51.634150Z","shell.execute_reply":"2022-08-03T18:11:51.639791Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"get_sameness(bid_df[bid_df[\"bidder_id\"] == \"1c5f4fc669099bfbfac515cd26997bd12ruaj\"][\"merchandise\"])","metadata":{"execution":{"iopub.status.busy":"2022-08-03T18:11:51.642492Z","iopub.execute_input":"2022-08-03T18:11:51.642916Z","iopub.status.idle":"2022-08-03T18:11:52.180966Z","shell.execute_reply.started":"2022-08-03T18:11:51.642875Z","shell.execute_reply":"2022-08-03T18:11:52.179883Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def preprocess_data(df, bid_df):\n    # unique = {}\n    # col_to_iter = [\"bidder_id\", \"auction\", \"device\", \"ip\", \"url\"]\n    # for col in col_to_iter:\n    #     unique[col] = df[col].rename(f\"{col}_unique\")\n    #     unique[col] = unique[col].map(unique[col].value_counts() == 1)\n    bidder_id_count = df[\"bidder_id\"].rename(\"bidder_id_count\")\n    bidder_id_count = bidder_id_count.map(bid_df[\"bidder_id\"].value_counts())\n    sameness = {}\n    col_to_iter = [\"auction\", \"merchandise\", \"device\", \"country\", \"ip\", \"url\"]\n#     param = {}\n#     for col in col_to_iter_2:\n#         param[col] = np.zeros(len(df), dtype=object)\n#         i = 0\n#         for bidder_id in df[\"bidder_id\"]:\n#             print(col, i)\n#             series = bid_df[bid_df[\"bidder_id\"] == bidder_id][col]\n#             param[col][i] = series\n#             # print(series)\n#             i += 1\n#         print(param[col])\n            \n#     print(param)\n#     print(sameness)\n            \n#     for col in col_to_iter_2:\n#         sameness[col] = get_sameness(param[col])\n#         print(col)\n        \n    for col in col_to_iter:\n        sameness[col] = np.zeros(len(df), dtype=object)\n        i = 0\n        for bidder_id in df[\"bidder_id\"]:\n            print(col, i)\n            sameness[col][i] = get_sameness(bid_df[bid_df[\"bidder_id\"] == bidder_id][col])\n            i += 1\n        print(sameness[col])\n        \n    sameness = pd.DataFrame(sameness)\n    bidder_id_count = pd.DataFrame(bidder_id_count)\n    sameness = pd.concat([sameness, bidder_id_count], axis=1)\n    df = pd.concat([df, sameness], axis=1)\n    df.drop(columns=['bidder_id', 'payment_account', 'address'], axis=1, inplace=True)\n    return df","metadata":{"execution":{"iopub.status.busy":"2022-08-03T18:11:52.184713Z","iopub.execute_input":"2022-08-03T18:11:52.185092Z","iopub.status.idle":"2022-08-03T18:11:52.196113Z","shell.execute_reply.started":"2022-08-03T18:11:52.185059Z","shell.execute_reply":"2022-08-03T18:11:52.194755Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"if os.path.exists('../input/facebook-preprocessed-data/preprocessed_train.csv'):\n    train_df = pd.read_csv('../input/facebook-preprocessed-data/preprocessed_train.csv')\nelse:\n    train_df = preprocess_data(train_df, bid_df)\n    train_df.to_csv('../input/facebook-preprocessed-data/preprocessed_train.csv', sep=',', index=False)","metadata":{"scrolled":true,"tags":[],"execution":{"iopub.status.busy":"2022-08-03T18:11:52.197886Z","iopub.execute_input":"2022-08-03T18:11:52.198406Z","iopub.status.idle":"2022-08-03T18:11:52.227885Z","shell.execute_reply.started":"2022-08-03T18:11:52.198359Z","shell.execute_reply":"2022-08-03T18:11:52.226909Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T18:11:52.229313Z","iopub.execute_input":"2022-08-03T18:11:52.229639Z","iopub.status.idle":"2022-08-03T18:11:52.246792Z","shell.execute_reply.started":"2022-08-03T18:11:52.229609Z","shell.execute_reply":"2022-08-03T18:11:52.245433Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T18:11:52.248664Z","iopub.execute_input":"2022-08-03T18:11:52.249103Z","iopub.status.idle":"2022-08-03T18:11:52.263224Z","shell.execute_reply.started":"2022-08-03T18:11:52.249066Z","shell.execute_reply":"2022-08-03T18:11:52.262030Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['bidder_id_count'].fillna(train_df['bidder_id_count'].mean(), inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T18:11:52.265079Z","iopub.execute_input":"2022-08-03T18:11:52.265543Z","iopub.status.idle":"2022-08-03T18:11:52.280772Z","shell.execute_reply.started":"2022-08-03T18:11:52.265495Z","shell.execute_reply":"2022-08-03T18:11:52.279810Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bid_df.drop(columns=['bid_id', 'time'], inplace=True, axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T18:11:52.281926Z","iopub.execute_input":"2022-08-03T18:11:52.282830Z","iopub.status.idle":"2022-08-03T18:11:52.946633Z","shell.execute_reply.started":"2022-08-03T18:11:52.282789Z","shell.execute_reply":"2022-08-03T18:11:52.945355Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bid_df.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T18:11:52.948319Z","iopub.execute_input":"2022-08-03T18:11:52.949112Z","iopub.status.idle":"2022-08-03T18:11:52.964481Z","shell.execute_reply.started":"2022-08-03T18:11:52.949064Z","shell.execute_reply":"2022-08-03T18:11:52.963256Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bid_df.describe()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T18:11:52.966034Z","iopub.execute_input":"2022-08-03T18:11:52.966413Z","iopub.status.idle":"2022-08-03T18:12:05.563024Z","shell.execute_reply.started":"2022-08-03T18:11:52.966380Z","shell.execute_reply":"2022-08-03T18:12:05.561863Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bid_df.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T18:12:05.564816Z","iopub.execute_input":"2022-08-03T18:12:05.565573Z","iopub.status.idle":"2022-08-03T18:12:07.839820Z","shell.execute_reply.started":"2022-08-03T18:12:05.565528Z","shell.execute_reply":"2022-08-03T18:12:07.838590Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bid_df.shape","metadata":{"execution":{"iopub.status.busy":"2022-08-03T18:12:07.841223Z","iopub.execute_input":"2022-08-03T18:12:07.841637Z","iopub.status.idle":"2022-08-03T18:12:07.850147Z","shell.execute_reply.started":"2022-08-03T18:12:07.841606Z","shell.execute_reply":"2022-08-03T18:12:07.848986Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df = pd.read_csv('./test.csv')\ntest_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T18:12:07.851692Z","iopub.execute_input":"2022-08-03T18:12:07.852195Z","iopub.status.idle":"2022-08-03T18:12:07.883090Z","shell.execute_reply.started":"2022-08-03T18:12:07.852161Z","shell.execute_reply":"2022-08-03T18:12:07.881900Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bidder_id = test_df['bidder_id']","metadata":{"execution":{"iopub.status.busy":"2022-08-03T18:12:07.886111Z","iopub.execute_input":"2022-08-03T18:12:07.886550Z","iopub.status.idle":"2022-08-03T18:12:07.892273Z","shell.execute_reply.started":"2022-08-03T18:12:07.886514Z","shell.execute_reply":"2022-08-03T18:12:07.891116Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T18:12:07.893788Z","iopub.execute_input":"2022-08-03T18:12:07.894158Z","iopub.status.idle":"2022-08-03T18:12:07.913398Z","shell.execute_reply.started":"2022-08-03T18:12:07.894128Z","shell.execute_reply":"2022-08-03T18:12:07.912375Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.describe()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T18:12:07.915173Z","iopub.execute_input":"2022-08-03T18:12:07.915947Z","iopub.status.idle":"2022-08-03T18:12:07.940773Z","shell.execute_reply.started":"2022-08-03T18:12:07.915909Z","shell.execute_reply":"2022-08-03T18:12:07.939929Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T18:12:07.942029Z","iopub.execute_input":"2022-08-03T18:12:07.942547Z","iopub.status.idle":"2022-08-03T18:12:07.950975Z","shell.execute_reply.started":"2022-08-03T18:12:07.942515Z","shell.execute_reply":"2022-08-03T18:12:07.949964Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.shape","metadata":{"execution":{"iopub.status.busy":"2022-08-03T18:12:07.952169Z","iopub.execute_input":"2022-08-03T18:12:07.953257Z","iopub.status.idle":"2022-08-03T18:12:07.967366Z","shell.execute_reply.started":"2022-08-03T18:12:07.953176Z","shell.execute_reply":"2022-08-03T18:12:07.966349Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"if os.path.exists('../input/facebook-preprocessed-data/preprocessed_test.csv'):\n    test_df = pd.read_csv('../input/facebook-preprocessed-data/preprocessed_test.csv')\nelse:\n    test_df = preprocess_data(test_df, bid_df)\n    test_df.to_csv('../input/facebook-preprocessed-data/preprocessed_test.csv', sep=',', index=False)","metadata":{"scrolled":true,"tags":[],"execution":{"iopub.status.busy":"2022-08-03T18:12:07.969152Z","iopub.execute_input":"2022-08-03T18:12:07.969652Z","iopub.status.idle":"2022-08-03T18:12:07.996210Z","shell.execute_reply.started":"2022-08-03T18:12:07.969606Z","shell.execute_reply":"2022-08-03T18:12:07.994715Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T18:12:08.004355Z","iopub.execute_input":"2022-08-03T18:12:08.004784Z","iopub.status.idle":"2022-08-03T18:12:08.015636Z","shell.execute_reply.started":"2022-08-03T18:12:08.004745Z","shell.execute_reply":"2022-08-03T18:12:08.014405Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df[\"bidder_id_count\"].fillna(test_df[\"bidder_id_count\"].mean(), inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T18:12:08.017875Z","iopub.execute_input":"2022-08-03T18:12:08.018447Z","iopub.status.idle":"2022-08-03T18:12:08.030358Z","shell.execute_reply.started":"2022-08-03T18:12:08.018404Z","shell.execute_reply":"2022-08-03T18:12:08.029064Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# test_bidder_in_train = 0\n# def inc_bidder(x):\n#     global test_bidder_in_train\n#     if x in train_df['bidder_id']:\n#         test_bidder_in_train += 1\n# test_df['bidder_id'].apply(inc_bidder)\n# test_bidder_in_train","metadata":{"execution":{"iopub.status.busy":"2022-08-03T18:12:08.033040Z","iopub.execute_input":"2022-08-03T18:12:08.033673Z","iopub.status.idle":"2022-08-03T18:12:08.043429Z","shell.execute_reply.started":"2022-08-03T18:12:08.033614Z","shell.execute_reply":"2022-08-03T18:12:08.042188Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# test_acc_in_train = 0\n# def inc_accr(x):\n#     global test_acc_in_train\n#     if x in train_df['payment_account']:\n#         test_acc_in_train += 1\n# test_df['payment_account'].apply(inc_accr)\n# test_acc_in_train","metadata":{"execution":{"iopub.status.busy":"2022-08-03T18:12:08.044901Z","iopub.execute_input":"2022-08-03T18:12:08.046326Z","iopub.status.idle":"2022-08-03T18:12:08.055620Z","shell.execute_reply.started":"2022-08-03T18:12:08.046164Z","shell.execute_reply":"2022-08-03T18:12:08.054637Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# test_address_in_train = 0\n# def inc_address(x):\n#     global test_address_in_train\n#     if x in train_df['address']:\n#         test_address_in_train += 1\n# test_df['address'].apply(inc_address)\n# test_address_in_train","metadata":{"execution":{"iopub.status.busy":"2022-08-03T18:12:08.057072Z","iopub.execute_input":"2022-08-03T18:12:08.057472Z","iopub.status.idle":"2022-08-03T18:12:08.067601Z","shell.execute_reply.started":"2022-08-03T18:12:08.057436Z","shell.execute_reply":"2022-08-03T18:12:08.066407Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# EDA results:\n- test_df and train_df don't have common values\n- outcome is very imbalanced","metadata":{}},{"cell_type":"markdown","source":"# Model defining","metadata":{}},{"cell_type":"code","source":"X = train_df.drop(columns=['outcome'], axis=1)\nY = train_df['outcome']\nX.shape, Y.shape","metadata":{"execution":{"iopub.status.busy":"2022-08-03T18:12:08.069204Z","iopub.execute_input":"2022-08-03T18:12:08.069572Z","iopub.status.idle":"2022-08-03T18:12:08.087333Z","shell.execute_reply.started":"2022-08-03T18:12:08.069539Z","shell.execute_reply":"2022-08-03T18:12:08.084966Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_test = test_df\nX_test.shape","metadata":{"execution":{"iopub.status.busy":"2022-08-03T18:12:08.090440Z","iopub.execute_input":"2022-08-03T18:12:08.091030Z","iopub.status.idle":"2022-08-03T18:12:08.099345Z","shell.execute_reply.started":"2022-08-03T18:12:08.090981Z","shell.execute_reply":"2022-08-03T18:12:08.098142Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.ensemble import GradientBoostingClassifier\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn.metrics import confusion_matrix, roc_auc_score, classification_report\nfrom sklearn.model_selection import cross_val_score","metadata":{"execution":{"iopub.status.busy":"2022-08-03T18:12:08.101314Z","iopub.execute_input":"2022-08-03T18:12:08.101802Z","iopub.status.idle":"2022-08-03T18:12:08.470536Z","shell.execute_reply.started":"2022-08-03T18:12:08.101755Z","shell.execute_reply":"2022-08-03T18:12:08.469356Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_gbc = GradientBoostingClassifier(max_depth=10, n_estimators=500, random_state=42)\nmodel_gbc.fit(X, Y)\npred_proba_gbc = model_gbc.predict_proba(X)[:,1]\nprint(classification_report(Y, model_gbc.predict(X)))","metadata":{"scrolled":true,"tags":[],"execution":{"iopub.status.busy":"2022-08-03T18:12:08.472120Z","iopub.execute_input":"2022-08-03T18:12:08.472554Z","iopub.status.idle":"2022-08-03T18:12:12.801571Z","shell.execute_reply.started":"2022-08-03T18:12:08.472521Z","shell.execute_reply":"2022-08-03T18:12:12.800360Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Y_pred = model_gbc.predict_proba(X_test)[:,1]","metadata":{"execution":{"iopub.status.busy":"2022-08-03T18:12:12.803888Z","iopub.execute_input":"2022-08-03T18:12:12.805165Z","iopub.status.idle":"2022-08-03T18:12:12.892613Z","shell.execute_reply.started":"2022-08-03T18:12:12.805102Z","shell.execute_reply":"2022-08-03T18:12:12.891612Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"solution = pd.DataFrame({\"bidder_id\": bidder_id, \"prediction\": Y_pred})\nsolution.to_csv(\"submission.csv\", sep=\",\", index=False)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T18:12:12.894195Z","iopub.execute_input":"2022-08-03T18:12:12.894858Z","iopub.status.idle":"2022-08-03T18:12:12.925069Z","shell.execute_reply.started":"2022-08-03T18:12:12.894803Z","shell.execute_reply":"2022-08-03T18:12:12.923833Z"},"trusted":true},"execution_count":null,"outputs":[]}]}