MOA Tutorial 2 Listing 1

112 views
Skip to first unread message

关洪涛

unread,
Dec 22, 2015, 10:07:14 PM12/22/15
to MOA users
I am trying to run Listing1 in eclipse. I meet some trouble

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
Type mismatch: cannot convert from InstanceExample to Instance

at test.Exercise2_1.main(Exercise2_1.java:24)


package test;

import com.yahoo.labs.samoa.instances.Instance;

import moa.classifiers.Classifier;
import moa.classifiers.trees.HoeffdingTree;
import moa.core.InstanceExample;
import moa.streams.generators.RandomRBFGenerator;

public class Exercise2_1 {
public static void main(String[] args) {
int numInstances =10000;
Classifier learner=new HoeffdingTree();                                               
RandomRBFGenerator stream=new RandomRBFGenerator();                                   
stream.prepareForUse();                                                             
                                                                                   
learner.setModelContext(stream.getHeader());                                        
learner.prepareForUse();                                                            
                                                                                   
int numberSamplesCorrect=0;                                                          
int numberSamples=0;                                                                 
boolean isTesting=true;                                                              
while(stream.hasMoreInstances()&&numberSamples<numInstances){
24: Instance trainInst=stream.nextInstance();                                            
   if(isTesting){                                                                      
if(learner.correctlyClassifies(trainInst)){                                        
numberSamplesCorrect++; 
}
   }
numberSamples++;                                                                    
learner.trainOnInstance(trainInst);                                                 
}
double accuracy=100.0*(double)numberSamplesCorrect/(double)numberSamples;            
System.out.println(numberSamples+" instances processed with"+accuracy+"% accuracy");
}
}

Albert Bifet

unread,
Dec 23, 2015, 3:29:08 PM12/23/15
to MOA users
With the new version of MOA that uses the new instances, there are two ways:

- change line 24 to

Instance trainInst=stream.nextInstance(
).getData();

-  or change line 24 to

InstanceExample trainInst=stream.nextInstance();   

and also

if(learner.correctlyClassifies(trainInst.getData())){   

Cheers, Albert

  

--
You received this message because you are subscribed to the Google Groups "MOA users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to moa-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Maxbest

unread,
Dec 23, 2015, 8:12:24 PM12/23/15
to MOA users, abi...@waikato.ac.nz
thank you very much ^_^

在 2015年12月24日星期四 UTC+8上午4:29:08,Albert Bifet写道:
Reply all
Reply to author
Forward
0 new messages