Class: ML::Learner::DecisionStumpLearner

Inherits:
Object
  • Object
show all
Includes:
Toolbox
Defined in:
lib/method/decision_stump.rb

Overview

Implementation of decision stump learning

Instance Method Summary collapse

Methods included from Toolbox

#classify_error

Constructor Details

#initialize(dim) ⇒ DecisionStumpLearner

Initialize a decision stump learner

Parameters:

  • dim (Integer)

    dimension



9
10
11
12
13
# File 'lib/method/decision_stump.rb', line 9

def initialize dim
  @dim = dim
  @min_error = 1.0/0
  @error_vector = []
end

Instance Method Details

#error_vectorArray

Error vector of each dimension

Returns:

  • (Array)

    the error vector



37
38
39
# File 'lib/method/decision_stump.rb', line 37

def error_vector
  @error_vector
end

#hypothesisArray

Get the hypothesis vector

Format of hypothesis vector h_s,i,t(x) = s sign((x)_i - t)

Returns:

  • (Array)
    s, i, t

    vector



47
48
49
# File 'lib/method/decision_stump.rb', line 47

def hypothesis
  @best_hypo
end

#predict(data) ⇒ Integer

Predict certain data

Parameters:

  • data (Array)

    data in question

Returns:

  • (Integer)

    prediction



30
31
32
# File 'lib/method/decision_stump.rb', line 30

def predict data
  classify data, @best_hypo
end

#train!(data) ⇒ Object

Train with a supervised data

Parameters:

  • data (Hash)

    supervised input data (mapping from array to integer)



18
19
20
21
22
23
24
# File 'lib/method/decision_stump.rb', line 18

def train! data
  for i in 0...@dim
    hypo, error = search data, i
    update_hypo hypo, error
    @error_vector[i] = error
  end
end