From 398d8ca681db3aa0a0552eee026705e60dd8449d Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Thu, 20 Aug 2015 14:02:04 +0200 Subject: crossvalidation fixes --- lib/regression.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'lib/regression.rb') diff --git a/lib/regression.rb b/lib/regression.rb index 8a52e7d..0bc6547 100644 --- a/lib/regression.rb +++ b/lib/regression.rb @@ -34,6 +34,30 @@ module OpenTox {:value => prediction,:confidence => confidence} end + def self.weighted_average_with_relevant_fingerprints neighbors + weighted_sum = 0.0 + sim_sum = 0.0 + fingerprint_features = [] + neighbors.each do |row| + n,sim,acts = row + neighbor = Compound.find n + fingerprint_features += neighbor.fp4 + end + fingerprint_features.uniq! + p fingerprint_features +=begin + p n + acts.each do |act| + weighted_sum += sim*Math.log10(act) + sim_sum += sim + end + end +=end + confidence = sim_sum/neighbors.size.to_f + sim_sum == 0 ? prediction = nil : prediction = 10**(weighted_sum/sim_sum) + {:value => prediction,:confidence => confidence} + end + # Local support vector regression from neighbors # @param [Hash] params Keys `:props, :activities, :sims, :min_train_performance` are required # @return [Numeric] A prediction value. -- cgit v1.2.3