Skip to content

Implement tree model dump with code generator. - #4602

Merged
trivialfis merged 8 commits into
dmlc:masterfrom
trivialfis:dump-model
Jun 26, 2019
Merged

trivialfis merged 8 commits into
dmlc:masterfrom
trivialfis:dump-model

Conversation

@trivialfis

@trivialfis trivialfis commented Jun 24, 2019 •

Copy link
Copy Markdown
Member
  • Split up builders.
  • Use pattern matching.
  • Implement generator for Graphviz.

Closes #4228, Closes #4561

There are few benefits of this PR:

  • After introducing proper code templates in generator, the semantic of generated text files become clearer. Currently we don't have documentation around what exactly a dumped model should look like.
  • Eliminates parsing the text dump again in language bindings. One can generate very weird output by parsing the dumped text, as in above linked issues. This PR implements a generator for Graphviz, which directly parses the tree model instead of text output.
  • All bindings of Graphviz can accept dot file strings, so it should be easier for scala and jvm (and any other languages) to implement plotting. @CodingCat. (I did a simple grep in the jvm package didn't find any implementation).

But there's one downside:

  • Now we need to pass extra parameters into c++ for Graphviz.

@CodingCat @RAMitchell @hcho3 Could you please take a quick look? See if the added complication is worthy for fixing above issues?

@trivialfis trivialfis changed the title [WIP] Implement tree model dump with proper code generator. [WIP] Implement tree model dump with code generator. Jun 24, 2019
@RAMitchell

Copy link
Copy Markdown
Member

Looks like a nice reorganisation of code. We don't need any changes to the C API right, because it already accepts a string specifying format?

@trivialfis

Copy link
Copy Markdown
Member Author

@KOLANICH I remember sometimes ago you mentioned allowing saving model in other formats, could this be one of the building blocks for your purpose?

@trivialfis

Copy link
Copy Markdown
Member Author

Will try to write the production rules for text file later.

@trivialfis

trivialfis commented Jun 25, 2019 •

Copy link
Copy Markdown
Member Author

@hcho3 Now plotting.to_graphviz in Python package returns a graphviz.Source instead of graphviz.Digraph , which means user can't modify the returned object like adding new node to the graph manually. I can't think of a good reason to do such thing so I'm just gonna make the change.

Can you think of some use cases for modifying returned graph? If so I will close this PR to avoid the change.

@KOLANICH

Copy link
Copy Markdown
Contributor

Thanks for mentioning me.

@trivialfis
trivialfis marked this pull request as ready for review June 25, 2019 17:44
@trivialfis trivialfis changed the title [WIP] Implement tree model dump with code generator. Implement tree model dump with code generator. Jun 25, 2019
@trivialfis

trivialfis commented Jun 25, 2019 •

Copy link
Copy Markdown
Member Author

Will add detailed user document in another PR alone with specification of output text mentioned above. But I won't go over other language bindings for now. Let me fix some piled up issues first.

Comment thread src/tree/tree_model.cc Resolved

@chyunsu3 chyunsu3 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Nice work combining code generators for text dump, JSON dump, and Graphviz dump. We no longer have a hodgepodge of string operations scattered around for different dump types.

Comment thread python-package/xgboost/plotting.py Resolved
Comment thread src/tree/tree_model.cc Resolved
Comment thread src/tree/tree_model.cc Resolved
Comment thread src/tree/tree_model.cc Resolved
Comment thread src/tree/tree_model.cc Resolved
Comment thread src/tree/tree_model.cc Resolved
Comment thread src/tree/tree_model.cc Resolved
Comment thread src/tree/tree_model.cc Resolved
Comment thread src/tree/tree_model.cc Resolved
@trivialfis
trivialfis merged commit 8bdf151 into dmlc:master Jun 26, 2019
@trivialfis

Copy link
Copy Markdown
Member Author

@hcho3 Thanks for the review.

@trivialfis
trivialfis deleted the dump-model branch June 28, 2019 19:43
@lock lock Bot locked as resolved and limited conversation to collaborators Sep 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ValueError: Unable to parse node: 0: plot_tree failed to parse tree nodes with feature names.

4 participants