blob: 5796ce298aed3aa86c22f97a916e9a8d5c4cf1cc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
module Lazar
# Classification algorithms
class Classification
# Weighted majority vote
# @param [Array<0,1>] dependent_variables
# @param [Array<Float>] weights
# @return [Hash]
def self.weighted_majority_vote dependent_variables:, weights:
w = []
w[0] = weights.each_index.select{|i| dependent_variables[i] == 0}.collect{|i| weights[i]}
w[1] = weights.each_index.select{|i| dependent_variables[i] == 1}.collect{|i| weights[i]}
weights_sum = weights.sum.to_f
weights_max = weights.max.to_f
probabilities = []
probabilities[0] = weights_max*w[0].sum/weights_sum
probabilities[1] = weights_max*w[1].sum/weights_sum
probabilities
end
end
end
|