Re: simplest of code

Bob Matthews <[email protected]>
Newsgroups gmane.comp.ai.weka
Message-ID <[email protected]>
Thanks Peter for the pointers.................

******************************************************************

private class WekaApp {

void doIt() throws Exception {
WekaApp wekaApp= new WekaApp();
       try{
               currentInstance();
           }
           catch (Exception e)
           {
               System.out.println("ERROR: "+ e);
               e.printStackTrace(myConsole.getOut()); // show the stack 
trace
           }

} //end of doIt()

void currentInstance() throws Exception {
try {
// [A] load model and header of data
// deserialize model

Classifier cls = (Classifier) 
weka.core.SerializationHelper.readAll("/somewhere/j48model");

// [B] create an Instances object on the fly and save it to an ARFF file

data = new Instances("MyRelation", atts, 0);

// create the current instance
      values = new double[data.numAttributes()];
// - numeric
      values[0] = OSV;
setDataset(currentInstance);

// [C] classify nominal class

// classifyInstance() just returns the index of the predicted label (the 
one with the highest probability) as a double
prediction = classifyInstance(currentInstance);
// myConsole.getOut().println("prediction: "+ prediction);
}
catch (Exception e)
{
     e.printStackTrace(myConsole.getOut()); // show the stack trace
     myConsole.getOut().println("Weka exception occurred: "+ e);
}

} // end of currentIcurrentstance

} // end of class WekaApp

******************************************************************

Have errors with 'currentInstance' and 'vals'

Bob M

On 11/8/2021 11:51 AM, Peter Reutemann wrote:
>> I am viewing one minute data from the forex market in real time
>>
>> At certain times I wish to
>>
>> 1) recall a saved model
> Use the weka.core.SerializationHelper helper class to load model and
> header of data it was trained with ("readAll" method):
> https://waikato.github.io/weka-wiki/serialization/
>
>> 2) present it with one new instance which comprises just one real variable
> The following article describes how to create an Instances object on
> the fly and saving it to an ARFF file. Since you are loading the
> header (ie empty Instances object) with your model, you can skip
> straight to creating Instance objects ("first instance"). You don't
> need to add the Instance to the Instances (ie header), simply
> reference the header information via "setDataset(Instances)":
> https://waikato.github.io/weka-wiki/formats_and_processing/creating_arff_file/
>
>> 3) have the model do a prediction based on this new instance
> Not sure whether your class is numeric or nominal, so you can either
> use the model's:
> - classifyInstance method to obtain regression value or class label index
> - distributionForInstance method to obtain class distribution
>
> Cheers, Peter
_______________________________________________
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.