Class: Eps::Model

Inherits:
Object
  • Object
show all
Defined in:
lib/eps/model.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = nil, y = nil, estimator: nil, **options) ⇒ Model

Returns a new instance of Model.



3
4
5
6
7
8
9
# File 'lib/eps/model.rb', line 3

def initialize(data = nil, y = nil, estimator: nil, **options)
  if estimator
    @estimator = estimator
  elsif data
    train(data, y, **options)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)



58
59
60
61
62
63
64
# File 'lib/eps/model.rb', line 58

def method_missing(method, *args, &block)
  if @estimator && @estimator.respond_to?(method)
    @estimator.public_send(method, *args, &block)
  else
    super
  end
end

Class Method Details

.load_pmml(data) ⇒ Object

pmml



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/eps/model.rb', line 13

def self.load_pmml(data)
  if data.is_a?(String)
    data = Nokogiri::XML(data) { |config| config.strict }
  end

  estimator_class =
    if data.css("Segmentation").any?
      LightGBM
    elsif data.css("RegressionModel").any?
      LinearRegression
    elsif data.css("NaiveBayesModel").any?
      NaiveBayes
    else
      raise "Unknown model"
    end

  new(estimator: estimator_class.load_pmml(data))
end