<jupyter_start><jupyter_text>Load Data  Mapping Index<jupyter_code>path = '../data/processed'
infile = open(os.path.join(path,'index_to_cusId.pkl'),'rb')
index_to_id_dict = pickle.load(infile)
infile.close()<jupyter_output><empty_output><jupyter_text>Transaction<jupyter_code>path = '../data/processed'
trans = pd.read_pickle(os.path.join(path,'transactions.pkl'))
trans["customer_id"] = trans["customer_id"].map(index_to_id_dict)
trans.head()
# customers
path = '../data/processed'
customers = pd.read_pickle(os.path.join(path,'customers.pkl'))
customers["customer_id"] = customers["customer_id"].map(index_to_id_dict)
customers.head(2)<jupyter_output><empty_output><jupyter_text>Top L1M<jupyter_code># start_dt =  datetime.datetime(2020,9,15)
end_dt =  datetime.datetime(2020,9,15)
start_dt = end_dt - timedelta(30)



temp_tran = trans[(trans.t_dat > start_dt) & (trans.t_dat <= end_dt)]
print('Min date: ', temp_tran.t_dat.min())
print('Max date: ', temp_tran.t_dat.max())
print(f'Total Customers: {temp_tran.customer_id.nunique()}')

top_l1m = pd.DataFrame(temp_tran.groupby(['article_id']).agg({'customer_id':'nunique'})\
                        .rename(columns={'customer_id':'total_customers'})\
                        .sort_values(by=['total_customers'],ascending=False)\
                        .reset_index()
                      )
top_l1m_list = list(top_l1m.iloc[:12]['article_id'])
top_l1m_list = ' '.join(top_l1m_list)
final_df = customers[["customer_id"]]
final_df['prediction'] = top_l1m_list

final_df.head()
final_df.to_csv(os.path.join(path,'top_l1m.csv'),index=False)<jupyter_output><empty_output><jupyter_text>Top L6Y<jupyter_code># start_dt =  datetime.datetime(2020,9,15)
end_dt =  datetime.datetime(2020,9,15)
start_dt = end_dt - timedelta(180)



temp_tran = trans[(trans.t_dat > start_dt) & (trans.t_dat <= end_dt)]
print('Min date: ', temp_tran.t_dat.min())
print('Max date: ', temp_tran.t_dat.max())
print(f'Total Customers: {temp_tran.customer_id.nunique()}')

top_l6m = pd.DataFrame(temp_tran.groupby(['article_id']).agg({'customer_id':'nunique'})\
                        .rename(columns={'customer_id':'total_customers'})\
                        .sort_values(by=['total_customers'],ascending=False)\
                        .reset_index()
                      )
top_l6m_list = list(top_l6m.iloc[:12]['article_id'])
top_l6m_list = ' '.join(top_l6m_list)
final_df = customers[["customer_id"]]
final_df['prediction'] = top_l6m_list

final_df.head()
final_df.to_csv(os.path.join(path,'top_l6m.csv'),index=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17055167055167056, 'fraction_numerical': 0.02097902097902098, 'mean_word_length': 5.016355140186916, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '354586', 'license': 'Apache-2.0', 'n_tokens_mistral': 1027, 'n_tokens_neox': 983, 'n_words': 98, 'path': 'model/.ipynb_checkpoints/5.Basic Model-checkpoint.ipynb', 'repo_name': 'mewprakarn/Product_Personalization_Project', 'size': '2574'}