weka.core.UnassignedDatasetException when creating an unlabeled instance

前端 未结 3 380
迷失自我
迷失自我 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 09:02

    You will see this error, when you classify a new instance which is not associated with a dataset. You have to associate every new instance you create to an Instances object using setDataset.

    //Make a place holder Instances
    //If you already have access to one, you can skip this step
    Instances dataset = new Instances("testdata", attr, 1);
    dataset.setClassIndex(classIdx);
    
    DenseInstance newInst = new DenseInstance(1.0,values);
    
    //To associate your instance with Instances object, in this case dataset
    newInst.setDataset(dataset); 
    

    After this you can classify newly created instance.

    double classif = ibk.classifyInstance(newInst);
    

    http://www.cs.tufts.edu/~ablumer/weka/doc/weka.core.Instance.html

    Detailed Implementation Link

提交回复
热议问题