Skip to content

Commit

Permalink
fix graph size issues
Browse files Browse the repository at this point in the history
  • Loading branch information
DannyBen committed Jan 13, 2017
1 parent 7b034dc commit 2d1bf75
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ spec/reports
test/tmp
test/version_tmp
tmp
*.png
12 changes: 10 additions & 2 deletions lib/decisiontree/id3_tree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,13 @@ def predict(test)
def graph(filename, file_type = 'png')
require 'graphr'
dgp = DotGraphPrinter.new(build_tree)
dgp.size = ''
dgp.node_labeler = proc { |n| n.split("\n").first }
dgp.write_to_file("#{filename}.#{file_type}", file_type)
rescue LoadError
STDERR.puts "Error: Cannot generate graph."
STDERR.puts " The 'graphr' gem doesn't seem to be installed."
STDERR.puts " Run 'gem install graphr' or add it to your Gemfile."
end

def ruleset
Expand Down Expand Up @@ -188,9 +194,11 @@ def build_tree(tree = @tree)
child = attr[1][key]
child_text = "#{child}\n(#{child.to_s.clone.object_id})"
end
label_text = "#{key} ''"

if type(attr[0].attribute) == :continuous
label_text.gsub!("''", attr[0].threshold.to_s)
label_text = "#{key} #{attr[0].threshold}"
else
label_text = key
end

[parent_text, child_text, label_text]
Expand Down

0 comments on commit 2d1bf75

Please sign in to comment.