text_plain_output_1.png
from scipy.sparse import coo_matrix

import numpy as np

transactions = transactions[transactions['t_dat'] > '2020-09-14']
transactions.shape

all_customers = customers['customer_id'].unique().tolist()
all_articles = articles['article_id'].unique().tolist()
customer_ids = dict(list(enumerate(all_customers)))
article_ids = dict(list(enumerate(all_articles)))
transactions['customer_id'] = transactions['customer_id'].map({u: uidx for uidx, u in customer_ids.items()})
transactions['article_id'] = transactions['article_id'].map({i: iidx for iidx, i in article_ids.items()})
del customers, articles

row = transactions['customer_id'].values
col = transactions['article_id'].values
data = np.ones(transactions.shape[0])
coo_train = coo_matrix((data, (row, col)), shape=(len(all_customers), len(all_articles)))
coo_train