Example #1
0
interactions = train[['user', 'item', 'rating']].values

n_users = np.unique(train[["user"]].values).shape[0]
n_items = np.unique(train[["item"]].values).shape[0]

print("Number of users: %s" % n_users)
print("Number of items: %s" % n_items)
logger = TLogger()

model = MF_SeqRank(n_iter=10,
                   n_jobs=8,
                   n_factors=10,
                   learning_rate=1,
                   logger=logger)

x = interactions[:, :-1]
y = interactions[:, -1]

model.fit(x, y, n_users=n_users, n_items=n_items)

plt.plot(logger.epochs, logger.losses)
plt.show()
users = np.unique(x[:, 0])
values = cartesian(users, np.unique(x[:, 1]))

table = np.zeros((users.shape[0], 6), dtype=np.int)
table[:, 0] = users
table[:, 1:] = model.predict(values, top=5)
print(table)
train = pd.merge(df, feats, on="tps_id")

n_users = df.user_id.unique().shape[0]
n_items = df.tps_id.unique().shape[0]
print("Number of users: %s" % n_users)
print("Number of items: %s" % n_items)
n_artists = feats.artist_id.unique().shape[0]
interactions = train[['user_id', 'tps_id', 'playcounts']].values

logger = TLogger()
model = MF_MMR(n_iter=1,
               learning_rate=1e-1,
               logger=logger,
               n_jobs=4,
               use_cuda=False)

x = interactions[:, :-1]
y = interactions[:, -1]
model.fit(x, y, n_users=n_users, n_items=n_items)
logger = TLogger()

plt.plot(logger.epochs, logger.losses)
plt.show()
users = np.unique(x[:, 0])[:10]
items = np.unique(x[:, 1])
values = cartesian(users, items)
top = 3
table = np.zeros((users.shape[0], top + 1), dtype=np.object)
table[:, 0] = users
table[:, 1:] = model.predict(values, top=top, b=1)
print(table)