{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.7.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":4294,"databundleVersionId":33829,"sourceType":"competition"},{"sourceId":4025486,"sourceType":"datasetVersion","datasetId":2385389}],"dockerImageVersionId":30213,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"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":"2024-01-03T10:18:29.126873Z","iopub.execute_input":"2024-01-03T10:18:29.127487Z","iopub.status.idle":"2024-01-03T10:18:29.133462Z","shell.execute_reply.started":"2024-01-03T10:18:29.127446Z","shell.execute_reply":"2024-01-03T10:18:29.132092Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from zipfile import ZipFile","metadata":{"execution":{"iopub.status.busy":"2024-01-03T10:18:29.136071Z","iopub.execute_input":"2024-01-03T10:18:29.136552Z","iopub.status.idle":"2024-01-03T10:18:29.149237Z","shell.execute_reply.started":"2024-01-03T10:18:29.136505Z","shell.execute_reply":"2024-01-03T10:18:29.147958Z"},"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":"2024-01-03T10:18:29.151370Z","iopub.execute_input":"2024-01-03T10:18:29.151981Z","iopub.status.idle":"2024-01-03T10:18:29.165776Z","shell.execute_reply.started":"2024-01-03T10:18:29.151944Z","shell.execute_reply":"2024-01-03T10:18:29.164702Z"},"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":"2024-01-03T10:18:29.167279Z","iopub.execute_input":"2024-01-03T10:18:29.167771Z","iopub.status.idle":"2024-01-03T10:18:36.710359Z","shell.execute_reply.started":"2024-01-03T10:18:29.167674Z","shell.execute_reply":"2024-01-03T10:18:36.709106Z"},"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":"2024-01-03T10:18:36.714086Z","iopub.execute_input":"2024-01-03T10:18:36.714762Z","iopub.status.idle":"2024-01-03T10:18:36.720134Z","shell.execute_reply.started":"2024-01-03T10:18:36.714724Z","shell.execute_reply":"2024-01-03T10:18:36.719085Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"warnings.filterwarnings('ignore')\nsns.set_theme()","metadata":{"execution":{"iopub.status.busy":"2024-01-03T10:18:36.722321Z","iopub.execute_input":"2024-01-03T10:18:36.722869Z","iopub.status.idle":"2024-01-03T10:18:36.734862Z","shell.execute_reply.started":"2024-01-03T10:18:36.722798Z","shell.execute_reply":"2024-01-03T10:18:36.733557Z"},"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":"2024-01-03T10:18:36.737341Z","iopub.execute_input":"2024-01-03T10:18:36.737928Z","iopub.status.idle":"2024-01-03T10:18:36.765194Z","shell.execute_reply.started":"2024-01-03T10:18:36.737878Z","shell.execute_reply":"2024-01-03T10:18:36.763900Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.info()","metadata":{"execution":{"iopub.status.busy":"2024-01-03T10:18:36.768260Z","iopub.execute_input":"2024-01-03T10:18:36.768621Z","iopub.status.idle":"2024-01-03T10:18:36.784436Z","shell.execute_reply.started":"2024-01-03T10:18:36.768590Z","shell.execute_reply":"2024-01-03T10:18:36.783085Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.describe(include=np.number)","metadata":{"execution":{"iopub.status.busy":"2024-01-03T10:18:36.786405Z","iopub.execute_input":"2024-01-03T10:18:36.786795Z","iopub.status.idle":"2024-01-03T10:18:36.810601Z","shell.execute_reply.started":"2024-01-03T10:18:36.786757Z","shell.execute_reply":"2024-01-03T10:18:36.809297Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.describe(include=object)","metadata":{"execution":{"iopub.status.busy":"2024-01-03T10:18:36.812472Z","iopub.execute_input":"2024-01-03T10:18:36.813072Z","iopub.status.idle":"2024-01-03T10:18:36.839804Z","shell.execute_reply.started":"2024-01-03T10:18:36.813036Z","shell.execute_reply":"2024-01-03T10:18:36.838839Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.isna().sum().sum()","metadata":{"execution":{"iopub.status.busy":"2024-01-03T10:18:36.844365Z","iopub.execute_input":"2024-01-03T10:18:36.845035Z","iopub.status.idle":"2024-01-03T10:18:36.854282Z","shell.execute_reply.started":"2024-01-03T10:18:36.844984Z","shell.execute_reply":"2024-01-03T10:18:36.853000Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.shape","metadata":{"execution":{"iopub.status.busy":"2024-01-03T10:18:36.855648Z","iopub.execute_input":"2024-01-03T10:18:36.856384Z","iopub.status.idle":"2024-01-03T10:18:36.867133Z","shell.execute_reply.started":"2024-01-03T10:18:36.856346Z","shell.execute_reply":"2024-01-03T10:18:36.865478Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\nimport matplotlib.pyplot as plt\n\n# Assuming train_df is your DataFrame\n# You can modify the appearance and customization based on your preferences\n\n# Set the style of the visualization\nsns.set(style=\"whitegrid\")\n\n# Create the countplot\nplt.figure(figsize=(8, 6))  # Adjust the figure size as needed\nsns.countplot(data=train_df, x='outcome', palette='Set2')  # You can choose a different color palette\n\n# Add labels and title\nplt.title('Outcome Distribution')\nplt.xlabel('Outcome')\nplt.ylabel('Count')\n\n# Rotate x-axis labels for better readability if needed\nplt.xticks(rotation=45)\n\n# Show the plot\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-03T10:18:36.868625Z","iopub.execute_input":"2024-01-03T10:18:36.869022Z","iopub.status.idle":"2024-01-03T10:18:37.045615Z","shell.execute_reply.started":"2024-01-03T10:18:36.868987Z","shell.execute_reply":"2024-01-03T10:18:37.044214Z"},"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":"2024-01-03T10:18:37.047336Z","iopub.execute_input":"2024-01-03T10:18:37.048642Z","iopub.status.idle":"2024-01-03T10:18:55.838247Z","shell.execute_reply.started":"2024-01-03T10:18:37.048590Z","shell.execute_reply":"2024-01-03T10:18:55.836906Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\n\ndef get_sameness(series):\n    \"\"\"\n    Computes sameness.\n    \"\"\"\n    if len(series) == 0:\n        return 0.3  # Default value for an empty series\n\n    value_counts = series.value_counts()\n    probability_counts = value_counts / len(series)\n\n    # Calculate the dot product of value counts and probability counts\n    dot_product = np.dot(value_counts.values, probability_counts.values)\n\n    # Normalize by the length of the series\n    sameness_score = dot_product / len(series)\n\n    return sameness_score\n","metadata":{"execution":{"iopub.status.busy":"2024-01-03T10:18:55.839656Z","iopub.execute_input":"2024-01-03T10:18:55.840076Z","iopub.status.idle":"2024-01-03T10:18:55.847246Z","shell.execute_reply.started":"2024-01-03T10:18:55.840040Z","shell.execute_reply":"2024-01-03T10:18:55.846218Z"},"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":"2024-01-03T10:18:55.848631Z","iopub.execute_input":"2024-01-03T10:18:55.849769Z","iopub.status.idle":"2024-01-03T10:18:57.253021Z","shell.execute_reply.started":"2024-01-03T10:18:55.849730Z","shell.execute_reply":"2024-01-03T10:18:57.251792Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\n\ndef preprocess_data(df, bid_df):\n    bidder_id_count = bid_df[\"bidder_id\"].value_counts().rename(\"bidder_id_count\")\n    bidder_id_count = df[\"bidder_id\"].map(bidder_id_count)\n\n    sameness_cols = [\"auction\", \"merchandise\", \"device\", \"country\", \"ip\", \"url\"]\n    sameness = pd.DataFrame()\n\n    for col in sameness_cols:\n        sameness[col] = df[\"bidder_id\"].apply(lambda bidder_id: get_sameness(bid_df[bid_df[\"bidder_id\"] == bidder_id][col]))\n\n    df = pd.concat([df, sameness, bidder_id_count], axis=1)\n    df.drop(columns=['bidder_id', 'payment_account', 'address'], axis=1, inplace=True)\n\n    return df\n","metadata":{"execution":{"iopub.status.busy":"2024-01-03T10:18:57.254623Z","iopub.execute_input":"2024-01-03T10:18:57.254989Z","iopub.status.idle":"2024-01-03T10:18:57.266875Z","shell.execute_reply.started":"2024-01-03T10:18:57.254956Z","shell.execute_reply":"2024-01-03T10:18:57.265462Z"},"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":"2024-01-03T10:18:57.269148Z","iopub.execute_input":"2024-01-03T10:18:57.269540Z","iopub.status.idle":"2024-01-03T10:18:57.287341Z","shell.execute_reply.started":"2024-01-03T10:18:57.269506Z","shell.execute_reply":"2024-01-03T10:18:57.285638Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-03T10:18:57.288612Z","iopub.execute_input":"2024-01-03T10:18:57.289132Z","iopub.status.idle":"2024-01-03T10:18:57.310190Z","shell.execute_reply.started":"2024-01-03T10:18:57.289082Z","shell.execute_reply":"2024-01-03T10:18:57.308833Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2024-01-03T10:18:57.312284Z","iopub.execute_input":"2024-01-03T10:18:57.312848Z","iopub.status.idle":"2024-01-03T10:18:57.329222Z","shell.execute_reply.started":"2024-01-03T10:18:57.312780Z","shell.execute_reply":"2024-01-03T10:18:57.328250Z"},"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":"2024-01-03T10:18:57.330676Z","iopub.execute_input":"2024-01-03T10:18:57.331050Z","iopub.status.idle":"2024-01-03T10:18:57.341823Z","shell.execute_reply.started":"2024-01-03T10:18:57.331006Z","shell.execute_reply":"2024-01-03T10:18:57.340460Z"},"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":"2024-01-03T10:18:57.343643Z","iopub.execute_input":"2024-01-03T10:18:57.344340Z","iopub.status.idle":"2024-01-03T10:18:58.002735Z","shell.execute_reply.started":"2024-01-03T10:18:57.344300Z","shell.execute_reply":"2024-01-03T10:18:58.001151Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bid_df.info()","metadata":{"execution":{"iopub.status.busy":"2024-01-03T10:18:58.005052Z","iopub.execute_input":"2024-01-03T10:18:58.005569Z","iopub.status.idle":"2024-01-03T10:18:58.018681Z","shell.execute_reply.started":"2024-01-03T10:18:58.005518Z","shell.execute_reply":"2024-01-03T10:18:58.017351Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bid_df.describe()","metadata":{"execution":{"iopub.status.busy":"2024-01-03T10:18:58.020351Z","iopub.execute_input":"2024-01-03T10:18:58.020836Z","iopub.status.idle":"2024-01-03T10:19:19.020149Z","shell.execute_reply.started":"2024-01-03T10:18:58.020769Z","shell.execute_reply":"2024-01-03T10:19:19.018887Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bid_df.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2024-01-03T10:19:19.021746Z","iopub.execute_input":"2024-01-03T10:19:19.022268Z","iopub.status.idle":"2024-01-03T10:19:25.173409Z","shell.execute_reply.started":"2024-01-03T10:19:19.022227Z","shell.execute_reply":"2024-01-03T10:19:25.172234Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bid_df.shape","metadata":{"execution":{"iopub.status.busy":"2024-01-03T10:19:25.174886Z","iopub.execute_input":"2024-01-03T10:19:25.175249Z","iopub.status.idle":"2024-01-03T10:19:25.184669Z","shell.execute_reply.started":"2024-01-03T10:19:25.175216Z","shell.execute_reply":"2024-01-03T10:19:25.183366Z"},"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":"2024-01-03T10:19:25.186562Z","iopub.execute_input":"2024-01-03T10:19:25.186981Z","iopub.status.idle":"2024-01-03T10:19:25.216862Z","shell.execute_reply.started":"2024-01-03T10:19:25.186931Z","shell.execute_reply":"2024-01-03T10:19:25.215509Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bidder_id = test_df['bidder_id']","metadata":{"execution":{"iopub.status.busy":"2024-01-03T10:19:25.218489Z","iopub.execute_input":"2024-01-03T10:19:25.219198Z","iopub.status.idle":"2024-01-03T10:19:25.224589Z","shell.execute_reply.started":"2024-01-03T10:19:25.219161Z","shell.execute_reply":"2024-01-03T10:19:25.223379Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.info()","metadata":{"execution":{"iopub.status.busy":"2024-01-03T10:19:25.232436Z","iopub.execute_input":"2024-01-03T10:19:25.232864Z","iopub.status.idle":"2024-01-03T10:19:25.250273Z","shell.execute_reply.started":"2024-01-03T10:19:25.232797Z","shell.execute_reply":"2024-01-03T10:19:25.249247Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.describe()","metadata":{"execution":{"iopub.status.busy":"2024-01-03T10:19:25.253782Z","iopub.execute_input":"2024-01-03T10:19:25.254198Z","iopub.status.idle":"2024-01-03T10:19:25.286497Z","shell.execute_reply.started":"2024-01-03T10:19:25.254162Z","shell.execute_reply":"2024-01-03T10:19:25.285250Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2024-01-03T10:19:25.288166Z","iopub.execute_input":"2024-01-03T10:19:25.288516Z","iopub.status.idle":"2024-01-03T10:19:25.301529Z","shell.execute_reply.started":"2024-01-03T10:19:25.288476Z","shell.execute_reply":"2024-01-03T10:19:25.300194Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.shape","metadata":{"execution":{"iopub.status.busy":"2024-01-03T10:19:25.303109Z","iopub.execute_input":"2024-01-03T10:19:25.303548Z","iopub.status.idle":"2024-01-03T10:19:25.313137Z","shell.execute_reply.started":"2024-01-03T10:19:25.303476Z","shell.execute_reply":"2024-01-03T10:19:25.311753Z"},"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":"2024-01-03T10:19:25.315021Z","iopub.execute_input":"2024-01-03T10:19:25.315388Z","iopub.status.idle":"2024-01-03T10:19:25.336601Z","shell.execute_reply.started":"2024-01-03T10:19:25.315355Z","shell.execute_reply":"2024-01-03T10:19:25.335302Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2024-01-03T10:19:25.338163Z","iopub.execute_input":"2024-01-03T10:19:25.338643Z","iopub.status.idle":"2024-01-03T10:19:25.350875Z","shell.execute_reply.started":"2024-01-03T10:19:25.338596Z","shell.execute_reply":"2024-01-03T10:19:25.349201Z"},"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":"2024-01-03T10:19:25.352201Z","iopub.execute_input":"2024-01-03T10:19:25.352685Z","iopub.status.idle":"2024-01-03T10:19:25.359761Z","shell.execute_reply.started":"2024-01-03T10:19:25.352647Z","shell.execute_reply":"2024-01-03T10:19:25.358728Z"},"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":"2024-01-03T10:19:25.361490Z","iopub.execute_input":"2024-01-03T10:19:25.362172Z","iopub.status.idle":"2024-01-03T10:19:25.367092Z","shell.execute_reply.started":"2024-01-03T10:19:25.362135Z","shell.execute_reply":"2024-01-03T10:19:25.366062Z"},"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":"2024-01-03T10:19:25.368669Z","iopub.execute_input":"2024-01-03T10:19:25.369066Z","iopub.status.idle":"2024-01-03T10:19:25.377011Z","shell.execute_reply.started":"2024-01-03T10:19:25.369022Z","shell.execute_reply":"2024-01-03T10:19:25.375882Z"},"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":"2024-01-03T10:19:25.378168Z","iopub.execute_input":"2024-01-03T10:19:25.378524Z","iopub.status.idle":"2024-01-03T10:19:25.388284Z","shell.execute_reply.started":"2024-01-03T10:19:25.378490Z","shell.execute_reply":"2024-01-03T10:19:25.387205Z"},"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":"2024-01-03T10:19:25.389593Z","iopub.execute_input":"2024-01-03T10:19:25.390220Z","iopub.status.idle":"2024-01-03T10:19:25.404331Z","shell.execute_reply.started":"2024-01-03T10:19:25.390184Z","shell.execute_reply":"2024-01-03T10:19:25.403072Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_test = test_df\nX_test.shape","metadata":{"execution":{"iopub.status.busy":"2024-01-03T10:19:25.406099Z","iopub.execute_input":"2024-01-03T10:19:25.407472Z","iopub.status.idle":"2024-01-03T10:19:25.418170Z","shell.execute_reply.started":"2024-01-03T10:19:25.407409Z","shell.execute_reply":"2024-01-03T10:19:25.416884Z"},"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":"2024-01-03T10:19:25.420231Z","iopub.execute_input":"2024-01-03T10:19:25.420708Z","iopub.status.idle":"2024-01-03T10:19:25.427994Z","shell.execute_reply.started":"2024-01-03T10:19:25.420663Z","shell.execute_reply":"2024-01-03T10:19:25.426914Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.ensemble import GradientBoostingClassifier\nfrom sklearn.metrics import classification_report\nimport seaborn as sns\nimport matplotlib.pyplot as plt\n\n# Assuming X and Y are your feature matrix and target variable, respectively\nmodel_gbc = GradientBoostingClassifier(max_depth=5, n_estimators=300, random_state=42)\nmodel_gbc.fit(X, Y)\n\n# Predict probabilities for positive class\npred_proba_gbc = model_gbc.predict_proba(X)[:, 1]\n\n# Get predictions and print classification report\npredictions_gbc = model_gbc.predict(X)\nreport_gbc = classification_report(Y, predictions_gbc, target_names=[\"Class 0\", \"Class 1\"], output_dict=True)\n\n# Convert the classification report to a DataFrame for better visualization\ndf_report = pd.DataFrame(report_gbc).transpose()\n\n# Display the classification report with color using seaborn\nsns.heatmap(df_report.iloc[:-1, :-3], annot=True, cmap=\"Blues\", fmt=\".2f\", linewidths=.5)\nplt.title('Classification Report')\nplt.show()\n","metadata":{"scrolled":true,"tags":[],"execution":{"iopub.status.busy":"2024-01-03T10:19:25.429643Z","iopub.execute_input":"2024-01-03T10:19:25.430082Z","iopub.status.idle":"2024-01-03T10:19:27.415606Z","shell.execute_reply.started":"2024-01-03T10:19:25.430004Z","shell.execute_reply":"2024-01-03T10:19:27.414342Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Y_pred = model_gbc.predict_proba(X_test)[:,1]","metadata":{"execution":{"iopub.status.busy":"2024-01-03T10:19:27.417374Z","iopub.execute_input":"2024-01-03T10:19:27.420238Z","iopub.status.idle":"2024-01-03T10:19:27.456497Z","shell.execute_reply.started":"2024-01-03T10:19:27.420174Z","shell.execute_reply":"2024-01-03T10:19:27.455125Z"},"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":"2024-01-03T10:19:27.458746Z","iopub.execute_input":"2024-01-03T10:19:27.459299Z","iopub.status.idle":"2024-01-03T10:19:27.498365Z","shell.execute_reply.started":"2024-01-03T10:19:27.459249Z","shell.execute_reply":"2024-01-03T10:19:27.497069Z"},"trusted":true},"execution_count":null,"outputs":[]}]}