summaryrefslogtreecommitdiff
path: root/lib/crossvalidation.rb
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.ch>2016-02-29 08:59:43 +0100
committerChristoph Helma <helma@in-silico.ch>2016-02-29 08:59:43 +0100
commit72f6cd966a249859e009a0db5f7b089aad1d6511 (patch)
tree8668abfd8e5cefdee9565b184b3ea63dd5e9491f /lib/crossvalidation.rb
parentd0c6234fed7d45227fcf9309cb6dc0854d17e647 (diff)
regression crossvalidation fixed
Diffstat (limited to 'lib/crossvalidation.rb')
-rw-r--r--lib/crossvalidation.rb20
1 files changed, 11 insertions, 9 deletions
diff --git a/lib/crossvalidation.rb b/lib/crossvalidation.rb
index 362842e..ea32a2b 100644
--- a/lib/crossvalidation.rb
+++ b/lib/crossvalidation.rb
@@ -176,11 +176,15 @@ module OpenTox
mae = 0
weighted_mae = 0
confidence_sum = 0
+ x = []
+ y = []
predictions.each do |pred|
compound_id,activity,prediction,confidence = pred
- if activity and prediction
- activity.each do |act|
- error = Math.log10(prediction)-Math.log10(act)
+ if activity and prediction
+ unless activity == [nil]
+ x << -Math.log10(activity.median)
+ y << -Math.log10(prediction)
+ error = Math.log10(prediction)-Math.log10(activity.median)
rmse += error**2
weighted_rmse += confidence*error**2
mae += error.abs
@@ -192,22 +196,20 @@ module OpenTox
$logger.debug "No training activities for #{Compound.find(compound_id).smiles} in training dataset #{model.training_dataset_id}."
end
end
- x = predictions.collect{|p| p[1]}
- y = predictions.collect{|p| p[2]}
R.assign "measurement", x
R.assign "prediction", y
R.eval "r <- cor(-log(measurement),-log(prediction),use='complete')"
r = R.eval("r").to_ruby
mae = mae/predictions.size
- weighted_mae = weighted_mae/confidence_sum
+ #weighted_mae = weighted_mae/confidence_sum
rmse = Math.sqrt(rmse/predictions.size)
- weighted_rmse = Math.sqrt(weighted_rmse/confidence_sum)
+ #weighted_rmse = Math.sqrt(weighted_rmse/confidence_sum)
update_attributes(
mae: mae,
rmse: rmse,
- weighted_mae: weighted_mae,
- weighted_rmse: weighted_rmse,
+ #weighted_mae: weighted_mae,
+ #weighted_rmse: weighted_rmse,
r_squared: r**2,
finished_at: Time.now
)