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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.