jpmml / jpmml-sparkml

Java library and command-line application for converting Apache Spark ML pipelines to PMML
GNU Affero General Public License v3.0
267 stars 80 forks source link

visualize pmml tree model #94

Closed XScarlett closed 4 years ago

XScarlett commented 4 years ago

Is there a better way to visualize PMML tree model?

ths.

vruusmann commented 4 years ago

The JPMML software project does not provide any visualization tools right now.

How would you like to visualize if free to choose? Any favourite tools/frameworks/libraries?

I would suggest using some "bridge" data format - instead of developing PMML visualizations tools from scratch, there would simply be a conversion tool that translates PMML models to some already supported data format, which can then be visualized using existing tools.

I know that Scikit-Learn uses DOT data format for tree visualization. So, one way to address this issue would be to build a PMML-to-DOT converter.

XScarlett commented 4 years ago

Thanks for your suggestion, i used DOT data format for tree visualization in scikit-learn and performed good, that is what i want, and how can i build a PMML-to-DOT converter?

vruusmann commented 4 years ago

how can i build a PMML-to-DOT converter?

You could develop an XSL stylesheet, or a Java application using the Visitor API of the JPMML-Model library.

The Java application way is probably easier - a new AbstractVisitor subclass that prints out a DOT graph vertex every time it visits an org.dmg.pmml.tree.Node object.

XScarlett commented 4 years ago

a Java application using the Visitor API of the JPMML-Model library.

The Java application way is probably easier - a new AbstractVisitor subclass that prints out a DOT graph vertex every time it visits an org.dmg.pmml.tree.Node object.

I know very little about the Visitor API. Would you help to give me an example? Thanks so much!

vruusmann commented 4 years ago

I know very little about the Visitor API.

It's time to learn something new then!

Would you help to give me an example?

PMML pmml = ...;

System.out.println("digraph PMML {");
Visitor dotPrinter = new AbstractVisitor(){
  @Override
  public VisitorAction visit(Node node){
    List<Node> children = node.getNodes();
    for(Node child : children){
      System.out.println(node.getId() + " -> " child.getId() + ";");
    }
    return super.visit(node);
  }
};
dotPrinter.applyTo(pmml);
System.out.println("}");

Add node attributes as necessary.

XScarlett commented 4 years ago

You are a great man, thank you every much!