March 2018
Intermediate to advanced
320 pages
7h 53m
English
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, ...Read now
Unlock full access