Module: Lazy_utils

Overview

This module is used by the 'lazy' classifiers from 'lazy.rb' to inherit the following methods (instance and class methods)

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Instance methods list


13
14
15
# File 'lib/ruby-band/weka/classifiers/lazy/lazy_utils.rb', line 13

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#cross_validate(fold) ⇒ Object

perform crossvalidation on a trained classifier ARGV: fold -> 'int' value


56
57
58
59
60
61
62
63
64
65
66
# File 'lib/ruby-band/weka/classifiers/lazy/lazy_utils.rb', line 56

def cross_validate(fold)
  if self.class.data
    eval = Weka::Classifier::Evaluation.new self.class.data
    eval.crossValidateModel(self.class.ancestors[2].new, self.class.data, fold.to_java(:int), Random.new(1))
    eval.summary 
  else
    eval = Weka::Classifier::Evaluation.new @dataset
    eval.crossValidateModel(self.class.ancestors[1].new, @dataset, fold.to_java(:int), Random.new(1))
    eval.summary
  end
end

#descriptionObject

Return a description from the Weka JavaDoc for the selected classifier


49
50
51
# File 'lib/ruby-band/weka/classifiers/lazy/lazy_utils.rb', line 49

def description
  puts globalInfo
end

#init_instance_classifier(&block) ⇒ Object


17
18
19
20
21
# File 'lib/ruby-band/weka/classifiers/lazy/lazy_utils.rb', line 17

def init_instance_classifier(&block)
  self.instance_eval(&block)
  @dataset.setClassIndex(@class_index)
  build_classifier(@dataset)
end

#init_lazyObject


6
7
8
9
10
# File 'lib/ruby-band/weka/classifiers/lazy/lazy_utils.rb', line 6

def init_lazy
  set_options(self.class.options) if self.class.options 
  self.class.data.setClassIndex(self.class.class_index) if self.class.class_index
  buildClassifier(self.class.data)
end

#list_optionsObject

List available options


44
45
46
# File 'lib/ruby-band/weka/classifiers/lazy/lazy_utils.rb', line 44

def list_options
  listOptions.map {|key| "#{key.synopsis} #{key.description}"}.join("\n")
end

#set_class_index(class_index) ⇒ Object

Set a class index for the input dataset


31
32
33
# File 'lib/ruby-band/weka/classifiers/lazy/lazy_utils.rb', line 31

def set_class_index(class_index)
  @class_index = class_index 
end

#set_data(data) ⇒ Object

Set data for instance classifier ARGV data -> an Instances object


26
27
28
# File 'lib/ruby-band/weka/classifiers/lazy/lazy_utils.rb', line 26

def set_data(data)
  @dataset = data 
end

#set_options(options) ⇒ Object

Set options for the selected classfier ARGS: options -> a String, i.e. “-K”


38
39
40
41
# File 'lib/ruby-band/weka/classifiers/lazy/lazy_utils.rb', line 38

def set_options(options)
  options_inst = Utils.splitOptions(options)
  setOptions(options_inst)
end