{"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":"none","dataSources":[{"sourceId":38760,"databundleVersionId":4493939,"sourceType":"competition"},{"sourceId":4436180,"sourceType":"datasetVersion","datasetId":2597726}],"dockerImageVersionId":30664,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## <p style=\"font-family:JetBrains Mono; font-weight:normal; letter-spacing: 2px; color:#EC0010; font-size:140%; text-align:left;padding: 0px; border-bottom: 3px solid #EC0010\">Libraries</p>","metadata":{}},{"cell_type":"code","source":"import pandas as pd, numpy as np\n\nimport glob\n\n\nimport warnings\nwarnings.filterwarnings(\"ignore\")\n\nfrom datetime import datetime\n\nfrom tqdm import tqdm\n\ntype_labels = {'clicks':1, 'carts':2, 'orders':3}","metadata":{"execution":{"iopub.status.busy":"2024-05-03T02:09:06.512797Z","iopub.execute_input":"2024-05-03T02:09:06.513298Z","iopub.status.idle":"2024-05-03T02:09:07.124747Z","shell.execute_reply.started":"2024-05-03T02:09:06.513260Z","shell.execute_reply":"2024-05-03T02:09:07.123392Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## <p style=\"font-family:JetBrains Mono; font-weight:normal; letter-spacing: 2px; color:#EC0010; font-size:140%; text-align:left;padding: 0px; border-bottom: 3px solid #EC0010\">Data Loading</p>","metadata":{}},{"cell_type":"code","source":"def load(which):    \n    dfs = []\n\n    test_files = glob.glob('/kaggle/input/otto-chunk-data-inparquet-format/'+which+'_parquet/*')\n    \n    for e, chunk_file in enumerate(test_files):\n        chunk = pd.read_parquet(chunk_file)\n        chunk.ts = (chunk.ts/1000).astype('int32')\n        chunk['type'] = chunk['type'].map(type_labels).astype('int8')\n        dfs.append(chunk)\n        \n    return pd.concat(dfs).reset_index(drop=True) #.astype({\"ts\": \"datetime64[ms]\"})","metadata":{"execution":{"iopub.status.busy":"2024-05-03T02:09:11.011587Z","iopub.execute_input":"2024-05-03T02:09:11.012908Z","iopub.status.idle":"2024-05-03T02:09:11.022558Z","shell.execute_reply.started":"2024-05-03T02:09:11.012854Z","shell.execute_reply":"2024-05-03T02:09:11.020938Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#test_df = load('test')\ntrain_df = load('train')","metadata":{"execution":{"iopub.status.busy":"2024-05-03T02:09:13.704846Z","iopub.execute_input":"2024-05-03T02:09:13.705398Z","iopub.status.idle":"2024-05-03T02:10:33.631874Z","shell.execute_reply.started":"2024-05-03T02:09:13.705355Z","shell.execute_reply":"2024-05-03T02:10:33.630314Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df","metadata":{"execution":{"iopub.status.busy":"2024-05-03T02:10:33.634467Z","iopub.execute_input":"2024-05-03T02:10:33.634862Z","iopub.status.idle":"2024-05-03T02:10:33.660073Z","shell.execute_reply.started":"2024-05-03T02:10:33.634832Z","shell.execute_reply":"2024-05-03T02:10:33.658522Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## <p style=\"font-family:JetBrains Mono; font-weight:normal; letter-spacing: 2px; color:#EC0010; font-size:140%; text-align:left;padding: 0px; border-bottom: 3px solid #EC0010\">Generation of small dataset</p>","metadata":{}},{"cell_type":"markdown","source":"## To reduce runtime, only consider data from the last 4 days as train_df.","metadata":{}},{"cell_type":"code","source":"datetime.strptime(\"2022-08-25 00:00:00\", \"%Y-%m-%d %H:%M:%S\").timestamp()","metadata":{"execution":{"iopub.status.busy":"2024-05-03T02:11:48.073565Z","iopub.execute_input":"2024-05-03T02:11:48.074049Z","iopub.status.idle":"2024-05-03T02:11:48.086459Z","shell.execute_reply.started":"2024-05-03T02:11:48.074016Z","shell.execute_reply":"2024-05-03T02:11:48.083655Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sum(train_df['ts']>=1661385600)","metadata":{"execution":{"iopub.status.busy":"2024-05-03T02:11:49.296849Z","iopub.execute_input":"2024-05-03T02:11:49.297375Z","iopub.status.idle":"2024-05-03T02:12:18.905760Z","shell.execute_reply.started":"2024-05-03T02:11:49.297335Z","shell.execute_reply":"2024-05-03T02:12:18.904366Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = train_df[train_df['ts']>=1661385600].reset_index(drop=True)","metadata":{"execution":{"iopub.status.busy":"2024-05-03T02:12:18.908190Z","iopub.execute_input":"2024-05-03T02:12:18.908586Z","iopub.status.idle":"2024-05-03T02:12:21.631718Z","shell.execute_reply.started":"2024-05-03T02:12:18.908557Z","shell.execute_reply":"2024-05-03T02:12:21.630372Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['datetime'] = train_df['ts'].apply(lambda x: datetime.fromtimestamp(x))","metadata":{"execution":{"iopub.status.busy":"2024-05-03T02:12:21.633038Z","iopub.execute_input":"2024-05-03T02:12:21.633433Z","iopub.status.idle":"2024-05-03T02:13:39.105614Z","shell.execute_reply.started":"2024-05-03T02:12:21.633401Z","shell.execute_reply":"2024-05-03T02:13:39.103703Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.shape","metadata":{"execution":{"iopub.status.busy":"2024-05-03T02:13:39.109113Z","iopub.execute_input":"2024-05-03T02:13:39.109679Z","iopub.status.idle":"2024-05-03T02:13:39.120190Z","shell.execute_reply.started":"2024-05-03T02:13:39.109636Z","shell.execute_reply":"2024-05-03T02:13:39.118602Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['session'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-05-03T02:13:39.122070Z","iopub.execute_input":"2024-05-03T02:13:39.122692Z","iopub.status.idle":"2024-05-03T02:13:40.428336Z","shell.execute_reply.started":"2024-05-03T02:13:39.122633Z","shell.execute_reply":"2024-05-03T02:13:40.426950Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['aid'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-05-03T02:13:40.429980Z","iopub.execute_input":"2024-05-03T02:13:40.430481Z","iopub.status.idle":"2024-05-03T02:13:41.542726Z","shell.execute_reply.started":"2024-05-03T02:13:40.430445Z","shell.execute_reply":"2024-05-03T02:13:41.541324Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df","metadata":{"execution":{"iopub.status.busy":"2024-05-03T02:13:41.545276Z","iopub.execute_input":"2024-05-03T02:13:41.546363Z","iopub.status.idle":"2024-05-03T02:13:41.564783Z","shell.execute_reply.started":"2024-05-03T02:13:41.546321Z","shell.execute_reply":"2024-05-03T02:13:41.563316Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## <p style=\"font-family:JetBrains Mono; font-weight:normal; letter-spacing: 2px; color:#EC0010; font-size:140%; text-align:left;padding: 0px; border-bottom: 3px solid #EC0010\">Division of training set and validation set</p>","metadata":{}},{"cell_type":"markdown","source":"## Choose the last day as the validation set.","metadata":{}},{"cell_type":"code","source":"train_df['datetime'].dt.day.unique()","metadata":{"execution":{"iopub.status.busy":"2024-05-03T02:13:41.567249Z","iopub.execute_input":"2024-05-03T02:13:41.568395Z","iopub.status.idle":"2024-05-03T02:13:42.588011Z","shell.execute_reply.started":"2024-05-03T02:13:41.568346Z","shell.execute_reply":"2024-05-03T02:13:42.586554Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['day'] = train_df['datetime'].dt.day","metadata":{"execution":{"iopub.status.busy":"2024-05-03T02:13:42.589879Z","iopub.execute_input":"2024-05-03T02:13:42.590270Z","iopub.status.idle":"2024-05-03T02:13:43.532940Z","shell.execute_reply.started":"2024-05-03T02:13:42.590239Z","shell.execute_reply":"2024-05-03T02:13:43.531651Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_val_offline = train_df[train_df['day']==28].reset_index(drop=True)\ndf_train_offline = train_df[train_df['day']<28].reset_index(drop=True)","metadata":{"execution":{"iopub.status.busy":"2024-05-03T02:13:43.536760Z","iopub.execute_input":"2024-05-03T02:13:43.537170Z","iopub.status.idle":"2024-05-03T02:13:46.775241Z","shell.execute_reply.started":"2024-05-03T02:13:43.537138Z","shell.execute_reply":"2024-05-03T02:13:46.773724Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## <p style=\"font-family:JetBrains Mono; font-weight:normal; letter-spacing: 2px; color:#EC0010; font-size:140%; text-align:left;padding: 0px; border-bottom: 3px solid #EC0010\">Recommendation based on item popularity</p>","metadata":{}},{"cell_type":"markdown","source":"## Analyze item popularity based on different types of behavior.","metadata":{}},{"cell_type":"code","source":"aid_pop_sta = df_train_offline.groupby(['aid','type'],as_index=False)['session'].count()","metadata":{"execution":{"iopub.status.busy":"2024-05-03T02:19:32.696077Z","iopub.execute_input":"2024-05-03T02:19:32.696589Z","iopub.status.idle":"2024-05-03T02:19:37.479356Z","shell.execute_reply.started":"2024-05-03T02:19:32.696552Z","shell.execute_reply":"2024-05-03T02:19:37.478024Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"aid_pop_sta.columns = ['aid','type','pop']","metadata":{"execution":{"iopub.status.busy":"2024-05-03T02:27:39.601615Z","iopub.execute_input":"2024-05-03T02:27:39.602228Z","iopub.status.idle":"2024-05-03T02:27:39.610899Z","shell.execute_reply.started":"2024-05-03T02:27:39.602168Z","shell.execute_reply":"2024-05-03T02:27:39.609160Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"aid_pop_sta","metadata":{"execution":{"iopub.status.busy":"2024-05-03T02:27:39.794514Z","iopub.execute_input":"2024-05-03T02:27:39.795079Z","iopub.status.idle":"2024-05-03T02:27:39.813030Z","shell.execute_reply.started":"2024-05-03T02:27:39.795026Z","shell.execute_reply":"2024-05-03T02:27:39.811194Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Obtain the top 200 most popular items.","metadata":{}},{"cell_type":"code","source":"aid_pop_sta = aid_pop_sta.sort_values(['type','pop'],ascending=False).reset_index(drop=True)","metadata":{"execution":{"iopub.status.busy":"2024-05-03T02:28:43.554935Z","iopub.execute_input":"2024-05-03T02:28:43.555420Z","iopub.status.idle":"2024-05-03T02:28:43.812716Z","shell.execute_reply.started":"2024-05-03T02:28:43.555382Z","shell.execute_reply":"2024-05-03T02:28:43.811168Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"aid_pop_sta","metadata":{"execution":{"iopub.status.busy":"2024-05-03T02:30:28.747581Z","iopub.execute_input":"2024-05-03T02:30:28.748049Z","iopub.status.idle":"2024-05-03T02:30:28.761211Z","shell.execute_reply.started":"2024-05-03T02:30:28.748015Z","shell.execute_reply":"2024-05-03T02:30:28.760323Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"top200_aid_click = list(aid_pop_sta.loc[aid_pop_sta['type']==1,'aid'][:200])\ntop200_aid_cart = list(aid_pop_sta.loc[aid_pop_sta['type']==2,'aid'][:200])\ntop200_aid_order = list(aid_pop_sta.loc[aid_pop_sta['type']==3,'aid'][:200])","metadata":{"execution":{"iopub.status.busy":"2024-05-03T02:30:24.014690Z","iopub.execute_input":"2024-05-03T02:30:24.015274Z","iopub.status.idle":"2024-05-03T02:30:24.074832Z","shell.execute_reply.started":"2024-05-03T02:30:24.015234Z","shell.execute_reply":"2024-05-03T02:30:24.072776Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Obtain the historical behavior list of the target user. The users in the validation set are the target users.","metadata":{}},{"cell_type":"code","source":"target_users = list( df_val_offline['session'].unique() )","metadata":{"execution":{"iopub.status.busy":"2024-05-03T02:43:12.919851Z","iopub.execute_input":"2024-05-03T02:43:12.920430Z","iopub.status.idle":"2024-05-03T02:43:13.235042Z","shell.execute_reply.started":"2024-05-03T02:43:12.920384Z","shell.execute_reply":"2024-05-03T02:43:13.233678Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(target_users)","metadata":{"execution":{"iopub.status.busy":"2024-05-03T02:44:32.645707Z","iopub.execute_input":"2024-05-03T02:44:32.646105Z","iopub.status.idle":"2024-05-03T02:44:32.655016Z","shell.execute_reply.started":"2024-05-03T02:44:32.646073Z","shell.execute_reply":"2024-05-03T02:44:32.653606Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"session_his = df_train_offline.loc[df_train_offline['session'].isin(target_users)].groupby(['session','type'],as_index=False)['aid'].agg(list)","metadata":{"execution":{"iopub.status.busy":"2024-05-03T02:44:01.947680Z","iopub.execute_input":"2024-05-03T02:44:01.948202Z","iopub.status.idle":"2024-05-03T02:44:32.611766Z","shell.execute_reply.started":"2024-05-03T02:44:01.948164Z","shell.execute_reply":"2024-05-03T02:44:32.609990Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"session_his","metadata":{"execution":{"iopub.status.busy":"2024-05-03T02:44:32.614677Z","iopub.execute_input":"2024-05-03T02:44:32.615203Z","iopub.status.idle":"2024-05-03T02:44:32.642997Z","shell.execute_reply.started":"2024-05-03T02:44:32.615161Z","shell.execute_reply":"2024-05-03T02:44:32.641101Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"session_his['session'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-05-03T02:44:49.220020Z","iopub.execute_input":"2024-05-03T02:44:49.220677Z","iopub.status.idle":"2024-05-03T02:44:49.282934Z","shell.execute_reply.started":"2024-05-03T02:44:49.220627Z","shell.execute_reply":"2024-05-03T02:44:49.281515Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Only 558344 out of 1350502 target users have historical behavior.**","metadata":{}},{"cell_type":"code","source":"his_click_dict = dict(zip(session_his.loc[session_his['type']==1,'session'],session_his.loc[session_his['type']==1,'aid']))\nhis_cart_dict = dict(zip(session_his.loc[session_his['type']==2,'session'],session_his.loc[session_his['type']==2,'aid']))\nhis_order_dict = dict(zip(session_his.loc[session_his['type']==3,'session'],session_his.loc[session_his['type']==3,'aid']))","metadata":{"execution":{"iopub.status.busy":"2024-05-03T02:49:02.198367Z","iopub.execute_input":"2024-05-03T02:49:02.198903Z","iopub.status.idle":"2024-05-03T02:49:02.720308Z","shell.execute_reply.started":"2024-05-03T02:49:02.198864Z","shell.execute_reply":"2024-05-03T02:49:02.718863Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Recommend to the target users based on item popularity, while excluding items that have appeared in the users' historical behavior records.","metadata":{}},{"cell_type":"code","source":"res = []\n\nfor each_session in tqdm(target_users):\n\n    if each_session in his_click_dict:\n        his_click_tmp = his_click_dict[each_session]\n        res.append([str(each_session)+'_clicks'] + [' '.join([str(x) for x in top200_aid_click if x not in his_click_tmp][:20])] )\n    else:\n        res.append([str(each_session)+'_clicks'] + [' '.join([str(x) for x in top200_aid_click][:20])])\n        \n        \n    if each_session in his_cart_dict:\n        his_cart_tmp = his_cart_dict[each_session]\n        res.append([str(each_session)+'_carts'] + [' '.join([str(x) for x in top200_aid_cart if x not in his_cart_tmp][:20])] )\n    else:\n        res.append([str(each_session)+'_carts'] + [' '.join([str(x) for x in top200_aid_cart][:20])])\n        \n    if each_session in his_order_dict:\n        his_order_tmp = his_order_dict[each_session]\n        res.append([str(each_session)+'_orders'] + [' '.join([str(x) for x in top200_aid_order if x not in his_order_tmp][:20])] )\n    else:\n        res.append([str(each_session)+'_orders'] + [' '.join([str(x) for x in top200_aid_order][:20])])\n    ","metadata":{"execution":{"iopub.status.busy":"2024-05-03T02:58:08.853046Z","iopub.execute_input":"2024-05-03T02:58:08.854547Z","iopub.status.idle":"2024-05-03T03:02:02.010410Z","shell.execute_reply.started":"2024-05-03T02:58:08.854496Z","shell.execute_reply":"2024-05-03T03:02:02.008644Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_res = pd.DataFrame(res)","metadata":{"execution":{"iopub.status.busy":"2024-05-03T03:05:55.369954Z","iopub.execute_input":"2024-05-03T03:05:55.370475Z","iopub.status.idle":"2024-05-03T03:05:56.679089Z","shell.execute_reply.started":"2024-05-03T03:05:55.370438Z","shell.execute_reply":"2024-05-03T03:05:56.677662Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_res","metadata":{"execution":{"iopub.status.busy":"2024-05-03T03:06:50.170563Z","iopub.execute_input":"2024-05-03T03:06:50.171441Z","iopub.status.idle":"2024-05-03T03:06:50.194204Z","shell.execute_reply.started":"2024-05-03T03:06:50.171380Z","shell.execute_reply":"2024-05-03T03:06:50.192725Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"res_dict = dict(zip(df_res[0],df_res[1]))","metadata":{"execution":{"iopub.status.busy":"2024-05-03T03:06:34.940870Z","iopub.execute_input":"2024-05-03T03:06:34.941363Z","iopub.status.idle":"2024-05-03T03:06:38.143595Z","shell.execute_reply.started":"2024-05-03T03:06:34.941326Z","shell.execute_reply":"2024-05-03T03:06:38.141664Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## <p style=\"font-family:JetBrains Mono; font-weight:normal; letter-spacing: 2px; color:#EC0010; font-size:140%; text-align:left;padding: 0px; border-bottom: 3px solid #EC0010\">Evaluate performance</p>","metadata":{}},{"cell_type":"code","source":"session_items_val = df_val_offline.groupby(['session','type'],as_index=False)['aid'].agg(set)","metadata":{"execution":{"iopub.status.busy":"2024-05-03T03:02:02.013064Z","iopub.execute_input":"2024-05-03T03:02:02.013546Z","iopub.status.idle":"2024-05-03T03:03:04.676782Z","shell.execute_reply.started":"2024-05-03T03:02:02.013487Z","shell.execute_reply":"2024-05-03T03:03:04.675283Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"session_items_val ","metadata":{"execution":{"iopub.status.busy":"2024-05-03T03:03:52.055563Z","iopub.execute_input":"2024-05-03T03:03:52.056109Z","iopub.status.idle":"2024-05-03T03:03:52.075483Z","shell.execute_reply.started":"2024-05-03T03:03:52.056076Z","shell.execute_reply":"2024-05-03T03:03:52.074487Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"session_items_val['session'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-05-03T03:04:10.020916Z","iopub.execute_input":"2024-05-03T03:04:10.021574Z","iopub.status.idle":"2024-05-03T03:04:10.165422Z","shell.execute_reply.started":"2024-05-03T03:04:10.021522Z","shell.execute_reply":"2024-05-03T03:04:10.164331Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def getScore(df, type_, suffix):\n    df_tmp = df[df['type']==type_].reset_index(drop=True)\n    \n    score_Numerator = 0\n    score_Denominator = 0\n\n    for i,row in tqdm( df_tmp.iterrows(),total=len(df_tmp) ):\n        recom_tmp = [int(x) for x in res_dict[str(row['session'])+suffix].split(' ')]\n        score_Numerator += len(row['aid'] & set(recom_tmp))\n        score_Denominator += min(20,len(row['aid']))\n        \n    return score_Numerator/score_Denominator","metadata":{"execution":{"iopub.status.busy":"2024-05-03T03:15:10.325063Z","iopub.execute_input":"2024-05-03T03:15:10.326799Z","iopub.status.idle":"2024-05-03T03:15:10.335653Z","shell.execute_reply.started":"2024-05-03T03:15:10.326744Z","shell.execute_reply":"2024-05-03T03:15:10.334527Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"score_click = getScore(session_items_val,1,'_clicks')","metadata":{"execution":{"iopub.status.busy":"2024-05-03T03:19:51.186725Z","iopub.execute_input":"2024-05-03T03:19:51.187105Z","iopub.status.idle":"2024-05-03T03:21:55.245156Z","shell.execute_reply.started":"2024-05-03T03:19:51.187072Z","shell.execute_reply":"2024-05-03T03:21:55.243714Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"score_cart = getScore(session_items_val,2,'_carts')","metadata":{"execution":{"iopub.status.busy":"2024-05-03T03:19:25.322959Z","iopub.execute_input":"2024-05-03T03:19:25.324499Z","iopub.status.idle":"2024-05-03T03:19:51.184448Z","shell.execute_reply.started":"2024-05-03T03:19:25.324436Z","shell.execute_reply":"2024-05-03T03:19:51.181841Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"score_order = getScore(session_items_val,3,'_orders')","metadata":{"execution":{"iopub.status.busy":"2024-05-03T03:18:51.528560Z","iopub.execute_input":"2024-05-03T03:18:51.529094Z","iopub.status.idle":"2024-05-03T03:19:00.830776Z","shell.execute_reply.started":"2024-05-03T03:18:51.529051Z","shell.execute_reply":"2024-05-03T03:19:00.829396Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"score_click * 0.1 + score_cart * 0.3 + score_order * 0.6","metadata":{"execution":{"iopub.status.busy":"2024-05-03T03:21:55.246959Z","iopub.execute_input":"2024-05-03T03:21:55.247394Z","iopub.status.idle":"2024-05-03T03:21:55.256548Z","shell.execute_reply.started":"2024-05-03T03:21:55.247356Z","shell.execute_reply":"2024-05-03T03:21:55.255094Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}