{"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":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nk=[]\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        k.append(os.path.join(dirname, filename))\n\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","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-11-18T07:18:05.446527Z","iopub.execute_input":"2022-11-18T07:18:05.447658Z","iopub.status.idle":"2022-11-18T07:18:05.482859Z","shell.execute_reply.started":"2022-11-18T07:18:05.447553Z","shell.execute_reply":"2022-11-18T07:18:05.481977Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"! pip install llvmlite --ignore-installed\n! pip install turicreate","metadata":{"execution":{"iopub.status.busy":"2022-11-17T16:09:25.520809Z","iopub.execute_input":"2022-11-17T16:09:25.521549Z","iopub.status.idle":"2022-11-17T16:11:06.102283Z","shell.execute_reply.started":"2022-11-17T16:09:25.521509Z","shell.execute_reply":"2022-11-17T16:11:06.100289Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import dask.dataframe as dd\nimport numpy as np\nimport time\nimport turicreate as tc\nfrom sklearn.model_selection import train_test_split","metadata":{"execution":{"iopub.status.busy":"2022-11-18T07:18:05.484362Z","iopub.execute_input":"2022-11-18T07:18:05.484881Z","iopub.status.idle":"2022-11-18T07:18:06.321687Z","shell.execute_reply.started":"2022-11-18T07:18:05.484849Z","shell.execute_reply":"2022-11-18T07:18:06.320153Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"k","metadata":{"execution":{"iopub.status.busy":"2022-11-18T07:18:11.576334Z","iopub.execute_input":"2022-11-18T07:18:11.576978Z","iopub.status.idle":"2022-11-18T07:18:11.585594Z","shell.execute_reply.started":"2022-11-18T07:18:11.576943Z","shell.execute_reply":"2022-11-18T07:18:11.584499Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data=pd.read_csv(k[3])\ndata_test=pd.read_csv(k[4])","metadata":{"execution":{"iopub.status.busy":"2022-11-17T16:12:00.681622Z","iopub.execute_input":"2022-11-17T16:12:00.682892Z","iopub.status.idle":"2022-11-17T16:12:09.994513Z","shell.execute_reply.started":"2022-11-17T16:12:00.682837Z","shell.execute_reply":"2022-11-17T16:12:09.993114Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.head()","metadata":{"execution":{"iopub.status.busy":"2022-11-17T16:12:09.997067Z","iopub.execute_input":"2022-11-17T16:12:09.997447Z","iopub.status.idle":"2022-11-17T16:12:10.021154Z","shell.execute_reply.started":"2022-11-17T16:12:09.997402Z","shell.execute_reply":"2022-11-17T16:12:10.019366Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_test.head()","metadata":{"execution":{"iopub.status.busy":"2022-11-17T16:12:10.023344Z","iopub.execute_input":"2022-11-17T16:12:10.023933Z","iopub.status.idle":"2022-11-17T16:12:10.036852Z","shell.execute_reply.started":"2022-11-17T16:12:10.023879Z","shell.execute_reply":"2022-11-17T16:12:10.035582Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import warnings\nfrom warnings import filterwarnings\nfilterwarnings('ignore')","metadata":{"execution":{"iopub.status.busy":"2022-11-17T16:12:10.039755Z","iopub.execute_input":"2022-11-17T16:12:10.040127Z","iopub.status.idle":"2022-11-17T16:12:10.046524Z","shell.execute_reply.started":"2022-11-17T16:12:10.040094Z","shell.execute_reply":"2022-11-17T16:12:10.045141Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.set_option('display.max_columns', None)","metadata":{"execution":{"iopub.status.busy":"2022-11-17T16:12:10.048983Z","iopub.execute_input":"2022-11-17T16:12:10.050892Z","iopub.status.idle":"2022-11-17T16:12:10.059116Z","shell.execute_reply.started":"2022-11-17T16:12:10.050824Z","shell.execute_reply":"2022-11-17T16:12:10.057774Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['session']=data['session'].astype('string')\ndata_test['session']=data_test['session'].astype('string')","metadata":{"execution":{"iopub.status.busy":"2022-11-17T16:12:11.369368Z","iopub.execute_input":"2022-11-17T16:12:11.369858Z","iopub.status.idle":"2022-11-17T16:12:18.62798Z","shell.execute_reply.started":"2022-11-17T16:12:11.369817Z","shell.execute_reply":"2022-11-17T16:12:18.626791Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['ids']=data['session']+data['type']\ndata_test['ids']=data_test['session']+data_test['type']","metadata":{"execution":{"iopub.status.busy":"2022-11-17T16:12:18.629916Z","iopub.execute_input":"2022-11-17T16:12:18.630312Z","iopub.status.idle":"2022-11-17T16:12:22.336217Z","shell.execute_reply.started":"2022-11-17T16:12:18.630277Z","shell.execute_reply":"2022-11-17T16:12:22.334822Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['ids_aid']=data['ids']+data['aid'].astype('string')\ndata_test['ids_aid']=data_test['ids']+data_test['aid'].astype('string')","metadata":{"execution":{"iopub.status.busy":"2022-11-17T16:12:22.337646Z","iopub.execute_input":"2022-11-17T16:12:22.338078Z","iopub.status.idle":"2022-11-17T16:12:33.269013Z","shell.execute_reply.started":"2022-11-17T16:12:22.338033Z","shell.execute_reply":"2022-11-17T16:12:33.267799Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df=pd.DataFrame()\ndf_test=pd.DataFrame()\n\ndf['ids_aid']=data['ids_aid'].unique()\ndf_test['ids_aid']=data_test['ids_aid'].unique()","metadata":{"execution":{"iopub.status.busy":"2022-11-17T16:12:33.271579Z","iopub.execute_input":"2022-11-17T16:12:33.271978Z","iopub.status.idle":"2022-11-17T16:12:41.274393Z","shell.execute_reply.started":"2022-11-17T16:12:33.271943Z","shell.execute_reply":"2022-11-17T16:12:41.273213Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['frequency']=list(data['ids_aid'].groupby(data['ids_aid'], sort=False).count())\ndf_test['frequency']=list(data_test['ids_aid'].groupby(data_test['ids_aid'], sort=False).count())","metadata":{"execution":{"iopub.status.busy":"2022-11-17T16:12:41.275964Z","iopub.execute_input":"2022-11-17T16:12:41.276319Z","iopub.status.idle":"2022-11-17T16:12:53.11128Z","shell.execute_reply.started":"2022-11-17T16:12:41.276288Z","shell.execute_reply":"2022-11-17T16:12:53.110089Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['ids']=df['ids_aid'].apply(lambda x: x.split('s')[0] + 's')\ndf['aid']=df['ids_aid'].apply(lambda x: x.split('s')[1])\n\ndf_test['ids']=df_test['ids_aid'].apply(lambda x: x.split('s')[0] + 's')\ndf_test['aid']=df_test['ids_aid'].apply(lambda x: x.split('s')[1])","metadata":{"execution":{"iopub.status.busy":"2022-11-17T16:12:53.112674Z","iopub.execute_input":"2022-11-17T16:12:53.113028Z","iopub.status.idle":"2022-11-17T16:13:00.562606Z","shell.execute_reply.started":"2022-11-17T16:12:53.112997Z","shell.execute_reply":"2022-11-17T16:13:00.561332Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df=df.drop(columns=['ids_aid'],axis=1)\ndf_test=df_test.drop(columns=['ids_aid'],axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-11-17T16:13:00.564104Z","iopub.execute_input":"2022-11-17T16:13:00.564582Z","iopub.status.idle":"2022-11-17T16:13:01.96031Z","shell.execute_reply.started":"2022-11-17T16:13:00.564538Z","shell.execute_reply":"2022-11-17T16:13:01.959342Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['aid']=df['aid'].astype('object')\ndf_test['aid']=df_test['aid'].astype('object')","metadata":{"execution":{"iopub.status.busy":"2022-11-17T16:13:01.963174Z","iopub.execute_input":"2022-11-17T16:13:01.964088Z","iopub.status.idle":"2022-11-17T16:13:02.41455Z","shell.execute_reply.started":"2022-11-17T16:13:01.964041Z","shell.execute_reply":"2022-11-17T16:13:02.413235Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['ids']=df['ids'].astype('object')\ndf_test['ids']=df_test['ids'].astype('object')","metadata":{"execution":{"iopub.status.busy":"2022-11-17T16:13:02.415937Z","iopub.execute_input":"2022-11-17T16:13:02.416278Z","iopub.status.idle":"2022-11-17T16:13:02.848098Z","shell.execute_reply.started":"2022-11-17T16:13:02.416248Z","shell.execute_reply":"2022-11-17T16:13:02.846176Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = dd.from_pandas(df, npartitions=10)\n","metadata":{"execution":{"iopub.status.busy":"2022-11-15T13:47:12.779328Z","iopub.execute_input":"2022-11-15T13:47:12.779877Z","iopub.status.idle":"2022-11-15T13:47:13.597646Z","shell.execute_reply.started":"2022-11-15T13:47:12.779841Z","shell.execute_reply":"2022-11-15T13:47:13.596394Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test=dd.from_pandas(df_test,npartitions=10)","metadata":{"execution":{"iopub.status.busy":"2022-11-15T13:47:13.599104Z","iopub.execute_input":"2022-11-15T13:47:13.599967Z","iopub.status.idle":"2022-11-15T13:47:13.83277Z","shell.execute_reply.started":"2022-11-15T13:47:13.599929Z","shell.execute_reply":"2022-11-15T13:47:13.831512Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data = tc.SFrame(df)\ntest_data = tc.SFrame(df_test)","metadata":{"execution":{"iopub.status.busy":"2022-11-17T16:13:02.849889Z","iopub.execute_input":"2022-11-17T16:13:02.850388Z","iopub.status.idle":"2022-11-17T16:13:14.325122Z","shell.execute_reply.started":"2022-11-17T16:13:02.850339Z","shell.execute_reply":"2022-11-17T16:13:14.323844Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.head()","metadata":{"execution":{"iopub.status.busy":"2022-11-17T16:13:14.326751Z","iopub.execute_input":"2022-11-17T16:13:14.327881Z","iopub.status.idle":"2022-11-17T16:13:14.348606Z","shell.execute_reply.started":"2022-11-17T16:13:14.32783Z","shell.execute_reply":"2022-11-17T16:13:14.347301Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data.head()","metadata":{"execution":{"iopub.status.busy":"2022-11-17T16:13:14.349887Z","iopub.execute_input":"2022-11-17T16:13:14.350278Z","iopub.status.idle":"2022-11-17T16:13:14.370499Z","shell.execute_reply.started":"2022-11-17T16:13:14.350248Z","shell.execute_reply":"2022-11-17T16:13:14.369127Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sessions=pd.DataFrame(df['ids'].unique())\nsessions.columns=['ids']","metadata":{"execution":{"iopub.status.busy":"2022-11-17T16:13:14.372181Z","iopub.execute_input":"2022-11-17T16:13:14.372573Z","iopub.status.idle":"2022-11-17T16:13:14.990556Z","shell.execute_reply.started":"2022-11-17T16:13:14.372541Z","shell.execute_reply":"2022-11-17T16:13:14.989241Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sess_id = 'ids'\nitem_id = 'aid'\nsess_to_recommend = list(sessions[sess_id])\nn_rec = 20","metadata":{"execution":{"iopub.status.busy":"2022-11-17T16:13:14.9917Z","iopub.execute_input":"2022-11-17T16:13:14.992059Z","iopub.status.idle":"2022-11-17T16:13:15.061074Z","shell.execute_reply.started":"2022-11-17T16:13:14.992029Z","shell.execute_reply":"2022-11-17T16:13:15.059769Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2022-11-17T16:13:15.063007Z","iopub.execute_input":"2022-11-17T16:13:15.063467Z","iopub.status.idle":"2022-11-17T16:13:15.074342Z","shell.execute_reply.started":"2022-11-17T16:13:15.063423Z","shell.execute_reply":"2022-11-17T16:13:15.073037Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"n_display=30","metadata":{"execution":{"iopub.status.busy":"2022-11-17T16:13:15.07555Z","iopub.execute_input":"2022-11-17T16:13:15.076026Z","iopub.status.idle":"2022-11-17T16:13:15.086343Z","shell.execute_reply.started":"2022-11-17T16:13:15.075989Z","shell.execute_reply":"2022-11-17T16:13:15.085007Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data=train_data.join(test_data, on={'frequency':'frequency','ids':'ids','aid':'aid'}, how='outer')","metadata":{"execution":{"iopub.status.busy":"2022-11-17T16:13:15.088408Z","iopub.execute_input":"2022-11-17T16:13:15.088882Z","iopub.status.idle":"2022-11-17T16:13:25.768348Z","shell.execute_reply.started":"2022-11-17T16:13:15.088846Z","shell.execute_reply":"2022-11-17T16:13:25.767144Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(data)","metadata":{"execution":{"iopub.status.busy":"2022-11-17T11:51:16.508891Z","iopub.execute_input":"2022-11-17T11:51:16.509172Z","iopub.status.idle":"2022-11-17T11:51:16.516546Z","shell.execute_reply.started":"2022-11-17T11:51:16.509144Z","shell.execute_reply":"2022-11-17T11:51:16.514893Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sessions=pd.DataFrame(data['ids'].unique())\nsessions.columns=['ids']\nsess_to_recommend = list(sessions[sess_id])","metadata":{"execution":{"iopub.status.busy":"2022-11-17T16:13:25.769773Z","iopub.execute_input":"2022-11-17T16:13:25.770108Z","iopub.status.idle":"2022-11-17T16:13:28.88461Z","shell.execute_reply.started":"2022-11-17T16:13:25.770075Z","shell.execute_reply":"2022-11-17T16:13:28.883147Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_1 = tc.item_similarity_recommender.create(tc.SFrame(data), \n                                            user_id=sess_id, \n                                            item_id=item_id, \n                                            target='frequency', similarity_type='cosine')\nrecom = model_1.recommend(users=sess_to_recommend, k=n_rec)\nrecom.print_rows(n_display)","metadata":{"execution":{"iopub.status.busy":"2022-11-16T10:10:55.444982Z","iopub.execute_input":"2022-11-16T10:10:55.44532Z","iopub.status.idle":"2022-11-16T11:23:42.248481Z","shell.execute_reply.started":"2022-11-16T10:10:55.445283Z","shell.execute_reply":"2022-11-16T11:23:42.246887Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_2 = tc.item_similarity_recommender.create(tc.SFrame(data), \n                                            user_id=sess_id, \n                                            item_id=item_id, \n                                            target='frequency', similarity_type='pearson')\nrecom = model_2.recommend(users=sess_to_recommend, k=n_rec)\nrecom.print_rows(n_display)","metadata":{"execution":{"iopub.status.busy":"2022-11-17T11:51:18.748381Z","iopub.execute_input":"2022-11-17T11:51:18.748754Z","iopub.status.idle":"2022-11-17T13:35:25.59988Z","shell.execute_reply.started":"2022-11-17T11:51:18.748722Z","shell.execute_reply":"2022-11-17T13:35:25.595421Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_3 = tc.item_similarity_recommender.create(tc.SFrame(data), \n                                            user_id=sess_id, \n                                            item_id=item_id, \n                                            target='frequency', similarity_type='jaccard')\nrecom = model_3.recommend(users=sess_to_recommend, k=n_rec)\nrecom.print_rows(n_display)","metadata":{"execution":{"iopub.status.busy":"2022-11-17T16:19:42.143929Z","iopub.execute_input":"2022-11-17T16:19:42.146805Z","iopub.status.idle":"2022-11-17T17:32:05.708244Z","shell.execute_reply.started":"2022-11-17T16:19:42.146712Z","shell.execute_reply":"2022-11-17T17:32:05.70651Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import re\nr=re.compile(\"([0-9]+)([a-zA-Z]+)\")","metadata":{"execution":{"iopub.status.busy":"2022-11-17T17:32:05.710833Z","iopub.execute_input":"2022-11-17T17:32:05.71122Z","iopub.status.idle":"2022-11-17T17:32:05.718656Z","shell.execute_reply.started":"2022-11-17T17:32:05.711184Z","shell.execute_reply":"2022-11-17T17:32:05.717307Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def create_output(model, sess_to_recommend, n_rec, print_csv=True):\n    recomendation = model.recommend(users=sess_to_recommend, k=n_rec)\n    df_rec = recomendation.to_dataframe()\n    df_rec['labels'] = df_rec.groupby([sess_id])[item_id] \\\n        .transform(lambda x: ' '.join(x.astype(str)))\n    df_rec['ids']=df_rec['ids'].apply(lambda x: str(r.match(x).group(1))+'_'+r.match(x).group(2))\n    df_output = df_rec[['ids', 'labels']].drop_duplicates() \\\n        .sort_values('ids').set_index('ids')\n    if print_csv:\n        df_output.to_csv('recommendation.csv')\n        print(\"An output file can be found in 'output' folder with name 'option1_recommendation.csv'\")\n    \n    return df_output","metadata":{"execution":{"iopub.status.busy":"2022-11-17T17:32:05.720153Z","iopub.execute_input":"2022-11-17T17:32:05.720604Z","iopub.status.idle":"2022-11-17T17:32:05.763906Z","shell.execute_reply.started":"2022-11-17T17:32:05.720572Z","shell.execute_reply":"2022-11-17T17:32:05.76282Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_output = create_output(model_1, sess_to_recommend, n_rec, print_csv=True)","metadata":{"execution":{"iopub.status.busy":"2022-11-16T11:23:42.277773Z","iopub.execute_input":"2022-11-16T11:23:42.278881Z","iopub.status.idle":"2022-11-16T12:39:46.986731Z","shell.execute_reply.started":"2022-11-16T11:23:42.278831Z","shell.execute_reply":"2022-11-16T12:39:46.985638Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_output_1 = create_output(model_2, sess_to_recommend, n_rec, print_csv=True)","metadata":{"execution":{"iopub.status.busy":"2022-11-17T13:35:25.640694Z","iopub.execute_input":"2022-11-17T13:35:25.641111Z","iopub.status.idle":"2022-11-17T15:26:50.781849Z","shell.execute_reply.started":"2022-11-17T13:35:25.641074Z","shell.execute_reply":"2022-11-17T15:26:50.780037Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_output_2 = create_output(model_3, sess_to_recommend, n_rec, print_csv=True)","metadata":{"execution":{"iopub.status.busy":"2022-11-17T18:47:38.898621Z","iopub.execute_input":"2022-11-17T18:47:38.899736Z","iopub.status.idle":"2022-11-17T20:06:06.345152Z","shell.execute_reply.started":"2022-11-17T18:47:38.899669Z","shell.execute_reply":"2022-11-17T20:06:06.343483Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(df_output.shape)\ndf_output.head(20)","metadata":{"execution":{"iopub.status.busy":"2022-11-16T12:39:46.988059Z","iopub.execute_input":"2022-11-16T12:39:46.989289Z","iopub.status.idle":"2022-11-16T12:39:47.007608Z","shell.execute_reply.started":"2022-11-16T12:39:46.989236Z","shell.execute_reply":"2022-11-16T12:39:47.006223Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(df_output_1.shape)\ndf_output_1.head(20)","metadata":{"execution":{"iopub.status.busy":"2022-11-17T15:26:50.783775Z","iopub.execute_input":"2022-11-17T15:26:50.784181Z","iopub.status.idle":"2022-11-17T15:26:50.796856Z","shell.execute_reply.started":"2022-11-17T15:26:50.784146Z","shell.execute_reply":"2022-11-17T15:26:50.795465Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample=pd.read_csv(k[1])","metadata":{"execution":{"iopub.status.busy":"2022-11-18T07:18:28.90471Z","iopub.execute_input":"2022-11-18T07:18:28.905152Z","iopub.status.idle":"2022-11-18T07:18:35.091022Z","shell.execute_reply.started":"2022-11-18T07:18:28.905115Z","shell.execute_reply":"2022-11-18T07:18:35.089859Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(sample)","metadata":{"execution":{"iopub.status.busy":"2022-11-18T07:18:35.093119Z","iopub.execute_input":"2022-11-18T07:18:35.093594Z","iopub.status.idle":"2022-11-18T07:18:35.101592Z","shell.execute_reply.started":"2022-11-18T07:18:35.09355Z","shell.execute_reply":"2022-11-18T07:18:35.1005Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"samples=list(sample['session_type'])","metadata":{"execution":{"iopub.status.busy":"2022-11-17T20:37:29.659312Z","iopub.execute_input":"2022-11-17T20:37:29.659871Z","iopub.status.idle":"2022-11-17T20:37:30.223038Z","shell.execute_reply.started":"2022-11-17T20:37:29.659817Z","shell.execute_reply":"2022-11-17T20:37:30.221459Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2022-11-16T12:59:58.563358Z","iopub.execute_input":"2022-11-16T12:59:58.563841Z","iopub.status.idle":"2022-11-16T12:59:58.57312Z","shell.execute_reply.started":"2022-11-16T12:59:58.563803Z","shell.execute_reply":"2022-11-16T12:59:58.571848Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tqdm import tqdm\nlabel=[]","metadata":{"execution":{"iopub.status.busy":"2022-11-17T20:06:13.78981Z","iopub.execute_input":"2022-11-17T20:06:13.790281Z","iopub.status.idle":"2022-11-17T20:06:13.800882Z","shell.execute_reply.started":"2022-11-17T20:06:13.790238Z","shell.execute_reply":"2022-11-17T20:06:13.799518Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i,j in tqdm(enumerate(samples)):\n    try:\n        label.append(df_output.loc[[j]].values[0])\n    except:\n        label.append(label[i-1])","metadata":{"execution":{"iopub.status.busy":"2022-11-16T13:53:37.822368Z","iopub.execute_input":"2022-11-16T13:53:37.822845Z","iopub.status.idle":"2022-11-16T14:25:31.771523Z","shell.execute_reply.started":"2022-11-16T13:53:37.822805Z","shell.execute_reply":"2022-11-16T14:25:31.769955Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample['labels']=label","metadata":{"execution":{"iopub.status.busy":"2022-11-17T20:37:49.416081Z","iopub.execute_input":"2022-11-17T20:37:49.416591Z","iopub.status.idle":"2022-11-17T20:37:50.201512Z","shell.execute_reply.started":"2022-11-17T20:37:49.416549Z","shell.execute_reply":"2022-11-17T20:37:50.200227Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample.to_csv('recommendations_2.csv',index=False)","metadata":{"execution":{"iopub.status.busy":"2022-11-17T20:37:55.580399Z","iopub.execute_input":"2022-11-17T20:37:55.581213Z","iopub.status.idle":"2022-11-17T20:39:58.661461Z","shell.execute_reply.started":"2022-11-17T20:37:55.58116Z","shell.execute_reply":"2022-11-17T20:39:58.660092Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"label=[]\nfor i,j in tqdm(enumerate(samples)):\n    try:\n        label.append(df_output_1.loc[[j]].values[0])\n    except:\n        label.append(label[i-1])","metadata":{"execution":{"iopub.status.busy":"2022-11-17T15:26:57.048112Z","iopub.execute_input":"2022-11-17T15:26:57.048677Z","iopub.status.idle":"2022-11-17T15:53:10.004444Z","shell.execute_reply.started":"2022-11-17T15:26:57.048635Z","shell.execute_reply":"2022-11-17T15:53:10.003478Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i,j in tqdm(enumerate(samples)):\n    try:\n        label.append(df_output_2.loc[[j]].values[0])\n    except:\n        label.append(label[i-1])","metadata":{"execution":{"iopub.status.busy":"2022-11-17T20:06:13.80307Z","iopub.execute_input":"2022-11-17T20:06:13.804045Z","iopub.status.idle":"2022-11-17T20:37:24.500207Z","shell.execute_reply.started":"2022-11-17T20:06:13.80399Z","shell.execute_reply":"2022-11-17T20:37:24.498862Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}