Note that there are some explanatory texts on larger screens.

plurals
  1. POweka.core.UnassignedDatasetException when creating an unlabeled instance
    text
    copied!<p>I trained an IBK classifier with some training data that I created manually as following:</p> <pre><code>ArrayList&lt;Attribute&gt; atts = new ArrayList&lt;Attribute&gt;(); ArrayList&lt;String&gt; classVal = new ArrayList&lt;String&gt;(); classVal.add("C1"); classVal.add("C2"); atts.add(new Attribute("a")); atts.add(new Attribute("b")); atts.add(new Attribute("c")); atts.add(new Attribute("d")); atts.add(new Attribute("@@class@@", classVal)); Instances dataRaw = new Instances("TestInstances", atts, 0); dataRaw.setClassIndex(dataRaw.numAttributes() - 1); double[] instanceValue1 = new double[]{3,0,1,0,0}; dataRaw.add(new DenseInstance(1.0, instanceValue1)); double[] instanceValue2 = new double[]{2,1,1,0,0}; dataRaw.add(new DenseInstance(1.0, instanceValue2)); double[] instanceValue3 = new double[]{2,0,2,0,0}; dataRaw.add(new DenseInstance(1.0, instanceValue3)); double[] instanceValue4 = new double[]{1,3,0,0,1}; dataRaw.add(new DenseInstance(1.0, instanceValue4)); double[] instanceValue5 = new double[]{0,3,1,0,1}; dataRaw.add(new DenseInstance(1.0, instanceValue5)); double[] instanceValue6 = new double[]{0,2,1,1,1}; dataRaw.add(new DenseInstance(1.0, instanceValue6)); </code></pre> <p>Then I build up the classifier:</p> <pre><code>IBk ibk = new IBk(); try { ibk.buildClassifier(dataRaw); } catch (Exception e) { e.printStackTrace(); } </code></pre> <p>I want to create a new instance with unlabeled class and classify this instance, I tried the following with no luck.</p> <pre><code>IBk ibk = new IBk(); try { ibk.buildClassifier(dataRaw); double[] values = new double[]{3,1,0,0,-1}; DenseInstance newInst = new DenseInstance(1.0,values); double classif = ibk.classifyInstance(newInst); System.out.println(classif); } catch (Exception e) { e.printStackTrace(); } </code></pre> <p>I just get the following errors</p> <pre><code>weka.core.UnassignedDatasetException: DenseInstance doesn't have access to a dataset! at weka.core.AbstractInstance.classAttribute(AbstractInstance.java:98) at weka.classifiers.AbstractClassifier.classifyInstance(AbstractClassifier.java:74) at TextCategorizationTest.instancesWithDoubleValues(TextCategorizationTest.java:136) at TextCategorizationTest.main(TextCategorizationTest.java:33) </code></pre> <p>Looks like I am doing something wrong while creating a new instance. How can I create an unlabeled instance exactly ?</p> <p>Thanks in Advance</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