Class: OpenTox::RegressionValidation
- Inherits:
-
Validation
- Object
- Validation
- OpenTox::RegressionValidation
- Defined in:
- lib/validation.rb
Instance Method Summary collapse
Methods inherited from Validation
create, #model, #prediction_dataset, #test_dataset
Instance Method Details
#statistics ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/validation.rb', line 71 def statistics rmse = 0 weighted_rmse = 0 rse = 0 weighted_rse = 0 mae = 0 weighted_mae = 0 confidence_sum = 0 predictions.each do |pred| compound_id,activity,prediction,confidence = pred if activity and prediction error = Math.log10(prediction)-Math.log10(activity.median) rmse += error**2 weighted_rmse += confidence*error**2 mae += error.abs weighted_mae += confidence*error.abs confidence_sum += confidence else warnings << "No training activities for #{Compound.find(compound_id).smiles} in training dataset #{model.training_dataset_id}." $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].median} 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 rmse = Math.sqrt(rmse/predictions.size) weighted_rmse = Math.sqrt(weighted_rmse/confidence_sum) { "R^2" => r**2, "RMSE" => rmse, "MAE" => mae } end |