naivebayes 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/VERSION +1 -1
- data/demo.rb +3 -1
- data/doc/ChangeLog +7 -0
- data/lib/naivebayes.rb +1 -1
- data/lib/naivebayes/classifier.rb +2 -0
- data/lib/naivebayes/version.rb +10 -0
- data/naivebayes.gemspec +6 -4
- data/spec/lib/naivebayes/classifier_spec.rb +327 -86
- data/spec/lib/naivebayes_spec.rb +4 -6
- metadata +14 -21
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6bbec8539369ff2f707fd59440b444cbd2a71e9f
|
4
|
+
data.tar.gz: 8b0fa15a8dec7d4e314c60cff086074f48f37115
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a3210aff3d52771134877dd65b4a9cf524dfd6a754f523eb708b85da4e651e00435b97be6fcca66e63fb2aa37313706012eab99405e940f2d20cd316e8ec43cc
|
7
|
+
data.tar.gz: d25b10280650406e9e33566641d9c5c9846a59a2fd81f8da9d38d147774174d348e2a43624946154b962c6b6aa98bade8aaebd2c35fcafb3cc54f4f6c075139f
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/demo.rb
CHANGED
data/doc/ChangeLog
CHANGED
data/lib/naivebayes.rb
CHANGED
@@ -0,0 +1,10 @@
|
|
1
|
+
# Name:: NaiveBayes::Version
|
2
|
+
# Author:: 774 <http://id774.net>
|
3
|
+
# Created:: Nov 24, 2013
|
4
|
+
# Updated:: Dec 13, 2013
|
5
|
+
# Copyright:: 774 Copyright (c) 2013
|
6
|
+
# License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0.
|
7
|
+
|
8
|
+
module NaiveBayes
|
9
|
+
VERSION = "0.0.3"
|
10
|
+
end
|
data/naivebayes.gemspec
CHANGED
@@ -2,14 +2,15 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: naivebayes 0.0.3 ruby lib
|
5
6
|
|
6
7
|
Gem::Specification.new do |s|
|
7
8
|
s.name = "naivebayes"
|
8
|
-
s.version = "0.0.
|
9
|
+
s.version = "0.0.3"
|
9
10
|
|
10
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
12
|
s.authors = ["id774"]
|
12
|
-
s.date = "2013-
|
13
|
+
s.date = "2013-12-13"
|
13
14
|
s.description = "Naive Bayes classifier"
|
14
15
|
s.email = "idnanashi@gmail.com"
|
15
16
|
s.extra_rdoc_files = [
|
@@ -29,6 +30,7 @@ Gem::Specification.new do |s|
|
|
29
30
|
"doc/README",
|
30
31
|
"lib/naivebayes.rb",
|
31
32
|
"lib/naivebayes/classifier.rb",
|
33
|
+
"lib/naivebayes/version.rb",
|
32
34
|
"naivebayes.gemspec",
|
33
35
|
"script/build",
|
34
36
|
"spec/lib/naivebayes/classifier_spec.rb",
|
@@ -39,11 +41,11 @@ Gem::Specification.new do |s|
|
|
39
41
|
s.homepage = "http://github.com/id774/naivebayes"
|
40
42
|
s.licenses = ["GPL"]
|
41
43
|
s.require_paths = ["lib"]
|
42
|
-
s.rubygems_version = "1.
|
44
|
+
s.rubygems_version = "2.1.11"
|
43
45
|
s.summary = "naivebayes"
|
44
46
|
|
45
47
|
if s.respond_to? :specification_version then
|
46
|
-
s.specification_version =
|
48
|
+
s.specification_version = 4
|
47
49
|
|
48
50
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
49
51
|
s.add_development_dependency(%q<cucumber>, [">= 0"])
|
@@ -3,158 +3,399 @@
|
|
3
3
|
|
4
4
|
require File.dirname(__FILE__) + '/../../spec_helper'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
describe NaiveBayes::Classifier do
|
7
|
+
describe '#initialize' do
|
8
|
+
context '@frequency_table with berounoulli model' do
|
9
|
+
subject { classifier.frequency_table }
|
10
|
+
|
11
|
+
let(:classifier) { NaiveBayes::Classifier.new(:model => "berounoulli") }
|
12
|
+
|
13
|
+
it 'should return frequency table' do
|
14
|
+
classifier.train("positive", {"aaa" => 0, "bbb" => 1})
|
15
|
+
classifier.train("negative", {"ccc" => 2, "ddd" => 3})
|
16
|
+
classifier.train("positive", {"aaa" => 1, "bbb" => 2})
|
17
|
+
classifier.train("negative", {"ccc" => 3, "ddd" => 4})
|
18
|
+
|
19
|
+
expected = {
|
20
|
+
"positive" => {"aaa" => 2, "bbb" => 2},
|
21
|
+
"negative" => {"ccc" => 2, "ddd" => 2}
|
22
|
+
}
|
23
|
+
|
24
|
+
expect(subject).to eq expected
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context '@frequency_table with multinomial model' do
|
29
|
+
subject { classifier.frequency_table }
|
30
|
+
|
31
|
+
let(:classifier) { NaiveBayes::Classifier.new(:model => "multinomial") }
|
32
|
+
|
33
|
+
it 'should return frequency table' do
|
34
|
+
classifier.train("positive", {"aaa" => 0, "bbb" => 1})
|
35
|
+
classifier.train("negative", {"ccc" => 2, "ddd" => 3})
|
36
|
+
classifier.train("positive", {"aaa" => 1, "bbb" => 2})
|
37
|
+
classifier.train("negative", {"ccc" => 3, "ddd" => 4})
|
38
|
+
|
39
|
+
expected = {
|
40
|
+
"positive" => {"aaa" => 1, "bbb" => 3},
|
41
|
+
"negative" => {"ccc" => 5, "ddd" => 7}
|
42
|
+
}
|
43
|
+
|
44
|
+
expect(subject).to eq expected
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context '@word_table with berounoulli model' do
|
49
|
+
subject { classifier.word_table }
|
50
|
+
|
51
|
+
let(:classifier) { NaiveBayes::Classifier.new(:model => "berounoulli") }
|
52
|
+
|
53
|
+
it 'should return word table' do
|
54
|
+
classifier.train("positive", {"aaa" => 0, "bbb" => 1})
|
55
|
+
classifier.train("negative", {"ccc" => 2, "ddd" => 3})
|
56
|
+
classifier.train("positive", {"aaa" => 1, "bbb" => 2})
|
57
|
+
classifier.train("negative", {"ccc" => 3, "ddd" => 4})
|
58
|
+
|
59
|
+
expected = {
|
60
|
+
"aaa" => 1, "bbb" => 1,
|
61
|
+
"ccc" => 1, "ddd" => 1
|
62
|
+
}
|
63
|
+
|
64
|
+
expect(subject).to eq expected
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context '@word_table with multinomial model' do
|
69
|
+
subject { classifier.word_table }
|
70
|
+
|
71
|
+
let(:classifier) { NaiveBayes::Classifier.new(:model => "multinomial") }
|
72
|
+
|
73
|
+
it 'should return word table' do
|
74
|
+
classifier.train("positive", {"aaa" => 0, "bbb" => 1})
|
75
|
+
classifier.train("negative", {"ccc" => 2, "ddd" => 3})
|
76
|
+
classifier.train("positive", {"aaa" => 1, "bbb" => 2})
|
77
|
+
classifier.train("negative", {"ccc" => 3, "ddd" => 4})
|
78
|
+
|
79
|
+
expected = {
|
80
|
+
"aaa" => 1, "bbb" => 1,
|
81
|
+
"ccc" => 1, "ddd" => 1
|
82
|
+
}
|
83
|
+
|
84
|
+
expect(subject).to eq expected
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context '@instance_count_of with berounoulli model' do
|
89
|
+
subject { classifier.instance_count_of }
|
90
|
+
|
91
|
+
let(:classifier) { NaiveBayes::Classifier.new(:model => "berounoulli") }
|
92
|
+
|
93
|
+
it 'should return instance_count_of' do
|
94
|
+
classifier.train("positive", {"aaa" => 0, "bbb" => 1})
|
95
|
+
classifier.train("negative", {"ccc" => 2, "ddd" => 3})
|
96
|
+
classifier.train("positive", {"aaa" => 1, "bbb" => 2})
|
97
|
+
classifier.train("negative", {"ccc" => 3, "ddd" => 4})
|
98
|
+
|
99
|
+
expected = {
|
100
|
+
"positive" => 2,
|
101
|
+
"negative" => 2
|
102
|
+
}
|
103
|
+
|
104
|
+
expect(subject).to eq expected
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context '@instance_count_of with multinomial model' do
|
109
|
+
subject { classifier.instance_count_of }
|
110
|
+
|
111
|
+
let(:classifier) { NaiveBayes::Classifier.new(:model => "multinomial") }
|
112
|
+
|
113
|
+
it 'should return instance_count_of' do
|
114
|
+
classifier.train("positive", {"aaa" => 0, "bbb" => 1})
|
115
|
+
classifier.train("negative", {"ccc" => 2, "ddd" => 3})
|
116
|
+
classifier.train("positive", {"aaa" => 1, "bbb" => 2})
|
117
|
+
classifier.train("negative", {"ccc" => 3, "ddd" => 4})
|
118
|
+
|
119
|
+
expected = {
|
120
|
+
"positive" => 2,
|
121
|
+
"negative" => 2
|
122
|
+
}
|
123
|
+
|
124
|
+
expect(subject).to eq expected
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
context '@total_count with berounoulli model' do
|
129
|
+
subject { classifier.total_count }
|
130
|
+
|
131
|
+
let(:classifier) { NaiveBayes::Classifier.new(:model => "berounoulli") }
|
132
|
+
|
133
|
+
it 'should return total count' do
|
134
|
+
classifier.train("positive", {"aaa" => 0, "bbb" => 1})
|
135
|
+
classifier.train("negative", {"ccc" => 2, "ddd" => 3})
|
136
|
+
classifier.train("positive", {"aaa" => 1, "bbb" => 2})
|
137
|
+
classifier.train("negative", {"ccc" => 3, "ddd" => 4})
|
138
|
+
|
139
|
+
expected = 4
|
140
|
+
|
141
|
+
expect(subject).to eq expected
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context '@total_count with multinomial model' do
|
146
|
+
subject { classifier.total_count }
|
147
|
+
|
148
|
+
let(:classifier) { NaiveBayes::Classifier.new(:model => "multinomial") }
|
149
|
+
|
150
|
+
it 'should return total count' do
|
151
|
+
classifier.train("positive", {"aaa" => 0, "bbb" => 1})
|
152
|
+
classifier.train("negative", {"ccc" => 2, "ddd" => 3})
|
153
|
+
classifier.train("positive", {"aaa" => 1, "bbb" => 2})
|
154
|
+
classifier.train("negative", {"ccc" => 3, "ddd" => 4})
|
155
|
+
|
156
|
+
expected = 4
|
157
|
+
|
158
|
+
expect(subject).to eq expected
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
context '@model with berounoulli model' do
|
163
|
+
subject { classifier.model }
|
164
|
+
|
165
|
+
let(:classifier) { NaiveBayes::Classifier.new(:model => "berounoulli") }
|
10
166
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
167
|
+
it 'should return model name' do
|
168
|
+
expected = "berounoulli"
|
169
|
+
expect(subject).to eq expected
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
context '@model with multinomial model' do
|
174
|
+
subject { classifier.model }
|
175
|
+
|
176
|
+
let(:classifier) { NaiveBayes::Classifier.new(:model => "multinomial") }
|
177
|
+
|
178
|
+
it 'should return model name' do
|
179
|
+
expected = "multinomial"
|
180
|
+
expect(subject).to eq expected
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
15
184
|
end
|
16
185
|
|
17
|
-
describe NaiveBayes::Classifier
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
186
|
+
describe NaiveBayes::Classifier do
|
187
|
+
describe 'The berounoulli model' do
|
188
|
+
context 'with train data of two expecting positive' do
|
189
|
+
|
190
|
+
subject { classifier.classify({"aaa" => 1, "bbb" => 1}) }
|
191
|
+
|
192
|
+
let(:classifier) { NaiveBayes::Classifier.new(:model => "berounoulli") }
|
193
|
+
|
194
|
+
it 'should return positive' do
|
195
|
+
classifier.train("positive", {"aaa" => 0, "bbb" => 1})
|
196
|
+
classifier.train("negative", {"ccc" => 2, "ddd" => 3})
|
197
|
+
|
198
|
+
expected = {
|
24
199
|
"positive" => 0.8767123287671234,
|
25
200
|
"negative" => 0.12328767123287669
|
26
201
|
}
|
27
|
-
|
28
|
-
|
202
|
+
|
203
|
+
expect(subject).to eq expected
|
29
204
|
end
|
30
205
|
end
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
206
|
+
|
207
|
+
context 'with train data of two expecting negative' do
|
208
|
+
|
209
|
+
subject { classifier.classify({"ccc" => 3, "ddd" => 3}) }
|
210
|
+
|
211
|
+
let(:classifier) { NaiveBayes::Classifier.new(:model => "berounoulli") }
|
212
|
+
|
213
|
+
it 'should return negative' do
|
214
|
+
classifier.train("positive", {"aaa" => 0, "bbb" => 1})
|
215
|
+
classifier.train("negative", {"ccc" => 2, "ddd" => 3})
|
216
|
+
|
217
|
+
expected = {
|
36
218
|
"positive" => 0.12328767123287668,
|
37
219
|
"negative" => 0.8767123287671234
|
38
220
|
}
|
39
|
-
|
40
|
-
|
221
|
+
|
222
|
+
expect(subject).to eq expected
|
41
223
|
end
|
42
224
|
end
|
43
225
|
end
|
44
226
|
end
|
45
227
|
|
46
|
-
describe NaiveBayes::Classifier
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
228
|
+
describe NaiveBayes::Classifier do
|
229
|
+
describe 'The multinomial model' do
|
230
|
+
context 'with train data of two expecting positive' do
|
231
|
+
|
232
|
+
subject { classifier.classify({"aaa" => 1, "bbb" => 1}) }
|
233
|
+
|
234
|
+
let(:classifier) { NaiveBayes::Classifier.new(:model => "multinomial") }
|
235
|
+
|
236
|
+
it 'should return positive' do
|
237
|
+
classifier.train("positive", {"aaa" => 0, "bbb" => 1})
|
238
|
+
classifier.train("negative", {"ccc" => 2, "ddd" => 3})
|
239
|
+
|
240
|
+
expected = {
|
53
241
|
"positive" => 0.9411764705882353,
|
54
242
|
"negative" => 0.05882352941176469
|
55
243
|
}
|
56
|
-
|
57
|
-
|
244
|
+
|
245
|
+
expect(subject).to eq expected
|
58
246
|
end
|
59
247
|
end
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
248
|
+
|
249
|
+
context 'with train data of two expecting negative' do
|
250
|
+
|
251
|
+
subject { classifier.classify({"ccc" => 3, "ddd" => 3}) }
|
252
|
+
|
253
|
+
let(:classifier) { NaiveBayes::Classifier.new(:model => "multinomial") }
|
254
|
+
|
255
|
+
it 'should return negative' do
|
256
|
+
classifier.train("positive", {"aaa" => 0, "bbb" => 1})
|
257
|
+
classifier.train("negative", {"ccc" => 2, "ddd" => 3})
|
258
|
+
|
259
|
+
expected = {
|
65
260
|
"positive" => 0.0588235294117647,
|
66
261
|
"negative" => 0.9411764705882353
|
67
262
|
}
|
68
|
-
|
69
|
-
|
263
|
+
|
264
|
+
expect(subject).to eq expected
|
70
265
|
end
|
71
266
|
end
|
72
267
|
end
|
73
268
|
end
|
74
269
|
|
75
|
-
describe NaiveBayes::Classifier
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
270
|
+
describe NaiveBayes::Classifier do
|
271
|
+
describe 'The berounoulli model' do
|
272
|
+
context 'with train data of three expecting positive' do
|
273
|
+
|
274
|
+
subject { classifier.classify({"aaa" => 1, "bbb" => 1}) }
|
275
|
+
|
276
|
+
let(:classifier) { NaiveBayes::Classifier.new(:model => "berounoulli") }
|
277
|
+
|
278
|
+
it 'should return positive' do
|
279
|
+
classifier.train("positive", {"aaa" => 2, "bbb" => 1})
|
280
|
+
classifier.train("negative", {"ccc" => 2, "ddd" => 2})
|
281
|
+
classifier.train("neutral", {"eee" => 3, "fff" => 3})
|
282
|
+
|
283
|
+
expected = {
|
82
284
|
"positive" => 0.7422680412371133,
|
83
285
|
"negative" => 0.12886597938144329,
|
84
286
|
"neutral" => 0.12886597938144329
|
85
287
|
}
|
86
|
-
|
87
|
-
|
288
|
+
|
289
|
+
expect(subject).to eq expected
|
88
290
|
end
|
89
291
|
end
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
292
|
+
|
293
|
+
context 'with train data of three expecting negative' do
|
294
|
+
|
295
|
+
subject { classifier.classify({"ccc" => 3, "ddd" => 2}) }
|
296
|
+
|
297
|
+
let(:classifier) { NaiveBayes::Classifier.new(:model => "berounoulli") }
|
298
|
+
|
299
|
+
it 'should return negative' do
|
300
|
+
classifier.train("positive", {"aaa" => 2, "bbb" => 1})
|
301
|
+
classifier.train("negative", {"ccc" => 2, "ddd" => 2})
|
302
|
+
classifier.train("neutral", {"eee" => 3, "fff" => 3})
|
303
|
+
|
304
|
+
expected = {
|
95
305
|
"positive" => 0.12886597938144329,
|
96
306
|
"negative" => 0.7422680412371133,
|
97
307
|
"neutral" => 0.12886597938144329
|
98
308
|
}
|
99
|
-
|
100
|
-
|
309
|
+
|
310
|
+
expect(subject).to eq expected
|
101
311
|
end
|
102
312
|
end
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
313
|
+
|
314
|
+
context 'with train data of three expecting neutral' do
|
315
|
+
|
316
|
+
subject { classifier.classify({"aaa" => 1, "ddd" => 2, "eee" => 3, "fff" => 1}) }
|
317
|
+
|
318
|
+
let(:classifier) { NaiveBayes::Classifier.new(:model => "berounoulli") }
|
319
|
+
|
320
|
+
it 'should return neutral' do
|
321
|
+
classifier.train("positive", {"aaa" => 2, "bbb" => 1})
|
322
|
+
classifier.train("negative", {"ccc" => 2, "ddd" => 2})
|
323
|
+
classifier.train("neutral", {"eee" => 3, "fff" => 3})
|
324
|
+
|
325
|
+
expected = {
|
108
326
|
"positive" => 0.2272727272727273,
|
109
327
|
"negative" => 0.22727272727272724,
|
110
328
|
"neutral" => 0.5454545454545455
|
111
329
|
}
|
112
|
-
|
113
|
-
|
330
|
+
|
331
|
+
expect(subject).to eq expected
|
114
332
|
end
|
115
333
|
end
|
116
334
|
end
|
117
335
|
end
|
118
336
|
|
119
|
-
describe NaiveBayes::Classifier
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
337
|
+
describe NaiveBayes::Classifier do
|
338
|
+
describe 'The multinomial model' do
|
339
|
+
context 'with train data of three expecting positive' do
|
340
|
+
|
341
|
+
subject { classifier.classify({"aaa" => 1, "bbb" => 1}) }
|
342
|
+
|
343
|
+
let(:classifier) { NaiveBayes::Classifier.new(:model => "multinomial") }
|
344
|
+
|
345
|
+
it 'should return positive' do
|
346
|
+
classifier.train("positive", {"aaa" => 2, "bbb" => 1})
|
347
|
+
classifier.train("negative", {"ccc" => 2, "ddd" => 2})
|
348
|
+
classifier.train("neutral", {"eee" => 3, "fff" => 3})
|
349
|
+
|
350
|
+
expected = {
|
126
351
|
"positive" => 0.896265560165975,
|
127
352
|
"negative" => 0.06639004149377592,
|
128
353
|
"neutral" => 0.03734439834024896
|
129
354
|
}
|
130
|
-
|
131
|
-
|
355
|
+
|
356
|
+
expect(subject).to eq expected
|
132
357
|
end
|
133
358
|
end
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
359
|
+
|
360
|
+
context 'with train data of three expecting negative' do
|
361
|
+
|
362
|
+
subject { classifier.classify({"ccc" => 3, "ddd" => 2}) }
|
363
|
+
|
364
|
+
let(:classifier) { NaiveBayes::Classifier.new(:model => "multinomial") }
|
365
|
+
|
366
|
+
it 'should return negative' do
|
367
|
+
classifier.train("positive", {"aaa" => 2, "bbb" => 1})
|
368
|
+
classifier.train("negative", {"ccc" => 2, "ddd" => 2})
|
369
|
+
classifier.train("neutral", {"eee" => 3, "fff" => 3})
|
370
|
+
|
371
|
+
expected = {
|
139
372
|
"positive" => 0.05665722379603399,
|
140
373
|
"negative" => 0.9178470254957508,
|
141
374
|
"neutral" => 0.0254957507082153
|
142
375
|
}
|
143
|
-
|
144
|
-
|
376
|
+
|
377
|
+
expect(subject).to eq expected
|
145
378
|
end
|
146
379
|
end
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
380
|
+
|
381
|
+
context 'with train data of three expecting neutral' do
|
382
|
+
|
383
|
+
subject { classifier.classify({"aaa" => 1, "ddd" => 2, "eee" => 3, "fff" => 1}) }
|
384
|
+
|
385
|
+
let(:classifier) { NaiveBayes::Classifier.new(:model => "multinomial") }
|
386
|
+
|
387
|
+
it 'should return neutral' do
|
388
|
+
classifier.train("positive", {"aaa" => 2, "bbb" => 1})
|
389
|
+
classifier.train("negative", {"ccc" => 2, "ddd" => 2})
|
390
|
+
classifier.train("neutral", {"eee" => 3, "fff" => 3})
|
391
|
+
|
392
|
+
expected = {
|
152
393
|
"positive" => 0.12195121951219513,
|
153
394
|
"negative" => 0.09756097560975606,
|
154
395
|
"neutral" => 0.7804878048780488
|
155
396
|
}
|
156
|
-
|
157
|
-
|
397
|
+
|
398
|
+
expect(subject).to eq expected
|
158
399
|
end
|
159
400
|
end
|
160
401
|
end
|
data/spec/lib/naivebayes_spec.rb
CHANGED
@@ -3,11 +3,9 @@
|
|
3
3
|
require File.dirname(__FILE__) + '/../spec_helper'
|
4
4
|
|
5
5
|
describe NaiveBayes do
|
6
|
-
context
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
NaiveBayes.const_get(:VERSION).should == expect
|
11
|
-
end
|
6
|
+
context "VERSION" do
|
7
|
+
subject { NaiveBayes::VERSION }
|
8
|
+
|
9
|
+
it { expect(subject).to eq "0.0.3" }
|
12
10
|
end
|
13
11
|
end
|
metadata
CHANGED
@@ -1,62 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: naivebayes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.3
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- id774
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-12-13 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: cucumber
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: bundler
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: jeweler
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - '>='
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - '>='
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
description: Naive Bayes classifier
|
@@ -79,6 +72,7 @@ files:
|
|
79
72
|
- doc/README
|
80
73
|
- lib/naivebayes.rb
|
81
74
|
- lib/naivebayes/classifier.rb
|
75
|
+
- lib/naivebayes/version.rb
|
82
76
|
- naivebayes.gemspec
|
83
77
|
- script/build
|
84
78
|
- spec/lib/naivebayes/classifier_spec.rb
|
@@ -88,26 +82,25 @@ files:
|
|
88
82
|
homepage: http://github.com/id774/naivebayes
|
89
83
|
licenses:
|
90
84
|
- GPL
|
85
|
+
metadata: {}
|
91
86
|
post_install_message:
|
92
87
|
rdoc_options: []
|
93
88
|
require_paths:
|
94
89
|
- lib
|
95
90
|
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
-
none: false
|
97
91
|
requirements:
|
98
|
-
- -
|
92
|
+
- - '>='
|
99
93
|
- !ruby/object:Gem::Version
|
100
94
|
version: '0'
|
101
95
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
-
none: false
|
103
96
|
requirements:
|
104
|
-
- -
|
97
|
+
- - '>='
|
105
98
|
- !ruby/object:Gem::Version
|
106
99
|
version: '0'
|
107
100
|
requirements: []
|
108
101
|
rubyforge_project:
|
109
|
-
rubygems_version: 1.
|
102
|
+
rubygems_version: 2.1.11
|
110
103
|
signing_key:
|
111
|
-
specification_version:
|
104
|
+
specification_version: 4
|
112
105
|
summary: naivebayes
|
113
106
|
test_files: []
|