Classifier part II

One of the main considerations is that a Naive Bayes classifier is a very simple program, and very difficult to get wrong. The entire program is in fact fewer than 100 lines. Let's look at it further.

We have sketched out so far the method Train, which will train the classifier on a given set of inputs. Here's how it looks:

func (c *Classifier) Train(examples []Example) {  for _, ex := range examples {    c.trainOne(ex)  }}func (c *Classifier) trainOne(example Example) {  d := make(doc, len(example.Document))  for i, word := range example.Document {    id := c.corpus.Add(word)    d[i] = id  }  c.tfidfs[example.Class].Add(d)  c.totals[example.Class]++}

So here it's very clear that Train is an  operation. But the function is structured in ...

Get Go Machine Learning Projects now with O’Reilly online learning.

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