Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 54 lines (44 sloc) 1.743 kB
3469095 @mperham Implement recursive odds calculation
authored
1 require 'helper'
2
3 class TestTraining < Test::Unit::TestCase
4
5 should "handle basic training" do
6 c = BayesMotel::Corpus.new('test')
7 c.train({ :something => 'foo' }, :ham)
8 c.train({ :something => 'foo' }, :spam)
9
8ebffba @mperham Add classify method, api tweaks
authored
10 results = c.score({ :something => 'foo' })
3469095 @mperham Implement recursive odds calculation
authored
11 assert results
12 assert_equal 2, results.size
13 assert_equal results[:spam], results[:ham]
14 end
15
16 should "not care about extra variables" do
17 c = BayesMotel::Corpus.new('test')
18 c.train({ :something => 'foo' }, :ham)
19 c.train({ :something => 'foo', :fubwhiz => 'oh noes' }, :spam)
20
8ebffba @mperham Add classify method, api tweaks
authored
21 results = c.score({ :something => 'foo' })
3469095 @mperham Implement recursive odds calculation
authored
22 assert results
23 assert_equal 2, results.size
24 assert_equal results[:spam], results[:ham]
25 end
26
27 should "give more weight with more appearances" do
28 c = BayesMotel::Corpus.new('test')
29 c.train({ :something => 'foo' }, :ham)
30 c.train({ :something => 'foo' }, :spam)
31 c.train({ :something => 'foo', :fubwhiz => 'oh noes' }, :spam)
32
8ebffba @mperham Add classify method, api tweaks
authored
33 doc = { :something => 'foo' }
34 results = c.score(doc)
3469095 @mperham Implement recursive odds calculation
authored
35 assert results
36 assert_equal 2, results.size
37 assert_equal results[:spam], 2*results[:ham]
8ebffba @mperham Add classify method, api tweaks
authored
38 assert_equal [:spam, 2.0/3], c.classify(doc)
3469095 @mperham Implement recursive odds calculation
authored
39 end
40
8ebffba @mperham Add classify method, api tweaks
authored
41 should "calculate score for nested documents" do
3469095 @mperham Implement recursive odds calculation
authored
42 c = BayesMotel::Corpus.new('test')
43 c.train({ :something => 'foo', :kids => { :bar => 'whiz', :id => 123 } }, :ham)
44 c.train({ :something => 'foo', :kids => { :bar => 'gee', :id => 145 } }, :spam)
45
8ebffba @mperham Add classify method, api tweaks
authored
46 doc = { :something => 'foo', :kids => { :bar => 'gee', :id => 167, :ack => 'blag' }}
47 results = c.score(doc)
3469095 @mperham Implement recursive odds calculation
authored
48 assert results
49 assert_equal 2, results.size
50 assert_equal results[:spam], 2*results[:ham]
8ebffba @mperham Add classify method, api tweaks
authored
51
52 assert_equal [:spam, 1.0], c.classify(doc)
3469095 @mperham Implement recursive odds calculation
authored
53 end
54 end
Something went wrong with that request. Please try again.