module Lazar # Classification algorithms class Classification # Weighted majority vote # @param [Array<0,1>] dependent_variables # @param [Array] 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