Sha256: b626ecae97e2136ee9ee88129bc4f1b99641360872e9428c4b3ca7c2f126bbcb

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

require "spec_helper"

describe "binary encoded classification" do
  let(:simple) { Selector::Simple.new(:career_level, classification_encoding: :binary) }

  let(:dictionary) { %w(auto pferd haus hase garten) }
  let(:data) { FactoryGirl.build(:data) }
  let(:vector) { simple.generate_vector(data) }

  before(:each) do
    simple.stubs(:global_dictionary).returns(dictionary)
  end
  it "should build a feature vector for each dataset with the size of the dictionary plus classifications" do
    vector.data.should have(5+4).things
  end
  it "should set 0 if a word from the dictionary NOT exists at the corresponding index" do
    vector.data[0].should eq(0)
  end
  it "should set 1 if a word from the dictionary exists at the corresponding index" do
    vector.data[1].should eq(1)
  end
  it "should set 0's and 1's for each word in the dictionary" do
    vector.data.first(5).should eq([0,1,1,0,1])
  end
  it "should add a n-sized array of 0's and 1's to the results" do
    vector.data.last(4).should eq([0,1,1,1])
  end
  it "should call make_vector" do
    simple.expects(:make_vector).once
    simple.generate_vector(data)
  end
  context "custom dictionary" do
    it "should accept a custom dictionary" do
      vector = simple.generate_vector(data, %w(pferd flasche glas))
      vector.data.should eq([[1,0,0],[0,1,1,1]].flatten)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
svm_helper-0.2.1 spec/svm_helper/selectors/with_binary_encoding_spec.rb