weka.core.UnassignedDatasetException when creating an unlabeled instance

前端 未结 3 381
迷失自我
迷失自我 2020-12-31 08:03

I trained an IBK classifier with some training data that I created manually as following:

ArrayList atts = new ArrayList();         


        
3条回答
  •  南笙
    南笙 (楼主)
    2020-12-31 08:57

    The problem is with this line:

    double classif = ibk.classifyInstance(newInst);
    

    When you try to classify newInst, Weka throws an exception because newInst has no Instances object (i.e., dataset) associated with it - thus it does not know anything about its class attribute.

    You should first create a new Instances object similar to the dataRaw, add your unlabeled instance to it, set class index, and only then try classifying it, e.g.:

    Instances dataUnlabeled = new Instances("TestInstances", atts, 0);
    dataUnlabeled.add(newInst);
    dataUnlabeled.setClassIndex(dataUnlabeled.numAttributes() - 1);        
    double classif = ibk.classifyInstance(dataUnlabeled.firstInstance());
    

提交回复
热议问题