diff options
author | Christoph Helma <helma@in-silico.ch> | 2015-10-07 12:45:10 +0200 |
---|---|---|
committer | Christoph Helma <helma@in-silico.ch> | 2015-10-07 12:45:10 +0200 |
commit | 72e2a77fb0b72f7d525ce4b51fc03c8ee9920da2 (patch) | |
tree | 3410deb787e8c6ac6ab00c2cf526eae167b731c5 /lib/classification.rb | |
parent | 8d2f1c8a0f6cc9f7a481d1117bf8b3351130b1ea (diff) |
confidence = similarity to nearest neighbor
Diffstat (limited to 'lib/classification.rb')
-rw-r--r-- | lib/classification.rb | 4 |
1 files changed, 3 insertions, 1 deletions
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}'" |