summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormguetlein <martin.guetlein@gmail.com>2011-07-12 13:21:27 +0200
committermguetlein <martin.guetlein@gmail.com>2011-07-12 13:21:27 +0200
commit1a01946eb3c89b9a672fb2c1165236c84cbaef36 (patch)
tree0d85db40fdd042831fce61ec0064682b89d644fc
parentd0f50a2218fca7580be80e0595b0a73069329ad6 (diff)
regression plot in 2 different scales
-rw-r--r--report/plot_factory.rb28
-rwxr-xr-xreport/report_content.rb38
2 files changed, 41 insertions, 25 deletions
diff --git a/report/plot_factory.rb b/report/plot_factory.rb
index d6c7d35..26a9c67 100644
--- a/report/plot_factory.rb
+++ b/report/plot_factory.rb
@@ -52,11 +52,12 @@ module Reports
module PlotFactory
- def self.create_regression_plot( out_files, validation_set, name_attribute )
+ def self.create_regression_plot( out_files, validation_set, name_attribute, logscale=true )
out_files = [out_files] unless out_files.is_a?(Array)
LOGGER.debug "Creating regression plot, out-file:"+out_files.to_s
+ omit_count = 0
names = []
x = []
y = []
@@ -64,25 +65,32 @@ module Reports
x_i = v.get_predictions.predicted_values
y_i = v.get_predictions.actual_values
- # filter out nil-predictions
- not_nil_indices = []
+ # filter out nil-predictions and <=0 predictions if log-scale wanted
+ valid_indices = []
x_i.size.times do |i|
- not_nil_indices << i if x_i[i]!=nil && y_i[i]!=nil
+ if x_i[i]!=nil and y_i[i]!=nil and (!logscale or (x_i[i]>0 and y_i[i]>0))
+ valid_indices << i
+ else
+ omit_count += 1
+ end
end
- if not_nil_indices.size < x_i.size
- x_i = not_nil_indices.collect{ |i| x_i[i] }
- y_i = not_nil_indices.collect{ |i| y_i[i] }
+ if valid_indices.size < x_i.size
+ x_i = valid_indices.collect{ |i| x_i[i] }
+ y_i = valid_indices.collect{ |i| y_i[i] }
end
names << ( name_attribute==:crossvalidation_fold ? "fold " : "" ) + v.send(name_attribute).to_s
x << x_i
y << y_i
end
-
- raise "no predictions performed" if x.size==0 || x[0].size==0
+ names = [""] if names.size==1
+
+ omit_str = omit_count>0 ? " ("+omit_count.to_s+" predictions omitted)" : ""
+ raise "no predictions performed"+omit_str if x.size==0 || x[0].size==0
out_files.each do |out_file|
- RubyPlot::regression_point_plot(out_file, "Regression plot", "Predicted values", "Actual values", names, x, y )
+ RubyPlot::regression_point_plot(out_file, "Regression plot", "Predicted values", "Actual values", names, x, y, logscale)
end
+ omit_count
end
diff --git a/report/report_content.rb b/report/report_content.rb
index ea2ad5a..8c437a8 100755
--- a/report/report_content.rb
+++ b/report/report_content.rb
@@ -141,31 +141,39 @@ class Reports::ReportContent
name_attribute,
section_title="Regression Plot",
section_text=nil,
- image_title=nil)
+ image_title="Regression Plot")
- image_title = "Regression plot" unless image_title
#section_regr = @xml_report.add_section(@current_section, section_title)
section_regr = @current_section
prediction_set = validation_set.collect{ |v| v.get_predictions }
if prediction_set.size>0
- section_text += "\nWARNING: regression plot information not available for all validation results" if prediction_set.size!=validation_set.size
- @xml_report.add_paragraph(section_regr, section_text) if section_text
- begin
- plot_png = add_tmp_file("regr_plot", "png")
- plot_svg = add_tmp_file("regr_plot", "svg")
- Reports::PlotFactory.create_regression_plot( [plot_png[:path], plot_svg[:path]], prediction_set, name_attribute )
- @xml_report.add_imagefigure(section_regr, image_title, plot_png[:name], "PNG", 100, plot_svg[:name])
- rescue Exception => ex
- LOGGER.error("Could not create regression plot: "+ex.message)
- rm_tmp_file(plot_png[:name])
- rm_tmp_file(plot_svg[:name])
- @xml_report.add_paragraph(section_regr, "could not create regression plot: "+ex.message)
- end
+ [true, false].each do |log|
+ scale_str = (log ? " (logarithmic scale)" : " (linear scale)")
+ image_title_2 = image_title + scale_str
+ section_title_2 = section_title + scale_str
+
+ section_text += "\nWARNING: regression plot information not available for all validation results" if prediction_set.size!=validation_set.size
+ @xml_report.add_paragraph(section_regr, section_text) if section_text
+ begin
+ log_str = (log ? "_log" : "")
+ plot_png = add_tmp_file("regr_plot"+log_str, "png")
+ plot_svg = add_tmp_file("regr_plot"+log_str, "svg")
+ omit_count = Reports::PlotFactory.create_regression_plot( [plot_png[:path], plot_svg[:path]], prediction_set, name_attribute, log )
+ image_title_2 += " ("+omit_count.to_s+" datapoints omitted)" if omit_count>0
+ @xml_report.add_imagefigure(section_regr, image_title_2, plot_png[:name], "PNG", 100, plot_svg[:name])
+ rescue Exception => ex
+ LOGGER.error("Could not create regression plot: "+ex.message)
+ rm_tmp_file(plot_png[:name])
+ rm_tmp_file(plot_svg[:name])
+ @xml_report.add_paragraph(section_regr, "could not create regression plot: "+ex.message)
+ end
+ end
else
@xml_report.add_paragraph(section_regr, "No prediction info for regression available.")
end
+ align_last_two_images section_title+" in logarithmic and linear scale (values <= 0 are omitted in logarithmic scale)"
end
def add_roc_plot( validation_set,