The classifier

Before we continue to build our classifier, let's imagine what the main function will look as follows. It will look something similar to this:

unc main() {
examples, err := ingest("bare")
log.Printf("Examples loaded: %d, Errors: %v", len(examples), err)
shuffle(examples)

if len(examples) == 0 {
log.Fatal("Cannot proceed: no training examples")
}

// create new classifier
c := New()

// train new classifier
c.Train(examples)

// predict
predicted := c.Predict(aDocument)
fmt.Printf("Predicted %v", predicted)
}

The use of Train and Predict as exported methods are useful in guiding us on what to build next. From the sketch in the preceding code block, we need a Classifier type, that has Train and Predict at the very least. So we'll start by doing that:

type Classifier {}

func (c *Classifier) Train(examples []Example) {}

func (c *Classifier) Predict(document []string) Class { ... }

So, now, it becomes a question of how the classifier works.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.212.217