Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add the untrain function #1

Merged
merged 2 commits into from

2 participants

@GCorbel

Hello,

I add a simple function to untrain the bayesian system.

Thanks a lot for your gem.

@reddavis reddavis merged commit e9e48bc into from
@reddavis
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 29, 2012
  1. @GCorbel
  2. @GCorbel

    remove unused folder (sorry)

    GCorbel authored
This page is out of date. Refresh to see the latest.
View
9 lib/naive_bayes.rb
@@ -45,6 +45,13 @@ def train(klass, *features)
@klass_count[klass] += 1
end
+ def untrain(klass, *features)
+ features.uniq.each do |feature|
+ @features_count[klass][feature] -= 1
+ end
+ @klass_count[klass] -= 1
+ end
+
#P(Class | Item) = P(Item | Class) * P(Class)
def classify(*features)
scores = {}
@@ -95,4 +102,4 @@ def assumed_probability
0.5 / (total_items/2)
end
-end
+end
View
2  spec/db/naive.nb
@@ -1 +1 @@
-o:NaiveBayes :@klass_count{: spamf1:hamf1:@db_filepath"U/Users/reddavis/Documents/projects/machine_learning/naive_bayes/spec/db/naive.nb:@features_count{;}" wordf1"badf1f0;}"wef1"badf1@:
+o:NaiveBayes :@features_count{: spam}I"bad:EFf1I" word;Ff1f0:ham}I"we;Ff1I"bad;Ff1@:@klass_count{;f1; f1:
View
7 spec/naive_bayes_spec.rb
@@ -12,6 +12,13 @@
a[0].should == :spam
a[1].should == 0.5
end
+
+ it "should change information" do
+ @classifier.untrain(:spam, 'bad', 'word')
+ a = @classifier.classify('bad', 'word')
+ a[0].should == :ham
+ a[1].should == 1.0
+ end
end
describe "Saving the NB" do
Something went wrong with that request. Please try again.