From 72e2a77fb0b72f7d525ce4b51fc03c8ee9920da2 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Wed, 7 Oct 2015 12:45:10 +0200 Subject: confidence = similarity to nearest neighbor --- lib/classification.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/classification.rb') diff --git a/lib/classification.rb b/lib/classification.rb index ab1efd8..0a32126 100644 --- a/lib/classification.rb +++ b/lib/classification.rb @@ -8,8 +8,10 @@ module OpenTox return {:value => nil,:confidence => nil,:warning => "Cound not find similar compounds."} if neighbors.empty? weighted_sum = {} sim_sum = 0.0 + confidence = 0.0 neighbors.each do |row| n,sim,acts = row + confidence = sim if sim > confidence # distance to nearest neighbor acts.each do |act| weighted_sum[act] ||= 0 weighted_sum[act] += sim @@ -22,7 +24,7 @@ module OpenTox sim_sum = weighted_sum[weighted_sum.keys[0]] sim_sum -= weighted_sum[weighted_sum.keys[1]] sim_sum > 0 ? prediction = weighted_sum.keys[0] : prediction = weighted_sum.keys[1] - confidence = (sim_sum/neighbors.size).abs + #confidence = (sim_sum/neighbors.size).abs return {:value => prediction,:confidence => confidence} else bad_request_error "Cannot predict more than 2 classes, multinomial classifications is not yet implemented. Received classes were: '#{weighted.sum.keys}'" -- cgit v1.2.3