From 35d2994404febf980395c50dcc82f30cf5c10948 Mon Sep 17 00:00:00 2001 From: rautenberg Date: Wed, 14 Sep 2016 15:29:03 +0200 Subject: test validation results --- lib/report.rb | 10 +- views/model_details.haml | 240 ++++++++++++++++++++++++----------------------- 2 files changed, 128 insertions(+), 122 deletions(-) diff --git a/lib/report.rb b/lib/report.rb index 628b095..aec30cd 100644 --- a/lib/report.rb +++ b/lib/report.rb @@ -27,7 +27,7 @@ get "/report/:id/?" do model = Model::Lazar.find params[:id] resource_not_found_error "Model with id: #{params[:id]} not found." unless model prediction_model = Model::Prediction.find_by :model_id => params[:id] - validation_template = File.join(File.dirname(__FILE__),"views/model_details.haml") + validation_template = File.join(File.dirname(__FILE__),"../views/model_details.haml") if File.directory?("#{File.dirname(__FILE__)}/../../lazar") lazar_commit = `cd #{File.dirname(__FILE__)}/../../lazar; git rev-parse HEAD`.strip @@ -145,11 +145,11 @@ get "/report/:id/?" do report.value "other_info", "#{prediction_model.source}" # Pre-processing of data before modelling 6.6 - report.value "preprocessing", (model.class == OpenTox::Model::LazarRegression ? "-log 10 transformation" : "none") + report.value "preprocessing", (model.class == OpenTox::Model::LazarRegression ? "-log10 transformation" : "none") - if model.crossvalidations - crossvalidations = model.crossvalidations - out = Haml::Engine.new(File.read(validation_template)).render @report + if prediction_model.crossvalidations + crossvalidations = prediction_model.crossvalidations + out = haml File.read(validation_template), :layout=> false, :locals => {:model => prediction_model} report.value "lmo", CGI.escapeHTML(out) end diff --git a/views/model_details.haml b/views/model_details.haml index 251fca8..34f4de8 100644 --- a/views/model_details.haml +++ b/views/model_details.haml @@ -1,117 +1,123 @@ -%b Model: -%br -Source: -%a{:href=>model.source, :target=>"external"} - = model.source -%br -- model.classification? ? type = "Classification" : type = "Regression" -= "Type:\t" -= type -%br -- training_dataset = OpenTox::Dataset.find model.training_dataset.id -= "Training compounds:\t" -= training_dataset.compounds.size - -%p -- if type == "Classification" - %b Independent crossvalidations: -- else - %b Independent crossvalidations (-log10 transformed): -%div.row{:id=>"validations#{model.id}", :style=>"background-color:#f5f5f5;"} - - model.crossvalidations.each do |crossvalidation| - %span.col-xs-4.col-sm-4.col-md-4.col-lg-4 - - cv = OpenTox::CrossValidation.find crossvalidation.id - = "Num folds:\t" - = cv.folds - %br - = "Num instances:\t" - = cv.nr_instances - %br - = "Num unpredicted" - = cv.nr_unpredicted - - if model.classification? - %br - = "Accuracy:\t" - = cv.accuracy.round(3) if cv.accuracy - %br - = "True positive rate:\t" - = cv.true_rate["active"].round(3) if cv.true_rate["active"] - %br - = "True negative rate:\t" - = cv.true_rate["inactive"].round(3) if cv.true_rate["inactive"] - %br - = "Positive predictive value:\t" - = cv.predictivity["active"].round(3) if cv.predictivity["active"] - %br - = "Negative predictive value:\t" - = cv.predictivity["inactive"].round(3) if cv.predictivity["inactive"] - %p - %b Confusion Matrix: - %table.table.table-condensed.table-borderless{:style=>"width:20%;"} - %tbody - %tr - %td - %td - %td - %b actual - %td - %td - %tr - %td - %td - %td active - %td inactive - -#%td total - %tr - %td - %b predicted - %td active - %td - =cv.confusion_matrix[0][0] - %td - =cv.confusion_matrix[0][1] - -#%td - =cv.confusion_matrix[0][0]+cv.confusion_matrix[0][1] - %tr - %td - %td inactive - %td - =cv.confusion_matrix[1][0] - %td - =cv.confusion_matrix[1][1] - -#%td - =cv.confusion_matrix[1][0]+cv.confusion_matrix[1][1] - -#%tr - %td - %td total - %td - =cv.confusion_matrix[0][0]+cv.confusion_matrix[1][0] - %td - =cv.confusion_matrix[0][1]+cv.confusion_matrix[1][1] - %td - -#= "Confusion Matrix:\t" - -#= cv.confusion_matrix - %br - /= "Confidence plot:" - /%p.plot - / %img{:src=>"confp#{cv.id}.svg"} - - if model.regression? - %br - = "Root mean squared error:\t" - = cv.rmse.round(3) if cv.rmse - %br - = "Mean absolute error:\t" - = cv.mae.round(3) if cv.mae - %br - = "R square:\t" - = cv.r_squared.round(3) if cv.r_squared - %br - /= "Confidence plot:" - /%p.plot - / %img{:src=>"/confp#{cv.id}.svg"} - /%br - /= "Correlation plot" - /%p.plot - / %img{:src=>"/corrp#{cv.id}.svg"} - -%br \ No newline at end of file +%html + %head + %body + %b Model: + %br + Source: + %a{:href=>model.source, :target=>"external"} + = model.source + %br + - model.classification? ? type = "Classification" : type = "Regression" + = "Type:\t" + = type + %br + - training_dataset = OpenTox::Dataset.find model.training_dataset.id + = "Training compounds:\t" + = training_dataset.compounds.size + + %p + - if type == "Classification" + %b Independent crossvalidations: + - else + %b Independent crossvalidations (-log10 transformed): + %div.row{:id=>"validations#{model.id}", :style=>"background-color:#f5f5f5;"} + - model.crossvalidations.each do |crossvalidation| + %span + - cv = OpenTox::CrossValidation.find crossvalidation.id + = "Num folds:\t" + = crossvalidation.folds + %br + = "Num instances:\t" + = crossvalidation.nr_instances + %br + = "Num unpredicted" + = crossvalidation.nr_unpredicted + - if model.classification? + %br + = "Accuracy:\t" + = crossvalidation.accuracy.round(3) if crossvalidation.accuracy + %br + - if crossvalidation.true_rate + = "True positive rate:\t" + = crossvalidation.true_rate["active"].round(3) if crossvalidation.true_rate["active"] + %br + = "True negative rate:\t" + = crossvalidation.true_rate["inactive"].round(3) if crossvalidation.true_rate["inactive"] + %br + - if crossvalidation.predictivity + = "Positive predictive value:\t" + = crossvalidation.predictivity["active"].round(3) if crossvalidation.predictivity["active"] + %br + = "Negative predictive value:\t" + = crossvalidation.predictivity["inactive"].round(3) if crossvalidation.predictivity["inactive"] + + %p + %b Confusion Matrix: + %table{:style=>"width:20%;"} + %tbody + %tr + %td + %td + %td + %b actual + %td + %td + %tr + %td + %td + %td active + %td inactive + -#%td total + %tr + %td + %b predicted + %td active + %td + =crossvalidation.confusion_matrix[0][0] + %td + =crossvalidation.confusion_matrix[0][1] + -#%td + =crossvalidation.confusion_matrix[0][0]+crossvalidation.confusion_matrix[0][1] + %tr + %td + %td inactive + %td + =crossvalidation.confusion_matrix[1][0] + %td + =crossvalidation.confusion_matrix[1][1] + -#%td + =crossvalidation.confusion_matrix[1][0]+crossvalidation.confusion_matrix[1][1] + -#%tr + %td + %td total + %td + =crossvalidation.confusion_matrix[0][0]+crossvalidation.confusion_matrix[1][0] + %td + =crossvalidation.confusion_matrix[0][1]+crossvalidation.confusion_matrix[1][1] + %td + -#= "Confusion Matrix:\t" + -#= crossvalidation.confusion_matrix + %br + /= "Confidence plot:" + /%p.plot + / %img{:src=>"confp#{crossvalidation.id}.svg"} + - if model.regression? + %br + = "Root mean squared error:\t" + = crossvalidation.rmse.round(3) if crossvalidation.rmse + %br + = "Mean absolute error:\t" + = crossvalidation.mae.round(3) if crossvalidation.mae + %br + = "R square:\t" + = crossvalidation.r_squared.round(3) if crossvalidation.r_squared + %br + /= "Confidence plot:" + /%p.plot + / %img{:src=>"/confp#{crossvalidation.id}.svg"} + /%br + /= "Correlation plot" + /%p.plot + / %img{:src=>"/corrp#{crossvalidation.id}.svg"} + + %br \ No newline at end of file -- cgit v1.2.3