You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@samoa.apache.org by "Yu Gong (JIRA)" <ji...@apache.org> on 2016/01/18 03:42:39 UTC

[jira] [Commented] (SAMOA-54) dump or serialize SAMOA learned model

    [ https://issues.apache.org/jira/browse/SAMOA-54?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15104081#comment-15104081 ] 

Yu Gong commented on SAMOA-54:
------------------------------

For example, I can define an interface of Model which can be serialized, and contains the method as predict.

public interface Model extends Serializable {
    double[] predict(Instance inst);
}

And for HoeffdingTreeModel, I can define it as:

public class HoeffdingTreeModel implements Model {
    private Instances dataset;
    private Node treeRoot;

    public HoeffdingTreeModel(Instances dataset, Node treeRoot) {
        this.dataset = dataset;
        this.treeRoot = treeRoot;
    }

    public HoeffdingTreeModel() {
    }

    @Override
    public double[] predict(Instance inst) {
        double[] prediction;
        // inst.setDataset(dataset);

        FoundNode foundNode;
        if (treeRoot != null) {
            foundNode = treeRoot.filterInstanceToLeaf(inst, null, -1);
            Node leafNode = foundNode.getNode();
            if (leafNode == null) {
                leafNode = foundNode.getParent();
            }
            prediction = leafNode.getClassVotes(inst, null);
        } else {
            int numClasses = dataset.numClasses();
            prediction = new double[numClasses];
        }
        return prediction;
    }
}

I can create the HoeffdingTreeModel object in org.apache.samoa.learners.classifiers.trees.ModelAggregatorProcessor, and output the object.

Can you give me some advice about it? Thanks a lot.

> dump or serialize SAMOA learned model
> -------------------------------------
>
>                 Key: SAMOA-54
>                 URL: https://issues.apache.org/jira/browse/SAMOA-54
>             Project: SAMOA
>          Issue Type: New Feature
>          Components: SAMOA-API
>            Reporter: Yu Gong
>
> If I can dump or serialize SAMOA learned model, I could use SAMOA model in an external task. I think it's important.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Re: [jira] [Commented] (SAMOA-54) dump or serialize SAMOA learned model

Posted by Gianmarco De Francisci Morales <gd...@apache.org>.
Hi Yu,

Serialisation of the model is definitely a great feature.
The simplest way to do it is to wait for the end-of-stream event and
serialise the model.
To start with, please have a look at this email thread
http://mail-archives.apache.org/mod_mbox/incubator-samoa-dev/201509.mbox/%3cCAGGcCMtQoboeDNu9_T+pnt0noSb-3RZBaKRf5sks65WLWjrTZQ@mail.gmail.com%3e

It's definitely on the roadmap, and if you want to take a stab at it, it
would be great.

Cheers,

-- Gianmarco

On 18 January 2016 at 05:42, Yu Gong (JIRA) <ji...@apache.org> wrote:

>
>     [
> https://issues.apache.org/jira/browse/SAMOA-54?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15104081#comment-15104081
> ]
>
> Yu Gong commented on SAMOA-54:
> ------------------------------
>
> For example, I can define an interface of Model which can be serialized,
> and contains the method as predict.
>
> public interface Model extends Serializable {
>     double[] predict(Instance inst);
> }
>
> And for HoeffdingTreeModel, I can define it as:
>
> public class HoeffdingTreeModel implements Model {
>     private Instances dataset;
>     private Node treeRoot;
>
>     public HoeffdingTreeModel(Instances dataset, Node treeRoot) {
>         this.dataset = dataset;
>         this.treeRoot = treeRoot;
>     }
>
>     public HoeffdingTreeModel() {
>     }
>
>     @Override
>     public double[] predict(Instance inst) {
>         double[] prediction;
>         // inst.setDataset(dataset);
>
>         FoundNode foundNode;
>         if (treeRoot != null) {
>             foundNode = treeRoot.filterInstanceToLeaf(inst, null, -1);
>             Node leafNode = foundNode.getNode();
>             if (leafNode == null) {
>                 leafNode = foundNode.getParent();
>             }
>             prediction = leafNode.getClassVotes(inst, null);
>         } else {
>             int numClasses = dataset.numClasses();
>             prediction = new double[numClasses];
>         }
>         return prediction;
>     }
> }
>
> I can create the HoeffdingTreeModel object in
> org.apache.samoa.learners.classifiers.trees.ModelAggregatorProcessor, and
> output the object.
>
> Can you give me some advice about it? Thanks a lot.
>
> > dump or serialize SAMOA learned model
> > -------------------------------------
> >
> >                 Key: SAMOA-54
> >                 URL: https://issues.apache.org/jira/browse/SAMOA-54
> >             Project: SAMOA
> >          Issue Type: New Feature
> >          Components: SAMOA-API
> >            Reporter: Yu Gong
> >
> > If I can dump or serialize SAMOA learned model, I could use SAMOA model
> in an external task. I think it's important.
>
>
>
> --
> This message was sent by Atlassian JIRA
> (v6.3.4#6332)
>