class Scoruby::ModelFactory

Constants

GBM_INDICATION_4_2
GBM_INDICATION_4_3
MODEL_NOT_SUPPORTED_ERROR
RANDOM_FOREST_MODEL

Public Class Methods

decision_tree?(xml) click to toggle source
# File lib/scoruby/model_factory.rb, line 28
def self.decision_tree?(xml)
  !xml.xpath('PMML/TreeModel').empty?
end
factory_for(xml) click to toggle source
# File lib/scoruby/model_factory.rb, line 15
def self.factory_for(xml)
  return Models::RandomForest::Model.new(xml) if random_forest?(xml)
  return Models::GradientBoostedModel::Model.new(xml) if gbm?(xml)
  return Models::DecisionTree.new(xml.child) if decision_tree?(xml)
  return Models::NaiveBayes::Model.new(xml) if naive_bayes?(xml)

  raise MODEL_NOT_SUPPORTED_ERROR
end
gbm?(xml) click to toggle source
# File lib/scoruby/model_factory.rb, line 37
def self.gbm?(xml)
  gbm_4_2?(xml) || gbm_4_3?(xml)
end
gbm_4_2?(xml) click to toggle source
# File lib/scoruby/model_factory.rb, line 41
def self.gbm_4_2?(xml)
  !xml.xpath(GBM_INDICATION_4_2).empty?
end
gbm_4_3?(xml) click to toggle source
# File lib/scoruby/model_factory.rb, line 45
def self.gbm_4_3?(xml)
  !xml.xpath(GBM_INDICATION_4_3).empty?
end
naive_bayes?(xml) click to toggle source
# File lib/scoruby/model_factory.rb, line 24
def self.naive_bayes?(xml)
  !xml.xpath('PMML/NaiveBayesModel').empty?
end
random_forest?(xml) click to toggle source
# File lib/scoruby/model_factory.rb, line 32
def self.random_forest?(xml)
  xml.xpath('PMML/MiningModel/@modelName').to_s == RANDOM_FOREST_MODEL ||
    xml.at('//Segmentation[@multipleModelMethod="average"]')
end