Module: RandomForester

Defined in:
lib/random_forester.rb,
lib/random_forester/version.rb

Constant Summary collapse

VERSION =
"0.1.2"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.loggerObject



15
16
17
18
19
# File 'lib/random_forester.rb', line 15

def logger
  @logger ||= Logger.new($stdout).tap do |log|
    log.progname = self.name
  end
end

Class Method Details

.get_model(pmml_file_name) ⇒ Object



22
23
24
25
# File 'lib/random_forester.rb', line 22

def self.get_model(pmml_file_name)
  xml = xml_from_file_path(pmml_file_name)
  new_model(xml)
end

.get_model_type(xml) ⇒ Object



46
47
48
# File 'lib/random_forester.rb', line 46

def self.get_model_type(xml)
  xml.xpath("PMML/MiningModel/@modelName").to_s
end

.new_model(xml) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/random_forester.rb', line 27

def self.new_model(xml)
  case get_model_type(xml)
    when RANDOM_FOREST_MODEL
      RandomForest.new(xml)
    else
      raise MODEL_NOT_SUPPORTED_ERROR
  end
end

.xml_from_file_path(pmml_file_name) ⇒ Object



36
37
38
39
# File 'lib/random_forester.rb', line 36

def self.xml_from_file_path(pmml_file_name)
  pmml_string = File.open(pmml_file_name, 'rb').read
  xml_from_string(pmml_string)
end

.xml_from_string(pmml_string) ⇒ Object



41
42
43
44
# File 'lib/random_forester.rb', line 41

def self.xml_from_string(pmml_string)
  xml = Nokogiri::XML(pmml_string) { |config| config.noblanks }
  xml.remove_namespaces!
end