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.

Parameters:

  • depth (Integer) (defaults to: 0)

    The depth of the node in tree.

  • impurity (Float) (defaults to: 0.0)

    The impurity of the node.

  • n_samples (Integer) (defaults to: 0)

    The number of the samples in the node.

  • probs (Float) (defaults to: 0.0)

    The probability of the node.

  • leaf (Boolean) (defaults to: false)

    The flag indicating whether the node is a leaf.

  • leaf_id (Integer) (defaults to: nil)

    The leaf index of the node.

  • left (Node) (defaults to: nil)

    The left node.

  • right (Node) (defaults to: nil)

    The right node.

  • feature_id (Integer) (defaults to: 0)

    The feature index used for evaluation.

  • threshold (Float) (defaults to: 0.0)

    The threshold value of the feature for splitting the node.



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.

Returns:

  • (Hash)

    The marshal data about Node



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.

Returns:

  • (nil)


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