Class: ML::Learner::DecisionStumpLearner
- Inherits:
-
Object
- Object
- ML::Learner::DecisionStumpLearner
- Includes:
- Toolbox
- Defined in:
- lib/method/decision_stump.rb
Overview
Implementation of decision stump learning
Instance Method Summary collapse
-
#error_vector ⇒ Array
Error vector of each dimension.
-
#hypothesis ⇒ Array
Get the hypothesis vector.
-
#initialize(dim) ⇒ DecisionStumpLearner
constructor
Initialize a decision stump learner.
-
#predict(data) ⇒ Integer
Predict certain data.
-
#train!(data) ⇒ Object
Train with a supervised data.
Methods included from Toolbox
Constructor Details
#initialize(dim) ⇒ DecisionStumpLearner
Initialize a decision stump learner
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_vector ⇒ Array
Error vector of each dimension
37 38 39 |
# File 'lib/method/decision_stump.rb', line 37 def error_vector @error_vector end |
#hypothesis ⇒ Array
Get the hypothesis vector
Format of hypothesis vector h_s,i,t(x) = s sign((x)_i - t)
47 48 49 |
# File 'lib/method/decision_stump.rb', line 47 def hypothesis @best_hypo end |
#predict(data) ⇒ Integer
Predict certain data
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
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 |