machine_learner 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/machine_learner/bayes.rb +8 -1
- data/lib/machine_learner/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9748fb82be9cc7e188169f7a9e9991916567bf90
|
4
|
+
data.tar.gz: 782b1df078b2713429d7044386a23a1aff086e73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 657d68abb8d816c9834e1fc86142aa86395f2c4d0c92640a9c26ccb44d7e2d25d8a5eb18d3327d1fd2a8bc4c234ac7d9c997ff72915ded8068f97dec3a012153
|
7
|
+
data.tar.gz: 31f9ac6e23446a92662f1813121a343d4a1ae2ba2cb0448eda56c13a62f5330a25b81ac35dd9d81eb8cac49e524c4edac49aeddf9a824f03062c2d7047f0fa83
|
@@ -16,9 +16,15 @@ module MachineLearner
|
|
16
16
|
# @param datas [Array<DataSet>] トレーニングデータの配列
|
17
17
|
# @return [Array<Boolean>] 識別結果の配列
|
18
18
|
def learn(datas, ds = nil)
|
19
|
+
# 学習データ
|
19
20
|
@training = datas
|
21
|
+
|
22
|
+
# 学習データがHashか
|
23
|
+
@hash_mode = @training[0].x.kind_of?(Hash)
|
24
|
+
|
25
|
+
# 学習データの結果のリスト
|
20
26
|
@ys = @training.map{|data| data.y }
|
21
|
-
@candidate_x = []
|
27
|
+
@candidate_x = @hash_mode ? {} : []
|
22
28
|
end
|
23
29
|
|
24
30
|
# 識別を行う
|
@@ -40,6 +46,7 @@ module MachineLearner
|
|
40
46
|
# P(Y | X) = P(Y) * product(P(Xi | Y))
|
41
47
|
p = Math.log(p_y(y))
|
42
48
|
xs.each_with_index do |xi, i|
|
49
|
+
i, xi = xi if @hash_mode
|
43
50
|
next if xi.nil?
|
44
51
|
p += Math.log(p_xi_y(xi, i, y))
|
45
52
|
end
|