Skip to content

Commit

Permalink
Update specs to better GBM data fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
asaf schers committed Mar 9, 2018
1 parent e9893a9 commit 2cdd736
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
11 changes: 6 additions & 5 deletions spec/scoruby/models/gradient_boosted_model/data_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,29 @@
let(:categorical_features) { { Sex: %w[female male] } }

it 'loads correct number of trees' do
expect(data.decision_trees.count).to eq 100
expect(data.decision_trees.count).to eq 15
end

it 'loads continuous features' do
expect(data.continuous_features).to be_empty
expect(data.continuous_features).to match_array %i[Survived Pclass Age Fare]
end

it 'loads categorical features' do
expect(data.categorical_features).to match categorical_features
end

context 'const value' do
let(:const) { -0.4732877044469254 }
context 'pmml 4.3' do
it 'loads correct number of trees' do
let(:const) { 1.3838383838383839 }
it 'loads const' do
expect(data.const).to eq const
end
end

context 'pmml 4.2' do
let(:const) { -0.4732877044469254 }
let(:gbm_file) { 'spec/fixtures/titanic_gbm_4_2.pmml' }
it 'loads correct number of trees' do
it 'loads const' do
expect(data.const).to eq const
end
end
Expand Down
32 changes: 20 additions & 12 deletions spec/scoruby/models/gradient_boosted_model/model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,44 @@
describe Scoruby::Models::GradientBoostedModel::Model do
let(:xml) { Scoruby.xml_from_file_path(gbm_file) }
let(:gbm) { described_class.new(xml) }
let(:approve_features) do
{ Sex: 'male', Parch: 0, Age: 30, Fare: 9.6875,
Pclass: 2, SibSp: 0, Embarked: 'Q' }
end
let(:decline_features) do
{ Sex: 'female', Parch: 0, Age: 38, Fare: 71.2833,
Pclass: 2, SibSp: 1, Embarked: 'C' }
end

context 'pmml 4.3' do
let(:gbm_file) { 'spec/fixtures/titanic_gbm.pmml' }
let(:features1) do
{ Sex: 'male', Parch: 0, Age: 30, Fare: 9.6875,
Pclass: 2, SibSp: 0, Embarked: 'Q' }
end
let(:features2) do
{ Sex: 'female', Parch: 0, Age: 38, Fare: 71.2833,
Pclass: 2, SibSp: 1, Embarked: 'C' }
end

it 'predicts approve' do
expect(gbm.score(approve_features)).to eq 0.3652639329522468
expect(gbm.score(features1)).to eq 0.7990679530500985
end

it 'predicts decline' do
expect(gbm.score(decline_features)).to eq 0.4178155014037758
expect(gbm.score(features2)).to eq 0.8009413525080109
end
end

context 'pmml 4.2' do
let(:gbm_file) { 'spec/fixtures/titanic_gbm_4_2.pmml' }
let(:features1) do
{ Sex: 'male', Parch: 0, Age: 30, Fare: 9.6875,
Pclass: 2, SibSp: 0, Embarked: 'Q' }
end
let(:features2) do
{ Sex: 'female', Parch: 0, Age: 38, Fare: 71.2833,
Pclass: 2, SibSp: 1, Embarked: 'C' }
end

it 'predicts approve' do
expect(gbm.score(approve_features)).to eq 0.3652639329522468
expect(gbm.score(features1)).to eq 0.3652639329522468
end

it 'predicts decline' do
expect(gbm.score(decline_features)).to eq 0.4178155014037758
expect(gbm.score(features2)).to eq 0.4178155014037758
end
end
end

0 comments on commit 2cdd736

Please sign in to comment.