fea_dict[idx] = dataset_iris[0][idx] return npd, fea_dict data_all, fea_dict = generate_sample_dataset_and_feature_dict(dataset_iris) from sklearn.model_selection import train_test_split data_train, data_test = train_test_split(data_all) print(len(data_train), len(data_test)) # create dataset instance from structured ndarray data import recsys.dataset as dataset dataset = imp.reload(dataset) train_dataset = dataset.Dataset(data_train, total_users=1, total_items=len(fea_dict), implicit_negative=False, name='Train') test_dataset = dataset.Dataset(data_test, total_users=1, total_items=len(fea_dict), implicit_negative=False, name='Test') # create featurizer for mapping: (user, item) -> vector import recsys.featurizers.plain_featurizer as plain_featurizer plain_featurizer = imp.reload(plain_featurizer) class Featurizer(plain_featurizer.PlainFeaturizer): """
import recsys.dataset as dataset train_data = np.load('lastfm_train.npy') test_data = np.load('lastfm_test.npy') total_users = max( set(list(train_data['user_id']) + list(test_data['user_id']))) + 1 total_items = max( set(list(train_data['item_id']) + list(test_data['item_id']))) + 1 print(total_users, total_items) train_data[:2], test_data[:2] # datasets import recsys.dataset as dataset dataset = imp.reload(dataset) train_dataset = dataset.Dataset(train_data, total_users, total_items, sortby='ts', name='Train') test_dataset = dataset.Dataset(test_data, total_users, total_items, sortby='ts', name='Test') # hyperparamerters dim_item_embed = 50 # dimension of item embedding max_seq_len = 100 # the maxium length of user's listen history num_units = 32 # Number of units in the RNN model total_iter = int(1e3) # iterations for training batch_size = 100 # training batch size eval_iter = 200 # iteration of evaluation