Class: MachineLearner::BayesLearner
- Inherits:
-
Learner
- Object
- Classifier
- Learner
- MachineLearner::BayesLearner
- Defined in:
- lib/machine_learner/bayes.rb
Overview
ナイブベイズ学習器
Instance Method Summary collapse
-
#classify(xs) ⇒ Fixnum
識別を行う.
- #classify_raw(xs) ⇒ Object
-
#initialize ⇒ BayesLearner
constructor
コンストラクタ.
-
#learn(datas, ds = nil) ⇒ Array<Boolean>
データを元に学習を行う.
Methods inherited from Classifier
Constructor Details
#initialize ⇒ BayesLearner
コンストラクタ
12 13 |
# File 'lib/machine_learner/bayes.rb', line 12 def initialize end |
Instance Method Details
#classify(xs) ⇒ Fixnum
識別を行う
33 34 35 36 |
# File 'lib/machine_learner/bayes.rb', line 33 def classify(xs) # 最も尤度の高い候補 y を探す classify_raw(xs).max{ |x, y| x[1] <=> y[1] }[0] end |
#classify_raw(xs) ⇒ Object
38 39 40 |
# File 'lib/machine_learner/bayes.rb', line 38 def classify_raw(xs) candidate_y.map{|y| [y, p_y_x(y, xs)]}.to_h end |
#learn(datas, ds = nil) ⇒ Array<Boolean>
データを元に学習を行う
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/machine_learner/bayes.rb', line 18 def learn(datas, ds = nil) # 学習データ @training = datas # 学習データがHashか @hash_mode = @training[0].x.kind_of?(Hash) # 学習データの結果のリスト @ys = @training.map{|data| data.y } @candidate_x = @hash_mode ? {} : [] end |