Alternative class design

Here, we imagine an alternative design of Class:

type Class stringconst (  Ham Class = "Ham"  Spam Class = "Spam")

With this change, we will have to update the definition of Classifier:

type Classifier struct {  corpus *corpus.Corpus  tfidfs map[Class]*tfidf.TFIDF  totals map[Class]float64  ready bool  sync.Mutex}

Consider now the steps required to get the totals of class Ham:

  1. The string has to be hashed
  2. The hash will be used to look up the bucket where the data for totals is stored
  3. An indirection is made to the bucket and the data is retrieved and returned to the user

Consider now the steps required to get the totals of class Ham if the class design was the original:

  • Since Ham is a number, we can directly compute the ...

Get Go Machine 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.