Skip to content

Commit

Permalink
Changed method name to LogScores.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrukh committed Dec 2, 2011
1 parent 4b26ba4 commit 11bfb37
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ and train it:
Then you can ascertain the scores of each class and
the most likely class your data belongs to:

scores, likely, _ := classifier.Score(
scores, likely, _ := classifier.LogScores(
[]string{"tall", "girl"}
)

Expand Down
2 changes: 1 addition & 1 deletion bayesian.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func (c *Classifier) Learn(words []string, which Class) {
// is classifier.Classes[inx]. If more than one of the
// returned probabilities has the maximum values, then
// strict is false.
func (c *Classifier) Scores(words []string) (scores []float64, inx int, strict bool) {
func (c *Classifier) LogScores(words []string) (scores []float64, inx int, strict bool) {
n := len(c.Classes)
scores = make([]float64, n, n)
priors := c.getPriors()
Expand Down
6 changes: 3 additions & 3 deletions bayesian_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ func TestLearn(t *testing.T) {
c.Learn([]string{"tall", "handsome", "rich"}, Good)
c.Learn([]string{"bald", "poor", "ugly"}, Bad)

score, likely, strict := c.Scores([]string{"the", "tall", "man"})
score, likely, strict := c.LogScores([]string{"the", "tall", "man"})
fmt.Printf("%v\n", score)
Assert(t, score[0]>score[1], "not good, round 1") // this is good
Assert(t, likely == 0, "not good, round 1")
Assert(t, strict == true, "not strict, round 1")

score, likely, strict = c.Scores([]string{"poor", "ugly", "girl"})
score, likely, strict = c.LogScores([]string{"poor", "ugly", "girl"})
fmt.Printf("%v\n", score)
Assert(t, score[0]<score[1]) // this is bad
Assert(t, likely == 1)
Assert(t, strict == true)

score, likely, strict = c.Scores([]string{"the", "bad", "man"})
score, likely, strict = c.LogScores([]string{"the", "bad", "man"})
fmt.Printf("%v\n", score)
Assert(t, score[0]==score[1], "not the same") // same
Assert(t, likely == 0, "not good") // first one is picked
Expand Down

0 comments on commit 11bfb37

Please sign in to comment.