scoruby 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2a1c339dc5c029d90d8e3a495af90499368bc92d
4
- data.tar.gz: 5ff3c0147290c83d76261b9a6907e35ca493b678
3
+ metadata.gz: aba708affa4e656a44a43d1f24b71b696760b7bd
4
+ data.tar.gz: d52253a2d308e3d7f7749f379feae9757e866887
5
5
  SHA512:
6
- metadata.gz: 8843f6c37d4b4d4e30f018348b5ec113e66558b2c78c945f4755ea01554b609af3dbb4a50334143ffa8f4bab205303b833831273a97bd18a2ecc9fa4e214f401
7
- data.tar.gz: 94078bb11bd0cf3490c93c90e822fed248d4721e24a2623004d2cd3af8805407d6a69599ba2d753bd024caefb0d7e08eb8ddebefef1f37b3dbfe2dcdf49a3bad
6
+ metadata.gz: 7f1dcf1c79cea6278c5a584c7390acaf275104fde029e83514d3cbf39859c840944d3893076c658c6eca9506add2c192525f5fbf6f6c65e1e8871ff5ddd6429f
7
+ data.tar.gz: e9d4f29650d95e74ae6e45c5fd5a4ef8435d552b792f558c9e15c07ce6d4d02f2bbe64ae34d07cfcbc55a4afe0f554df2adb79b25d0a1dfc69d611cc3b660a8a
data/.gitignore CHANGED
@@ -12,3 +12,5 @@ spec/fixtures/decision_tree_v2.pmml
12
12
  test_gbm.pmml
13
13
 
14
14
  test_gbm.rb
15
+
16
+ titanic_rf.pmml
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- scoruby (0.2.5)
4
+ scoruby (0.2.6)
5
5
  nokogiri (~> 1.7)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  Ruby scoring API for Predictive Model Markup Language (PMML).
9
9
 
10
- Currently supports Decision Tree, Random Forest and Gradient Boosted Models.
10
+ Currently supports Decision Tree, Random Forest Naive Bayes and Gradient Boosted Models.
11
11
 
12
12
  Will be happy to implement new models by demand, or assist with any other issue.
13
13
 
@@ -50,7 +50,7 @@ features = {
50
50
 
51
51
  random_forest.predict(features)
52
52
 
53
- => "0"
53
+ => {:label=>"0", :score=>0.882}
54
54
 
55
55
  random_forest.decisions_count(features)
56
56
 
@@ -88,22 +88,21 @@ gbm.score(features)
88
88
 
89
89
  ```ruby
90
90
  decision_tree = Scoruby.get_model 'decision_tree.pmml'
91
-
92
- features = {
93
- Sex: 'male',
94
- Parch: 0,
95
- Age: 30,
96
- Fare: 9.6875,
97
- Pclass: 2,
98
- SibSp: 0,
99
- Embarked: 'Q'
100
- }
101
-
91
+ features = { f1 : v1, ... }
102
92
  decision_tree.decide(features)
103
93
 
104
94
  => #<Decision:0x007fc232384180 @score="0", @score_distribution={"0"=>"0.999615579933873", "1"=>"0.000384420066126561"}>
105
95
  ```
106
96
 
97
+ ### Naibve Bayes
98
+
99
+ ```ruby
100
+ naive_bayes = Scoruby.get_model 'naive_bayes.pmml'
101
+ features = { f1: v1 , ... }
102
+ naive_bayes.lvalues(features)
103
+ naive_bayes.score(features, 'l1')
104
+ ```
105
+
107
106
  ## Development
108
107
 
109
108
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -30,7 +30,7 @@ module Scoruby
30
30
  @labels = {}
31
31
  @xml.xpath('//BayesOutput//TargetValueCount').each do |l|
32
32
  l.attr('value')
33
- @labels[l.attr('value')] = {'count': l.attr('count').to_f}
33
+ @labels[l.attr('value')] = { 'count': l.attr('count').to_f }
34
34
  end
35
35
  end
36
36
 
@@ -19,7 +19,11 @@ module Scoruby
19
19
  end
20
20
 
21
21
  def predict(features)
22
- decisions_count(features).max_by {|_, v| v}[0]
22
+ decisions_count = decisions_count(features)
23
+ {
24
+ label: decisions_count.max_by {|_, v| v}[0],
25
+ score: decisions_count.max_by {|_, v| v}[1] / decisions_count.values.reduce(0, :+).to_f
26
+ }
23
27
  end
24
28
  end
25
29
  end
@@ -1,3 +1,3 @@
1
1
  module Scoruby
2
- VERSION = '0.2.6'
2
+ VERSION = '0.2.7'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scoruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Asaf Schers
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-15 00:00:00.000000000 Z
11
+ date: 2017-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -167,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
167
  version: '0'
168
168
  requirements: []
169
169
  rubyforge_project:
170
- rubygems_version: 2.2.2
170
+ rubygems_version: 2.4.8
171
171
  signing_key:
172
172
  specification_version: 4
173
173
  summary: Ruby Scoring API for PMML.