Class: Eps::LightGBM

Inherits:
BaseEstimator show all
Includes:
PmmlGenerators::LightGBM
Defined in:
lib/eps/lightgbm.rb

Class Method Summary collapse

Methods inherited from BaseEstimator

#evaluate, extract_text_features, #initialize, #predict, #summary, #to_pmml

Constructor Details

This class inherits a constructor from Eps::BaseEstimator

Class Method Details

.load_pmml(data) ⇒ Object


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/eps/lightgbm.rb', line 7

def self.load_pmml(data)
  super do |data|
    objective = data.css("MiningModel").first.attribute("functionName").value
    if objective == "classification"
      labels = data.css("RegressionModel OutputField").map { |n| n.attribute("value").value }
      objective = labels.size > 2 ? "multiclass" : "binary"
    end

    features = {}
    text_features, derived_fields = extract_text_features(data, features)
    node = data.css("DataDictionary").first
    node.css("DataField")[1..-1].to_a.each do |node|
      features[node.attribute("name").value] =
        if node.attribute("optype").value == "categorical"
          "categorical"
        else
          "numeric"
        end
    end

    trees = []
    data.css("Segmentation TreeModel").each do |tree|
      node = find_nodes(tree.css("Node").first, derived_fields)
      trees << node
    end

    Evaluators::LightGBM.new(trees: trees, objective: objective, labels: labels, features: features, text_features: text_features)
  end
end