How to save a model (that is a predictor) and use it in your Java code?


When using Weka, you can train a classifier, save the model, and then use it in your Java code. Does KNIME provide a similar functionality? If so, where can I find it documented? Thanks!

You can write out the trained classifier or clustering model into a file using the Weka Classifier or Weka Cluster Writer nodes. However, those nodes only write out the KNIME internal Weka format which Weka won't understand. Alternatively, you can check out the KNIME SDK (for developers) and look at the Reader code for this models inside the org.knime.ext.weka plug-in.

Thank you Gabriel, that is definitiely a starting point. However, it seems that this applies to Weka nodes, only. What about KNIME nodes, can I write these models into a file that can be called from within a Java program?

Yes, most of the data mining nodes support PMML 4.1 which can be written out with the PMML Writer and read back with the PMML Reader. This format can be understood by various applications, and you could write your own Java code to consume PMML. The same is true here, check out our PMML code available in the KNIME SDK which gives a good starting point for writing your own PMML Java code/node.