Skip to content

Commit

Permalink
styling
Browse files Browse the repository at this point in the history
  • Loading branch information
asaf schers committed Feb 3, 2018
1 parent c057d3e commit f1c53d7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
10 changes: 7 additions & 3 deletions lib/scoruby/models/gradient_boosted_model/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ def initialize(xml)

def score(features)
formatted_features = Features.new(features).formatted
scores = decision_trees.map do |dt|
dt.decide(formatted_features).score.to_s.to_f
end
scores = traverse_trees(formatted_features)
sum = scores.reduce(:+) + const
Math.exp(sum) / (1 + Math.exp(sum))
end

def traverse_trees(formatted_features)
decision_trees.map do |dt|
dt.decide(formatted_features).score.to_s.to_f
end
end
end
end
end
Expand Down
12 changes: 9 additions & 3 deletions spec/scoruby/models/gradient_boosted_model/model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@
describe Scoruby::Models::GradientBoostedModel::Model do
let(:xml) { Scoruby.xml_from_file_path(gbm_file) }
let(:gbm) { described_class.new(xml) }
let(:approve_features) { { Sex: 'male', Parch: 0, Age: 30, Fare: 9.6875, Pclass: 2, SibSp: 0, Embarked: 'Q' } }
let(:decline_features) { { Sex: 'female', Parch: 0, Age: 38, Fare: 71.2833, Pclass: 2, SibSp: 1, Embarked: 'C' } }
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' }

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

0 comments on commit f1c53d7

Please sign in to comment.