Data preparation and baseline

Like previously, we need to represent the items and users as integers. This time, however, we need to have a special placeholder value for unknown users. Additionally, we need a special placeholder for items to represent "no item" at the beginning of each transaction. We will talk more about it later in this section, but for now, we need to implement the encoding such that the 0 index is reserved for special purposes.

Previously we were using a dictionary, but this time let us implement a special class, LabelEncoder, for this purpose:

class LabelEncoder:    def fit(self, seq):        self.vocab = sorted(set(seq))        self.idx = {c: i + 1 for i, c in enumerate(self.vocab)}    def transform(self, seq):        n = len(seq) result = np.zeros(n, ...

Get TensorFlow Deep Learning Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.