Sha256: 66277f4f338c5d9d7453ddd0498804eccaf55168aa39de6316de22b43edfb4f6

Contents?: true

Size: 1.04 KB

Versions: 4

Compression:

Stored size: 1.04 KB

Contents

require 'test/unit'
require_relative '../src/naive-bayes-classifier'

class NaiveBayesEmTests < Test::Unit::TestCase
  def setup
    number_examples = [%w(one two three), %w(two three four five six), %w(seven three one four five eight nine), %w(ten one two six three seven), %w(one five six seven two eight ten nine)]
    color_examples = [%w(red blue green), %w(red blue yellow purple red), %w(brown green purple red blue black white)]
    @two = NaiveBayesClassifier.train_em(20, number_examples + color_examples)
  end
  
  def test_classify
    color_classifications = [%w(red rainbow green grass), %w(one red blue green), %w(brown cow)].map do |example|
      @two.classify(example)
    end    
    number_classifications = [%w(one hundred two three red), %w(one nine one one eight), %w(three cows)].map do |example|      
      @two.classify(example)
    end
    
    assert_equal 1, color_classifications.uniq.size
    assert_equal 1, number_classifications.uniq.size
    assert_not_equal color_classifications.first, number_classifications.first
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
unsupervised-language-detection-0.0.4 test/test_naive_bayes_em.rb
unsupervised-language-detection-0.0.3 test/test_naive_bayes_em.rb
unsupervised-language-detection-0.0.2 test/test_naive_bayes_em.rb
unsupervised-language-detection-0.0.1 test/test_naive_bayes_em.rb