Can’t access random forest learner methods (follow up)

Hello everyone,

as a follow up to my previous post, is there any way to test my node in a real KNIME environment? In my development environment the node runs perfectly, but in my standard KNIME distribution (3.7), the node doesn’t work because of the not (yet) exported packages.

Best wishes,
Morris

The only way to fully test nodes is to install your extension in a real KNIME installation.

The problem is that the necessary packages in the treeensembles2 package are not exported yet, so I can’t get my node to run in a real KNIME installation. My question was if there is a way around that until the packages are exported.

Hi @Morris_Kurz,
I think there might be a little misunderstanding going on I am sorry if my previous post was not clear. I advised you to just copy the tree ensemble learning code you need into your plugin. As this is plugin internal code, there is no guarantee that it won’t change in the future in ways that would break your nodes. Is there a specific reason that prevents you from doing this?

best,
Gabriel

Hey @gab1one,
I guess I misunderstood you, sorry for that. So I tried to copy the code into my project and I still receive the error “loader constraint violation: loader (instance of org/eclipse/osgi/internal/loader/EquinoxClassLoader) previously initiated loading for a different type with name “org/knime/base/node/mine/treeensemble2/node/learner/TreeEnsembleLearnerConfiguration””. Should I rename the corresponding classes? I wish I would understand more of the underlying architecture, but since I don’t I need to come to you for help. Thanks again for everything!

Best,
Morris

You can either rename the class, or just change the package name, e.g add a toplevel package external and put all code you copied from the treeensemble plugin in that.

So suppose I copied the source code in such a toplevel package external and now I get as node input a TreeEnsembleModelPortObject from the original treeensemble2 package. How do I transform this object and all its generated objects, which reside in the original package, to my copied version so I can work with it? Or am I understanding it wrong?

To shed more light on my situation, I have one node which is already built upon the treeensemble2 package. I added additional functionality by creating a new PredictionParser. To access some of the non-accessible code in the treeensemble2 package, I imported the 3.6 version as a .jar and imported the necessary packages from there. Now I want to create an additional node based upon this node, where I learn a random forest on a certain dataset and then use the PredictionParser I implemented. Because I want a certain custom configuration for the learner, I copied the code from the TreeEnsembleRegressionLearnerNodeModel. I thought it would work if I continued as before, by importing the code from the included .jar-package and then going about my business, but then this loader constraint turned up which I don’t really understand. It seems that in the class TreeDataCreator, there are two versions of the class TreeEnsembleLearnerConfiguration present, which I can’t resolve. If you have any tips I would greatly appreciate them!

Best,
Morris

I am sure we will find a way to make this work :slight_smile:

This happens because you are mixing dependencies, where you include the same class via the jar and the plugin dependency. This is not allowed by OSGi and therefore won’t work.
Maybe you can share the source code of your project with us? I might be able to figure out what is going wrong.

best,
Gabriel

1 Like

Sadly I don’t think I am allowed to, but I modified the example node provided by KNIME to showcase my problem. You can find the code here. Simply connect a dataset with a column “Class Numeric” to it (here I hardcoded the column name because it is meant as an example) and run the node. The project setup is more or less equivalent with the situation I have in my own node. Now here I could simply copy the treeensemble2 code as you mentioned, but I need the resulting PredictorRecord and TreeEnsembleModel to be from the original treeensemble2 package so I can pass it to a PredictionItemParser.

Hi @Morris_Kurz,
I am sorry for the delayed answer, I am at a conference this week. I took a look at your example and the problem is definitely caused by the fact that you have the same classes twice on your classpath.

I don’t think there is an easy workaround for you right now, I will talk to my colleagues about how to help you with this.
What you can do in the meantime is to create a copy of the treeensemble plugin that exports the classes you need or that you add your classes to. This copy has to have a different package name, e.g. org.knime.morris.treeensembles … you can then install this plugin into a KNIME Analytics Platform and use that with your nodes.

best,
Gabriel

1 Like

Hey @gab1one,

yes, I had the same idea regarding the temporary workaround. Thanks again for all your help! Can you reach out to me via email or via forum regarding any news?

Best wishes,
Morris