Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create an `Instances` in Weka from a `List<Instance>`?

I am using Weka as a part of a much longer pipeline, and as a result, I can't afford to write all the data to a file or database just to create an Instances object. What I can do on-the-fly is to create a list of Instance objects.

From this page of their API I can see that Instances implements List<Instance>, but Weka doesn't seem to have a public constructor that will take a List<Instance> as argument. I tried a crude casting as well:

List<Instance> instanceList;
while ( ... ) {         // some conditional loop
    Instance inst = ... // more code where I am populating an individual instance
    instanceList.add(inst);
}
Instances instances = (Instances) instanceList;

In the last line above, Idea Intellij shows me a warning that I may run into a ClassCastException. How can I safely create Instances from my individual Instance objects?

like image 537
Chthonic Project Avatar asked Dec 10 '25 19:12

Chthonic Project


1 Answers

You have to create one using this constructor, and then add them one by one to the new Instances object.

Or switch to not Weka.

like image 120
Raff.Edward Avatar answered Dec 12 '25 07:12

Raff.Edward



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!