mirror of
https://github.com/dkam/decisiontree.git
synced 2025-12-28 15:14:52 +00:00
fix graph size issues
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -15,3 +15,4 @@ spec/reports
|
|||||||
test/tmp
|
test/tmp
|
||||||
test/version_tmp
|
test/version_tmp
|
||||||
tmp
|
tmp
|
||||||
|
*.png
|
||||||
@@ -130,7 +130,13 @@ module DecisionTree
|
|||||||
def graph(filename, file_type = 'png')
|
def graph(filename, file_type = 'png')
|
||||||
require 'graphr'
|
require 'graphr'
|
||||||
dgp = DotGraphPrinter.new(build_tree)
|
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)
|
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
|
end
|
||||||
|
|
||||||
def ruleset
|
def ruleset
|
||||||
@@ -188,9 +194,11 @@ module DecisionTree
|
|||||||
child = attr[1][key]
|
child = attr[1][key]
|
||||||
child_text = "#{child}\n(#{child.to_s.clone.object_id})"
|
child_text = "#{child}\n(#{child.to_s.clone.object_id})"
|
||||||
end
|
end
|
||||||
label_text = "#{key} ''"
|
|
||||||
if type(attr[0].attribute) == :continuous
|
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
|
end
|
||||||
|
|
||||||
[parent_text, child_text, label_text]
|
[parent_text, child_text, label_text]
|
||||||
|
|||||||
Reference in New Issue
Block a user