class Scoruby::Models::GradientBoostedModel::Data
Constants
- CONST_XPATH
- CONST_XPATH_4_2
- GBM_FOREST_XPATH
Public Class Methods
new(xml)
click to toggle source
# File lib/scoruby/models/gradient_boosted_model/data.rb, line 11 def initialize(xml) @xml = xml end
Public Instance Methods
categorical_features()
click to toggle source
# File lib/scoruby/models/gradient_boosted_model/data.rb, line 29 def categorical_features @categorical_features ||= fetch_categorical_features end
const()
click to toggle source
# File lib/scoruby/models/gradient_boosted_model/data.rb, line 21 def const @const ||= const_by_version end
continuous_features()
click to toggle source
# File lib/scoruby/models/gradient_boosted_model/data.rb, line 25 def continuous_features @continuous_features ||= fetch_continuous_features end
decision_trees()
click to toggle source
# File lib/scoruby/models/gradient_boosted_model/data.rb, line 15 def decision_trees @decision_trees ||= @xml.xpath(GBM_FOREST_XPATH).map do |xml_tree| DecisionTree.new(xml_tree) end end
Private Instance Methods
categorical_features_xml()
click to toggle source
# File lib/scoruby/models/gradient_boosted_model/data.rb, line 48 def categorical_features_xml @xml.xpath('//DataField') .select { |xml| xml.attr('optype') == 'categorical' } .reject { |xml| xml.attr('name') == target } end
const_by_version()
click to toggle source
# File lib/scoruby/models/gradient_boosted_model/data.rb, line 60 def const_by_version ModelFactory.gbm_4_3?(@xml) ? const_pmml_4_3 : const_pmml_4_2 end
const_pmml_4_2()
click to toggle source
# File lib/scoruby/models/gradient_boosted_model/data.rb, line 64 def const_pmml_4_2 @xml.xpath(CONST_XPATH_4_2).first.content.to_f end
const_pmml_4_3()
click to toggle source
# File lib/scoruby/models/gradient_boosted_model/data.rb, line 68 def const_pmml_4_3 @xml.xpath(CONST_XPATH).to_s.to_f end
fetch_categorical_features()
click to toggle source
# File lib/scoruby/models/gradient_boosted_model/data.rb, line 41 def fetch_categorical_features categorical_features_xml.each_with_object(Hash.new([])) do |xml, res| res[xml.attr('name').to_sym] = xml.xpath('Value') .map { |xml| xml.attr('value') } end end
fetch_continuous_features()
click to toggle source
# File lib/scoruby/models/gradient_boosted_model/data.rb, line 35 def fetch_continuous_features @xml.xpath('//DataField') .select { |xml| xml.attr('optype') == 'continuous' } .map { |xml| xml.attr('name').to_sym } end
target()
click to toggle source
# File lib/scoruby/models/gradient_boosted_model/data.rb, line 54 def target @target ||= @xml.xpath('//MiningField') .find { |xml| xml.attr('usageType') == 'target' } .attr('name').to_s end