summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgebele <gebele@in-silico.ch>2015-09-17 17:21:42 +0200
committergebele <gebele@in-silico.ch>2015-09-17 17:21:42 +0200
commit44e2641783d4d4ef82479b4be3a37b177698fc97 (patch)
treeccaefb28584603252e01fae1b2afc7bf31324f01
parentc20b9fb92b56c7818a4f24b22eead665b1dd1143 (diff)
introduced batch prediction
-rw-r--r--application.rb8
-rw-r--r--views/batch.haml19
2 files changed, 16 insertions, 11 deletions
diff --git a/application.rb b/application.rb
index 0214db4..07af20b 100644
--- a/application.rb
+++ b/application.rb
@@ -208,13 +208,13 @@ post '/predict/?' do
input = OpenTox::Dataset.from_csv_file File.join "tmp", params[:fileselect][:filename]
dataset = OpenTox::Dataset.find input.id
@compounds = dataset.compounds
- @models = []
- @predictions = []
+ @batch = {}
@compounds.each do |compound|
+ @batch[compound] = []
params[:selection].keys.each do |model_id|
model = Model::Prediction.find model_id
- @models << model
- @predictions << model.predict(compound)
+ prediction = model.predict(compound)
+ @batch[compound] << [model, prediction]
end
end
input.delete
diff --git a/views/batch.haml b/views/batch.haml
index 5bae411..8fbc8cc 100644
--- a/views/batch.haml
+++ b/views/batch.haml
@@ -6,31 +6,36 @@
%h3 Batch Prediction Results:
%tbody
- - @compounds.each_with_index do |compound,i|
+ / key = compound, values = array of arrays with model, prediction
+ - @batch.each do |key, values|
+ - compound = key
%tr
- %td{:id=>"compound", :style=>"vertical-align:top;"}
+ %td{:style=>"vertical-align:top;"}
%p= compound.svg
%p= compound.smiles
- - @predictions.each_with_index do |prediction,i|
+ / array = single prediction [endpoint, result]
+ - values.each_with_index do |array,i|
%td{:style=>"vertical-align:top;"}
+ - model = array[0]
+ - prediction = array[1]
%b{:class => "title"}
- = "#{@models[i].endpoint.gsub('_', ' ')} (#{@models[i].species})"
+ = "#{model.endpoint.gsub('_', ' ')} (#{model.species})"
%p
- if prediction[:confidence] == "measured"
%p
/ TODO fix scientific notation from database
%b Measured activity:
- = prediction[:value].numeric? ? "#{prediction[:value].round(3)} (#{@models[i].unit})" : prediction[:value]
+ = prediction[:value].numeric? ? "#{prediction[:value].round(3)} (#{model.unit})" : prediction[:value]
%p Compound is part of the training dataset
- elsif prediction[:neighbors].size > 0
%p
/ model type (classification|regression)
%b Type:
- = @models[i].model.class.to_s.match("Classification") ? "Classification" : "Regression"
+ = model.model.class.to_s.match("Classification") ? "Classification" : "Regression"
%br
%b Prediction:
/ TODO scientific notation
- = prediction[:value].numeric? ? "#{'%.2e' % prediction[:value]} #{@models[i].unit}" : prediction[:value]
+ = prediction[:value].numeric? ? "#{'%.2e' % prediction[:value]} #{model.unit}" : prediction[:value]
%br
/ TODO probability
%b Confidence: