Class: OpenTox::Algorithm::Classification

Inherits:
Object
  • Object
show all
Defined in:
lib/classification.rb

Overview

Classification algorithms

Class Method Summary collapse

Class Method Details

.weighted_majority_vote(dependent_variables:, independent_variables: nil, weights:, query_variables: nil) ⇒ Hash

Weighted majority vote

Parameters:

Returns:

  • (Hash)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/classification.rb', line 11

def self.weighted_majority_vote dependent_variables:, independent_variables:nil, weights:, query_variables:nil
  class_weights = {}
  dependent_variables.each_with_index do |v,i|
    class_weights[v] ||= []
    class_weights[v] << weights[i] unless v.nil?
  end
  probabilities = {}
  class_weights.each do |a,w|
    probabilities[a] = w.sum/weights.sum
  end
  probabilities = probabilities.collect{|a,p| [a,weights.max*p]}.to_h
  p_max = probabilities.collect{|a,p| p}.max
  prediction = probabilities.key(p_max)
  {:value => prediction,:probabilities => probabilities}
end