[ 
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)

Reply via email to