scoruby 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 79744e1d26538f6439febfcec9d204f1b32230ca
4
- data.tar.gz: aff86cee1ebd5e380b9d58fc5e2763474b6a2a87
3
+ metadata.gz: 18cd7707e6697afbec6c3f379673284e314a852e
4
+ data.tar.gz: ad6be58c00b30f7763e8605a8997037d034538d4
5
5
  SHA512:
6
- metadata.gz: 090dc196102cb081225cc0a308bb5f54745e57900d8a0f33b9cafbae8f0d91d2fcfca3190c8ad1dc0b2ad48363d3925759d3e54ddde0519a570fdf382cd1a2ae
7
- data.tar.gz: 3f0fcd6f3a85d55dcbfa450548856e2a49f5d17c4b71438c51da543fa1ee87c68fd65013ac1b7ccf19f8cfd296788f2b000fd6d3559006df0156291980c1bd96
6
+ metadata.gz: 2f2a3a2bddcb481c1252d0715a2b7b20b56739797c38360d2f62911a9ca932fae6339748ea45255d4dd8b9e4a46d025580cfa9814a5c7167dd281a2fa628069c
7
+ data.tar.gz: e0fdc1cba17e1a026d6949395f6ba46040736dbccbcf31a05a558d483c377f7dc3b5d0d3dd1fabaf4c09053c997b803b3d5b9d273024ccd74e32997231ff5889
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- scoruby (0.3.2)
4
+ scoruby (0.3.3)
5
5
  nokogiri (~> 1.7)
6
6
 
7
7
  GEM
@@ -21,6 +21,11 @@ module Scoruby
21
21
  ModelFactory.factory_for(xml)
22
22
  end
23
23
 
24
+ def self.load_model_from_string(pmml_string)
25
+ xml = xml_from_string(pmml_string)
26
+ ModelFactory.factory_for(xml)
27
+ end
28
+
24
29
  def self.xml_from_file_path(pmml_file_name)
25
30
  pmml_string = File.open(pmml_file_name, 'rb').read
26
31
  xml_from_string(pmml_string)
@@ -21,7 +21,11 @@ module Scoruby
21
21
  def probability(score_distribution, xml)
22
22
  probability = score_distribution.attributes['probability'].to_s
23
23
  return probability.to_f if probability != ''
24
- score_distribution.attributes['recordCount'].to_s.to_f / xml.attributes['recordCount'].to_s.to_f
24
+ record_count(score_distribution) / record_count(xml)
25
+ end
26
+
27
+ def record_count(xml)
28
+ xml.attributes['recordCount'].to_s.to_f
25
29
  end
26
30
  end
27
31
  end
@@ -31,7 +31,7 @@ module Scoruby
31
31
 
32
32
  def self.random_forest?(xml)
33
33
  xml.xpath('PMML/MiningModel/@modelName').to_s == RANDOM_FOREST_MODEL ||
34
- xml.xpath('//Extension').to_s.include?('RandomForestClassifier')
34
+ xml.at('//Segmentation[@multipleModelMethod="average"]')
35
35
  end
36
36
 
37
37
  def self.gbm?(xml)
@@ -9,7 +9,7 @@ module Scoruby
9
9
 
10
10
  def initialize(tree_xml)
11
11
  @id = tree_xml.attribute('id')
12
- @root = Node.new(tree_xml.xpath('TreeModel/Node'))
12
+ @root = Node.new(tree_xml.at_xpath('TreeModel/Node'))
13
13
  end
14
14
 
15
15
  def decide(features)
@@ -39,15 +39,18 @@ module Scoruby
39
39
  end
40
40
 
41
41
  def fetch_categorical_features
42
- @xml.xpath('//DataField')
43
- .select { |xml| xml.attr('optype') == 'categorical' }
44
- .reject { |xml| xml.attr('name') == target }
45
- .each_with_object(Hash.new([])) do |xml, res|
42
+ categorical_features_xml.each_with_object(Hash.new([])) do |xml, res|
46
43
  res[xml.attr('name').to_sym] = xml.xpath('Value')
47
44
  .map { |xml| xml.attr('value') }
48
45
  end
49
46
  end
50
47
 
48
+ def categorical_features_xml
49
+ @xml.xpath('//DataField')
50
+ .select { |xml| xml.attr('optype') == 'categorical' }
51
+ .reject { |xml| xml.attr('name') == target }
52
+ end
53
+
51
54
  def target
52
55
  @target ||= @xml.xpath('//MiningField')
53
56
  .find { |xml| xml.attr('usageType') == 'target' }
@@ -55,8 +58,15 @@ module Scoruby
55
58
  end
56
59
 
57
60
  def const_by_version
58
- return Float(@xml.xpath(CONST_XPATH).to_s) if ModelFactory.gbm_4_3?(@xml)
59
- Float(@xml.xpath(CONST_XPATH_4_2).first.content)
61
+ ModelFactory.gbm_4_3?(@xml) ? const_pmml_4_3 : const_pmml_4_2
62
+ end
63
+
64
+ def const_pmml_4_2
65
+ @xml.xpath(CONST_XPATH_4_2).first.content.to_f
66
+ end
67
+
68
+ def const_pmml_4_3
69
+ @xml.xpath(CONST_XPATH).to_s.to_f
60
70
  end
61
71
  end
62
72
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Scoruby
4
- VERSION = '0.3.2'
4
+ VERSION = '0.3.3'
5
5
  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.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Asaf Schers
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-02-16 00:00:00.000000000 Z
11
+ date: 2018-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler