class MachineLearner::SimpleLearner

複数の識別器から最良のものを自動選択する学習器

Public Instance Methods

classifiers(datas, ds) click to toggle source

識別器を列挙する 識別器はyieldでblockに渡す @param datas [Array<DataSet>] トレーニングデータの配列 @param ds [Array<Float>] 各トレーナーデータの重みの配列

# File lib/machine_learner/adaboost.rb, line 31
def classifiers(datas, ds)
  raise NotImplementedError.new
end
classify(x) click to toggle source

識別を行う @param x 特徴空間 @return [Fixnum] 識別結果

# File lib/machine_learner/adaboost.rb, line 44
def classify(x)
  cl.classify(x)
end
learn(datas, ds) click to toggle source

データを元に学習を行う classifiersの各戻り値に対し識別を行い、結果のもっともよいものを採用する @param datas [Array<DataSet>] トレーニングデータの配列 @param ds [Array<Float>] 各トレーナーデータの重みの配列 @return [Array<Boolean>] 識別結果の配列

# File lib/machine_learner/adaboost.rb, line 15
def learn(datas, ds)
  @log = []
  classifiers(datas, ds) do |cl|
    results = datas.map{|data| cl.test(data) }
    epsilon = results.zip(ds).map{|r, w| r ? 0 : w }.inject(:+)
    @log << {epsilon: epsilon, classifier: cl, results: results}
  end
  
  @best = @log.min {|h1, h2| h1[:epsilon] <=> h2[:epsilon] }
  @best[:results]
end
to_s() click to toggle source

識別器を文字列で表現する @return [String] 識別器を表す文字列

# File lib/machine_learner/adaboost.rb, line 37
def to_s
  cl.to_s
end

Private Instance Methods

cl() click to toggle source

性能の最も良い識別器を取得する @return [Classifier] 性能の最も良い識別器を取得する

# File lib/machine_learner/adaboost.rb, line 52
def cl
  @best[:classifier]
end
log() click to toggle source

データを識別器に掛けた結果 ハッシュの配列であり、各ハッシュはキー[:classifier, :result, :epsiron]を持つ @return log [Array<Hash>] 識別結果の配列

# File lib/machine_learner/adaboost.rb, line 59
def log
  @log
end