Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In <a href="http://weka.wikispaces.com/Use+WEKA+in+your+Java+code#Classification-Classifying%20instances" rel="nofollow">http://weka.wikispaces.com/Use+WEKA+in+your+Java+code#Classification-Classifying%20instances</a> there is a quick how to for classifying a single instance.</p> <pre><code>//load model (saved from user interface) Classifier tree = (Classifier) weka.core.SerializationHelper.read("/some/where/j48.model"); // load unlabeled data Instances unlabeled = new Instances( new BufferedReader(new FileReader("/some/where/unlabeled.arff"))); // set class attribute unlabeled.setClassIndex(unlabeled.numAttributes() - 1); // create copy Instances labeled = new Instances(unlabeled); // label instances for (int i = 0; i &lt; unlabeled.numInstances(); i++) { double clsLabel = tree.classifyInstance(unlabeled.instance(i)); labeled.instance(i).setClassValue(clsLabel); System.out.println(clsLabel + " -&gt; " + unlabeled.classAttribute().value((int) clsLabel)); double[] dist =tree.distributionForInstance(unlabeled.instance(i)) for(int j=0; j&lt;dist.length;j++){ System.print(unlabeled.classAttribute().value(j)+": " +dist[j]); } } </code></pre> <p><strong>Edit</strong> This method doesn't train, evaluate and save a model. This is something I usually do using the weka gui. ( <a href="http://weka.wikispaces.com/Serialization" rel="nofollow">http://weka.wikispaces.com/Serialization</a> ) This method uses a tree type model in the example with a nominal class, but that should be easily converted to a Naive Bayes example.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload