adaboost 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/adaboost/adaboost.rb +15 -14
- 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: f550adc8429f2927416f49e86461497d9f43a072
|
4
|
+
data.tar.gz: bf2fa99dad4d438a25588f93d8de7a2c62c7f45f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38b3488dd4d034e9694200841a8b1c5022b60f8e8cb06afd88b99147dc140b73183153b12d7ba5c79e06865969958051dee9b59ef76af91e2901731626681b6b
|
7
|
+
data.tar.gz: 8f41f660c6a53b66ee8eed9a80b3948a66bae0bb516ab8d4f52d3322a66c0f40f9201f700cb499be885c5727bc1d2b65966efd04f48fe4bfdcb4453c8607fed9
|
data/lib/adaboost/adaboost.rb
CHANGED
@@ -23,6 +23,7 @@ module AdaBoost
|
|
23
23
|
weak_classifier.compute_alpha
|
24
24
|
update_weights weak_classifier, samples
|
25
25
|
@weak_classifiers << weak_classifier
|
26
|
+
yield i, weak_classifier if block_given?
|
26
27
|
end
|
27
28
|
end
|
28
29
|
|
@@ -50,21 +51,21 @@ module AdaBoost
|
|
50
51
|
negative_weight = 1 / samples_size
|
51
52
|
positive_weight = negative_weight
|
52
53
|
if Config::INCORPORATE_COST_SENSITIVE_LEARNING
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
54
|
+
analyzer = FeaturesAnalyzer.new @y_index
|
55
|
+
distribution = analyzer.analyze(samples).distribution
|
56
|
+
positive_rate = distribution.positive / samples_size
|
57
|
+
negative_rate = distribution.negative / samples_size
|
58
|
+
normalizing_constant = distribution.negative * positive_rate + distribution.positive * negative_rate
|
59
|
+
positive_weight = positive_rate / normalizing_constant.to_f
|
60
|
+
negative_weight = negative_rate / normalizing_constant.to_f
|
60
61
|
end
|
61
62
|
samples.each_with_index do |sample, i|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
63
|
+
y = sample[@y_index]
|
64
|
+
if y == -1
|
65
|
+
@weights[i] = positive_weight
|
66
|
+
else
|
67
|
+
@weights[i] = negative_weight
|
68
|
+
end
|
68
69
|
end
|
69
70
|
end
|
70
71
|
|
@@ -76,7 +77,7 @@ module AdaBoost
|
|
76
77
|
sum += @weights[i]
|
77
78
|
end
|
78
79
|
@weights.each_with_index do |_, i|
|
79
|
-
|
80
|
+
@weights[i] /= sum
|
80
81
|
end
|
81
82
|
end
|
82
83
|
end
|