Create a new weka Instance

拜拜、爱过 提交于 2019-12-03 21:17:24

If you already have the arff structure available and want to add extra instances , then you can do so by:

 //assuming we already have arff loaded in a variable called dataset
 Instance newInstance  = new Instance();
 for(int i = 0 ; i < dataset.numAttributes() ; i++)
 {

     newInstance.setValue(i , value);
     //i is the index of attribute
     //value is the value that you want to set
 }
 //add the new instance to the main dataset at the last position
 dataset.add(newInstance);
 //repeat as necessary

This link shows you how Weka suggests to build a new instance.

If you want to stick to your code and see if it is working, you could try creating some instances by hand. You could then classify the instances to see if you get the same result as with the instance created using your method.

To create some Instances by hand you would:

  1. Create a physical copy of your existing ".arff" training data
  2. Open the copy with a text editor
  3. Edit and save the X and Y values as you see fit

If these instances are classified differently then the ones you modify with your code, you can be sure that the instances are not being created correctly.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!