{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.14","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[{"sourceId":3288,"databundleVersionId":31051,"sourceType":"competition"}],"dockerImageVersionId":30788,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Import the data","metadata":{}},{"cell_type":"code","source":"# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport matplotlib.pyplot as plt\n# Input data files are available in the read-only \"../input/\" directory\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-01-05T06:34:25.046130Z","iopub.execute_input":"2025-01-05T06:34:25.046811Z","iopub.status.idle":"2025-01-05T06:34:25.053170Z","shell.execute_reply.started":"2025-01-05T06:34:25.046776Z","shell.execute_reply":"2025-01-05T06:34:25.052289Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"event_attendees=pd.read_csv(\"/kaggle/input/event-recommendation-engine-challenge/event_attendees.csv.gz\", compression = \"gzip\")\nusers=pd.read_csv(\"/kaggle/input/event-recommendation-engine-challenge/users.csv\")\nuser_friends = pd.read_csv(\"/kaggle/input/event-recommendation-engine-challenge/user_friends.csv.gz\", compression = \"gzip\")\nevents=pd.read_csv(\"/kaggle/input/event-recommendation-engine-challenge/events.csv.gz\", compression = \"gzip\")\n\ntrain=pd.read_csv(\"/kaggle/input/event-recommendation-engine-challenge/train.csv\")\ntest=pd.read_csv(\"/kaggle/input/event-recommendation-engine-challenge/test.csv\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-05T06:32:23.459556Z","iopub.execute_input":"2025-01-05T06:32:23.460386Z","iopub.status.idle":"2025-01-05T06:32:59.207156Z","shell.execute_reply.started":"2025-01-05T06:32:23.460348Z","shell.execute_reply":"2025-01-05T06:32:59.206220Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"#convert to datetime format \ntrain[\"timestamp\"] = pd.to_datetime(train[\"timestamp\"],format = \"ISO8601\")\nusers[\"joinedAt\"] = pd.to_datetime(users[\"joinedAt\"],format = \"ISO8601\")\nevents[\"start_time\"] = pd.to_datetime(events[\"start_time\"],format = \"ISO8601\", errors = \"coerce\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-05T06:33:02.046946Z","iopub.execute_input":"2025-01-05T06:33:02.047964Z","iopub.status.idle":"2025-01-05T06:33:02.919174Z","shell.execute_reply.started":"2025-01-05T06:33:02.047910Z","shell.execute_reply":"2025-01-05T06:33:02.918300Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def info_describe(df):\n    print(\"{} \\n \\n {} \".format(df.info(), df.describe(include = \"all\")))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-05T03:48:23.745307Z","iopub.execute_input":"2025-01-05T03:48:23.745570Z","iopub.status.idle":"2025-01-05T03:48:23.749777Z","shell.execute_reply.started":"2025-01-05T03:48:23.745545Z","shell.execute_reply":"2025-01-05T03:48:23.748810Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## train","metadata":{}},{"cell_type":"code","source":"train[train[\"invited\"]!=0].head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-05T08:04:29.468193Z","iopub.execute_input":"2025-01-05T08:04:29.468996Z","iopub.status.idle":"2025-01-05T08:04:29.479506Z","shell.execute_reply.started":"2025-01-05T08:04:29.468959Z","shell.execute_reply":"2025-01-05T08:04:29.478534Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"info_describe(train)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-05T03:48:23.769534Z","iopub.execute_input":"2025-01-05T03:48:23.769776Z","iopub.status.idle":"2025-01-05T03:48:23.801392Z","shell.execute_reply.started":"2025-01-05T03:48:23.769751Z","shell.execute_reply":"2025-01-05T03:48:23.800340Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## event_attendees","metadata":{}},{"cell_type":"code","source":"event_attendees.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-05T03:48:23.802591Z","iopub.execute_input":"2025-01-05T03:48:23.802945Z","iopub.status.idle":"2025-01-05T03:48:23.811538Z","shell.execute_reply.started":"2025-01-05T03:48:23.802917Z","shell.execute_reply":"2025-01-05T03:48:23.810651Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"info_describe(event_attendees)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-05T03:48:23.812415Z","iopub.execute_input":"2025-01-05T03:48:23.812717Z","iopub.status.idle":"2025-01-05T03:48:23.955411Z","shell.execute_reply.started":"2025-01-05T03:48:23.812691Z","shell.execute_reply":"2025-01-05T03:48:23.954547Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## users","metadata":{}},{"cell_type":"code","source":"users.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-05T03:48:23.956543Z","iopub.execute_input":"2025-01-05T03:48:23.956810Z","iopub.status.idle":"2025-01-05T03:48:23.967798Z","shell.execute_reply.started":"2025-01-05T03:48:23.956783Z","shell.execute_reply":"2025-01-05T03:48:23.966871Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"info_describe(users)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-05T03:48:23.968861Z","iopub.execute_input":"2025-01-05T03:48:23.969145Z","iopub.status.idle":"2025-01-05T03:48:24.015030Z","shell.execute_reply.started":"2025-01-05T03:48:23.969105Z","shell.execute_reply":"2025-01-05T03:48:24.014250Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## events","metadata":{}},{"cell_type":"code","source":"events.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-05T03:48:24.015914Z","iopub.execute_input":"2025-01-05T03:48:24.016159Z","iopub.status.idle":"2025-01-05T03:48:24.032522Z","shell.execute_reply.started":"2025-01-05T03:48:24.016129Z","shell.execute_reply":"2025-01-05T03:48:24.031582Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"info_describe(events)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-05T03:48:24.033596Z","iopub.execute_input":"2025-01-05T03:48:24.034233Z","iopub.status.idle":"2025-01-05T03:48:31.320240Z","shell.execute_reply.started":"2025-01-05T03:48:24.034204Z","shell.execute_reply":"2025-01-05T03:48:31.319379Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## user_friends","metadata":{}},{"cell_type":"code","source":"user_friends.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-05T03:48:31.321392Z","iopub.execute_input":"2025-01-05T03:48:31.321766Z","iopub.status.idle":"2025-01-05T03:48:31.329674Z","shell.execute_reply.started":"2025-01-05T03:48:31.321726Z","shell.execute_reply":"2025-01-05T03:48:31.328864Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"info_describe(user_friends)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-05T03:48:31.330904Z","iopub.execute_input":"2025-01-05T03:48:31.331203Z","iopub.status.idle":"2025-01-05T03:48:31.552563Z","shell.execute_reply.started":"2025-01-05T03:48:31.331176Z","shell.execute_reply":"2025-01-05T03:48:31.551721Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Understand target variable","metadata":{}},{"cell_type":"code","source":"train.groupby([\"interested\",\"not_interested\"]).size()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-05T03:48:31.553710Z","iopub.execute_input":"2025-01-05T03:48:31.554348Z","iopub.status.idle":"2025-01-05T03:48:31.563919Z","shell.execute_reply.started":"2025-01-05T03:48:31.554305Z","shell.execute_reply":"2025-01-05T03:48:31.563095Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Process event_attendees table into 4 tables: yes.maybe,invite,no tables","metadata":{}},{"cell_type":"code","source":"# Create function that creates exploded sub table from event_attendees table\n\ndef exploded_sub_df( target_col, id, source_table,new_colname):\n    sub_df = source_table[[id,target_col]].copy()\n    sub_df[new_colname] = sub_df[target_col].str.split()\n    sub_df = sub_df.explode(new_colname, ignore_index = True)\n    sub_df.dropna(subset=[new_colname], inplace=True)\n    sub_df[new_colname] = sub_df[new_colname].astype('int64')\n    sub_df.drop([target_col], axis = 1, inplace = True)\n    return sub_df","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-05T06:46:56.255533Z","iopub.execute_input":"2025-01-05T06:46:56.255875Z","iopub.status.idle":"2025-01-05T06:46:56.261162Z","shell.execute_reply.started":"2025-01-05T06:46:56.255845Z","shell.execute_reply":"2025-01-05T06:46:56.260208Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# create table that captures users who said \"yes\" to an event\nevent_attendees_yes = exploded_sub_df( \"yes\", \"event\", event_attendees, \"user\")\nprint(event_attendees_yes.info())\nevent_attendees_yes.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-05T06:47:02.583910Z","iopub.execute_input":"2025-01-05T06:47:02.584249Z","iopub.status.idle":"2025-01-05T06:47:02.972390Z","shell.execute_reply.started":"2025-01-05T06:47:02.584217Z","shell.execute_reply":"2025-01-05T06:47:02.971534Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# create table that captures users who said \"maybe\" to an event\nevent_attendees_maybe = exploded_sub_df( \"maybe\", \"event\", event_attendees,\"user\")\nprint(event_attendees_maybe.info())\nevent_attendees_maybe.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-05T06:47:08.230809Z","iopub.execute_input":"2025-01-05T06:47:08.231766Z","iopub.status.idle":"2025-01-05T06:47:08.488221Z","shell.execute_reply.started":"2025-01-05T06:47:08.231717Z","shell.execute_reply":"2025-01-05T06:47:08.487359Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# create table that captures users who said \"no\" to an event\nevent_attendees_no = exploded_sub_df( \"no\", \"event\", event_attendees,\"user\")\nprint(event_attendees_no.info())\nevent_attendees_no.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-05T06:47:10.353220Z","iopub.execute_input":"2025-01-05T06:47:10.354107Z","iopub.status.idle":"2025-01-05T06:47:10.596269Z","shell.execute_reply.started":"2025-01-05T06:47:10.354072Z","shell.execute_reply":"2025-01-05T06:47:10.595426Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# create table that captures users who said \"invited\" to an event\nevent_attendees_invited = exploded_sub_df( \"invited\", \"event\", event_attendees,\"user\")\nprint(event_attendees_invited.info())\nevent_attendees_invited.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-05T06:47:12.511279Z","iopub.execute_input":"2025-01-05T06:47:12.511928Z","iopub.status.idle":"2025-01-05T06:47:16.755410Z","shell.execute_reply.started":"2025-01-05T06:47:12.511893Z","shell.execute_reply":"2025-01-05T06:47:16.754589Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Process user_friends table into exploded table","metadata":{"execution":{"iopub.status.busy":"2025-01-05T06:19:21.432649Z","iopub.execute_input":"2025-01-05T06:19:21.433002Z","iopub.status.idle":"2025-01-05T06:19:21.436996Z","shell.execute_reply.started":"2025-01-05T06:19:21.432969Z","shell.execute_reply":"2025-01-05T06:19:21.436142Z"}}},{"cell_type":"code","source":"user_friends_df = exploded_sub_df( \"friends\", \"user\", user_friends,\"friends_uid\")\nprint(user_friends_df.info())\nuser_friends_df.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-05T06:47:21.444669Z","iopub.execute_input":"2025-01-05T06:47:21.445031Z","iopub.status.idle":"2025-01-05T06:47:35.040636Z","shell.execute_reply.started":"2025-01-05T06:47:21.444998Z","shell.execute_reply":"2025-01-05T06:47:35.039836Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Feature engineering: Time realted feaures","metadata":{}},{"cell_type":"code","source":"# check the date column in event table\nprint(\"MIN of event[\\\"start_time\\\"] : {} \\n\".format(events[\"start_time\"].min()))\nprint(\"MAX of event[\\\"start_time\\\"] : {}\\n\".format(events[\"start_time\"].max()))\nprint(events.groupby(events[\"start_time\"].dt.strftime('%Y'))['event_id'].nunique())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-05T03:48:31.565030Z","iopub.execute_input":"2025-01-05T03:48:31.565273Z","iopub.status.idle":"2025-01-05T03:48:45.667167Z","shell.execute_reply.started":"2025-01-05T03:48:31.565249Z","shell.execute_reply":"2025-01-05T03:48:45.666260Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# check the date column in users table\nprint(\"MIN of users[\\\"joinedAt\\\"] : {} \\n\".format(users[\"joinedAt\"].min()))\nprint(\"MAX of users[\\\"joinedAt\\\"] : {} \\n\".format(users[\"joinedAt\"].max()))\nprint(users.groupby(users[\"joinedAt\"].dt.strftime('%Y'))['user_id'].nunique())\n\n# train[\"timestamp\"] = pd.to_datetime(train[\"timestamp\"],format = \"ISO8601\")\n# users[\"joinedAt\"] = pd.to_datetime(users[\"joinedAt\"],format = \"ISO8601\")\n# events[\"start_time\"] = pd.to_datetime(events[\"start_time\"],format = \"ISO8601\", errors = \"coerce\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-05T03:48:45.668055Z","iopub.execute_input":"2025-01-05T03:48:45.668287Z","iopub.status.idle":"2025-01-05T03:48:45.843259Z","shell.execute_reply.started":"2025-01-05T03:48:45.668264Z","shell.execute_reply":"2025-01-05T03:48:45.842528Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# check the date column in train table\nprint(\"MIN of train[\\\"timestamp\\\"] : {} \\n\".format(train[\"timestamp\"].min()))\nprint(\"MAX of train[\\\"timestamp\\\"] : {} \\n\".format(train[\"timestamp\"].max()))\nprint(train.groupby(train[\"timestamp\"].dt.strftime('%Y'))['user'].nunique())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-05T03:48:45.844221Z","iopub.execute_input":"2025-01-05T03:48:45.844469Z","iopub.status.idle":"2025-01-05T03:48:45.925368Z","shell.execute_reply.started":"2025-01-05T03:48:45.844430Z","shell.execute_reply":"2025-01-05T03:48:45.924502Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Time Feature 1: Time left to the event from viewing the event","metadata":{}},{"cell_type":"code","source":"train_df=pd.merge(train,events[[\"event_id\",\"start_time\"]],left_on=\"event\",right_on=\"event_id\",how=\"left\").drop(\"event_id\",axis=1)\ntrain_df[\"hrs_to_event\"] = (train_df[\"start_time\"]-train_df[\"timestamp\"]).dt.total_seconds()/3600","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-05T08:00:25.756793Z","iopub.execute_input":"2025-01-05T08:00:25.757433Z","iopub.status.idle":"2025-01-05T08:00:26.131626Z","shell.execute_reply.started":"2025-01-05T08:00:25.757397Z","shell.execute_reply":"2025-01-05T08:00:26.130624Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-05T03:48:46.307094Z","iopub.execute_input":"2025-01-05T03:48:46.307371Z","iopub.status.idle":"2025-01-05T03:48:46.317431Z","shell.execute_reply.started":"2025-01-05T03:48:46.307344Z","shell.execute_reply":"2025-01-05T03:48:46.316369Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(\"\\n*** df shape \\n {} ***\".format(train_df.shape))\nprint(\"\\n*** hrs_to_event analysis \\n {} ***\".format(train_df[\"hrs_to_event\"].describe()))\nprint(\"\\n*** Missing count {} ***\".format (train_df['hrs_to_event'].isnull().sum()))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-05T03:48:46.321701Z","iopub.execute_input":"2025-01-05T03:48:46.322003Z","iopub.status.idle":"2025-01-05T03:48:46.331152Z","shell.execute_reply.started":"2025-01-05T03:48:46.321979Z","shell.execute_reply":"2025-01-05T03:48:46.330314Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"fig, axes = plt.subplots(1,3, figsize = (15,4))\n\ntrain_df[\"hrs_to_event\"].plot.hist(ax=axes[0])\ntrain_df[\"hrs_to_event\"].plot.hist(ax=axes[1], density = True)\ntrain_df[\"hrs_to_event\"].plot.kde(ax=axes[1])\ntrain_df[\"hrs_to_event\"].plot.box(ax=axes[2])\n\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-05T03:48:46.331979Z","iopub.execute_input":"2025-01-05T03:48:46.332192Z","iopub.status.idle":"2025-01-05T03:48:47.544134Z","shell.execute_reply.started":"2025-01-05T03:48:46.332169Z","shell.execute_reply":"2025-01-05T03:48:47.543258Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"pd.cut(train_df[\"hrs_to_event\"],bins = [-1000,0,21,55,93,500,1000]).value_counts().sort_index()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-05T03:48:47.545050Z","iopub.execute_input":"2025-01-05T03:48:47.545373Z","iopub.status.idle":"2025-01-05T03:48:47.559937Z","shell.execute_reply.started":"2025-01-05T03:48:47.545348Z","shell.execute_reply":"2025-01-05T03:48:47.559259Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Time Feature 2: Time left to the event from user joined date","metadata":{}},{"cell_type":"code","source":"train_df = pd.merge(train_df,users[[\"user_id\",\"joinedAt\"]],left_on =\"user\",right_on =\"user_id\",how=\"left\").drop(\"user_id\",axis=1)\ntrain_df[\"minsToEvent_frmJoin\"] = (train_df[\"timestamp\"] - train_df[\"joinedAt\"]).dt.total_seconds()/60","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-05T08:00:30.494679Z","iopub.execute_input":"2025-01-05T08:00:30.495394Z","iopub.status.idle":"2025-01-05T08:00:30.509158Z","shell.execute_reply.started":"2025-01-05T08:00:30.495360Z","shell.execute_reply":"2025-01-05T08:00:30.508414Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-05T06:33:24.437903Z","iopub.execute_input":"2025-01-05T06:33:24.438259Z","iopub.status.idle":"2025-01-05T06:33:24.451557Z","shell.execute_reply.started":"2025-01-05T06:33:24.438227Z","shell.execute_reply":"2025-01-05T06:33:24.450650Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(\"***Table shape {}***\".format(train_df.shape))\nprint(\"\\n*** minsToEvent_frmJoin univariate analysis \\n {}***\".format(train_df[\"minsToEvent_frmJoin\"].describe()))\nprint(\"\\n*** minsToEvent_frmJoin null analysis {}***\".format(train_df[\"minsToEvent_frmJoin\"].isnull().sum()))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-05T06:33:46.114737Z","iopub.execute_input":"2025-01-05T06:33:46.115405Z","iopub.status.idle":"2025-01-05T06:33:46.125325Z","shell.execute_reply.started":"2025-01-05T06:33:46.115368Z","shell.execute_reply":"2025-01-05T06:33:46.124330Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"fig, axes = plt.subplots(1,3,figsize = (15,4))\ntrain_df[\"minsToEvent_frmJoin\"].plot.hist(ax = axes[0])\ntrain_df[\"minsToEvent_frmJoin\"].plot.hist(density = True, ax = axes[1])\ntrain_df[\"minsToEvent_frmJoin\"].plot.kde(ax = axes[1])\ntrain_df[\"minsToEvent_frmJoin\"].plot.box(ax = axes[2])\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-05T06:34:39.603973Z","iopub.execute_input":"2025-01-05T06:34:39.604823Z","iopub.status.idle":"2025-01-05T06:34:40.921781Z","shell.execute_reply.started":"2025-01-05T06:34:39.604790Z","shell.execute_reply":"2025-01-05T06:34:40.920754Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"pd.cut(train_df[\"minsToEvent_frmJoin\"], bins = [-3500,0,0.019633,0.056268,28.509839, 100, 1000 ]).value_counts().sort_index()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-05T06:34:52.481326Z","iopub.execute_input":"2025-01-05T06:34:52.482236Z","iopub.status.idle":"2025-01-05T06:34:52.498475Z","shell.execute_reply.started":"2025-01-05T06:34:52.482201Z","shell.execute_reply":"2025-01-05T06:34:52.497635Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Time Feature 3: Users preferred days ","metadata":{}},{"cell_type":"code","source":"# To all the users in the train data get all events that they either chose yes or maybe\ntrain_user = pd.DataFrame(train_df[\"user\"].unique(), columns=['user']) # Get unique user from train\nweekday_pref_yes = pd.merge(train_user,event_attendees_yes.astype({'event':'Int64'}),on=\"user\",how=\"inner\")\nweekday_pref_maybe = pd.merge(train_user, event_attendees_maybe.astype({'event':'Int64'}),on=\"user\",how = \"inner\")\nprint(\"train_user.shape={}\".format(train_user.shape))\nprint(\"weekday_pref_yes.shape={}\".format(weekday_pref_yes.shape))\nprint(\"weekday_pref_maybe.shape={}\\n\".format(weekday_pref_maybe.shape))\n\n# Concat to get the list of user to yes/maybe events\nweekday_pref = pd.concat([weekday_pref_yes, weekday_pref_maybe], axis = 0)\n\nprint(weekday_pref.info())\nweekday_pref.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-05T07:54:14.466775Z","iopub.execute_input":"2025-01-05T07:54:14.467360Z","iopub.status.idle":"2025-01-05T07:54:14.583621Z","shell.execute_reply.started":"2025-01-05T07:54:14.467322Z","shell.execute_reply":"2025-01-05T07:54:14.582718Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# join to events table to get event start_time and extract event's weekday info\nweekday_pref=pd.merge(weekday_pref,events[[\"event_id\",\"start_time\"]],left_on =\"event\",right_on=\"event_id\",how=\"left\")\nweekday_pref[\"weekday\"] = weekday_pref['start_time'].dt.strftime('%A')\nprint(weekday_pref.shape)\nweekday_pref[weekday_pref[\"weekday\"].notna()].head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-05T07:54:19.592211Z","iopub.execute_input":"2025-01-05T07:54:19.592568Z","iopub.status.idle":"2025-01-05T07:54:19.963531Z","shell.execute_reply.started":"2025-01-05T07:54:19.592539Z","shell.execute_reply":"2025-01-05T07:54:19.962602Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# transpose so that we get 7 column for each weekday and count of events on each week day the user had yes/maybe\nweekday_pref_wide = (weekday_pref.groupby([\"user\",\"weekday\"])['event'].nunique()\n                     .unstack(fill_value = 0)\n                     .add_prefix(\"pref_\")\n                     .reset_index()\n                    )\nprint(weekday_pref_wide.shape)\nweekday_pref_wide.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-05T07:54:23.895441Z","iopub.execute_input":"2025-01-05T07:54:23.896085Z","iopub.status.idle":"2025-01-05T07:54:23.911770Z","shell.execute_reply.started":"2025-01-05T07:54:23.896051Z","shell.execute_reply":"2025-01-05T07:54:23.910937Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# join the new weekday pref datapoint to train_df table\ntrain_df = pd.merge(train_df, weekday_pref_wide, on = \"user\", how = \"left\")\nprint(train_df.info()) \ntrain_df[train_df[\"pref_Saturday\"].notna()].head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-05T08:00:49.908676Z","iopub.execute_input":"2025-01-05T08:00:49.909452Z","iopub.status.idle":"2025-01-05T08:00:49.938574Z","shell.execute_reply.started":"2025-01-05T08:00:49.909419Z","shell.execute_reply":"2025-01-05T08:00:49.937708Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Social Feature 1: #of users attending the event","metadata":{"execution":{"iopub.status.busy":"2025-01-05T08:06:39.513606Z","iopub.execute_input":"2025-01-05T08:06:39.513942Z","iopub.status.idle":"2025-01-05T08:06:39.517870Z","shell.execute_reply.started":"2025-01-05T08:06:39.513909Z","shell.execute_reply":"2025-01-05T08:06:39.517028Z"}}},{"cell_type":"markdown","source":"## Social Feature 2: #of friends attending the event","metadata":{}},{"cell_type":"markdown","source":"## Social Feature 3: Is the even host friend of the user","metadata":{}}]}