Class: Rumale::Tree::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/rumale/tree/node.rb

Overview

Node is a class that implements node used for construction of decision tree. This class is used for internal data structures.

Instance Method Summary collapse

Constructor Details

#initialize(depth: 0, impurity: 0.0, n_samples: 0, probs: 0.0, leaf: false, leaf_id: nil, left: nil, right: nil, feature_id: 0, threshold: 0.0) ⇒ Node

Create a new node for decision tree.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rumale/tree/node.rb', line 23

def initialize(depth: 0, impurity: 0.0, n_samples: 0, probs: 0.0,
               leaf: false, leaf_id: nil,
               left: nil, right: nil, feature_id: 0, threshold: 0.0)
  @depth = depth
  @impurity = impurity
  @n_samples = n_samples
  @probs = probs
  @leaf = leaf
  @leaf_id = leaf_id
  @left = left
  @right = right
  @feature_id = feature_id
  @threshold = threshold
end

Instance Method Details

#marshal_dumpHash

Dump marshal data.



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rumale/tree/node.rb', line 40

def marshal_dump
  { depth: @depth,
    impurity: @impurity,
    n_samples: @n_samples,
    probs: @probs,
    leaf: @leaf,
    leaf_id: @leaf_id,
    left: @left,
    right: @right,
    feature_id: @feature_id,
    threshold: @threshold }
end

#marshal_load(obj) ⇒ nil

Load marshal data.



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/rumale/tree/node.rb', line 55

def marshal_load(obj)
  @depth = obj[:depth]
  @impurity = obj[:impurity]
  @n_samples = obj[:n_samples]
  @probs = obj[:probs]
  @leaf = obj[:leaf]
  @leaf_id = obj[:leaf_id]
  @left = obj[:left]
  @right = obj[:right]
  @feature_id = obj[:feature_id]
  @threshold = obj[:threshold]
  nil
end