Re: How to classify unseen multi instance data?

Peter Reutemann <[email protected]> Mon, 29 Jan 2024 16:11:57 +1300
Newsgroups gmane.comp.ai.weka
Message-ID <CAHoQ12LuYod_dqqew41TvEDfSCz7Tq-g3wuXeEkFkPAOL_1yEA@mail.gmail.com>
> > At prediction time you re-use (rather than re-create) the header from
> > the training data to create new Instance objects. These Instance
> > objects you then present to the classifier to obtain predictions.
>
> Are there any examples for how this procedure works with multi-instance
> data?

There is no difference to non-multi-instance data.
The wiki example demonstrates how to fill a relational attribute with
values (I may have already posted that before):
https://waikato.github.io/weka-wiki/formats_and_processing/creating_arff_file/

> I am using a DatabaseLoader to load the header. Unfortunately calling
> loader.getStructure() does not work due to a bug in Weka,

What's the bug?

> so I have to
> use loader.getDataSet() and subsequently delete all Instances, which
> will leave me with just the header. But then I need to add all
> Attributes, because they are not contained in the header. This is
> basically the same procedure I previously did in training.
>
> Maybe what you mean is that after training I should somehow save the
> header to the database and reload it later? So that I would already have
> all the attributes? Or do you mean that the header is contained in the
> Classifier and I could get it from there after loading the trained
> Classifier?

It depends. If you've saved a model with the Explorer, then it would
contain the header (an empty Instances object with the structure) as
the second object in the serialized file.
You could use the readAll method of the weka.core.SerializationHelper
class to read such a model in and then cast the array elements
accordingly:
https://weka.sourceforge.io/doc.dev/weka/core/SerializationHelper.html#readAll-java.io.InputStream-
For saving a model (and its header), you would use the writeAll method
(model and header as the two array elements):
https://weka.sourceforge.io/doc.dev/weka/core/SerializationHelper.html#writeAll-java.io.OutputStream-java.lang.Object:A-

If you don't actually save your model anywhere, but just keep in
memory, then you would create an empty copy of the training data with
something like:
Instances train = ...  // your training data
Instances header = new Instances(train, 0);

> > Yes and no. Whilst it would be nice to determine this via the Java
> > type, the general RELATIONAL attribute is column-based and not
> > row-based (and we already have DenseInstance and SparseInstance row
> > types). The idea behind the attribute is to represent data from a
> > relational database. But, this attribute can also be used to represent
> > the simpler multi-instance data, by encapsulating the bag in such an
> > attribute.
>
> Why does it matter where the data is coming from (relational database or
> files or maybe an external API)? And what is the difference in terms of
> internal structure between "simpler multi-instance data" and "data from
> a relational database"? In the documentation I found only one type of
> multi-instance data and that is the "bag" type.

You can think of multi-instance data as of a join between two tables.
The first one contains the bagid and the class, the second the bagid
and the attributes that are part of the bag.
The more general relational database (star schema) would not just have
one table attached to the central table, but multiple. You'd therefore
get multiple "bags" of varying shapes and sizes. Hence, multi-instance
data is "simpler".

> > The RELAGGS filter is specifically designed for processing data from a
> > relational database (the original code worked straight off JDBC
> > databases):
> > https://weka.sourceforge.io/doc.stable/weka/filters/unsupervised/attribute/RELAGGS.html
>
> Are there any examples how to use this filter in Java? What kind of
> processing does it do?

You can apply it straight to your multi-instance data. Works just like
any other filter.

Cheers, Peter
-- 
Peter Reutemann
Dept. of Computer Science
University of Waikato, Hamilton, NZ
Mobile +64 22 190 2375
https://www.cs.waikato.ac.nz/~fracpete/
http://www.data-mining.co.nz/
_______________________________________________
Wekalist mailing list -- [email protected]
Send posts to [email protected]
To unsubscribe send an email to [email protected]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html