if the elements are just nominal or string values we can use Instance object to represent that particular instance. Also for the Instances dataset we can get attributes by pre-defining them. But i have question. what is the approach if we want to use collections as values to the attribute elements?
for ex:
weka.core.Attribute attribute1 = new weka.core.Attribute("list1");
weka.core.Attribute attribute2 = new weka.core.Attribute("list2");
weka.core.Attribute classAttribute = new weka.core.Attribute("Function");
FastVector fvWekaAttributes = new FastVector(3);
fvWekaAttributes.addElement(attribute1);
fvWekaAttributes.addElement(attribute2);
fvWekaAttributes.addElement(classAttribute);
is the way we create the attributes if two are nominal values and one is string(class). and the way we 开发者_高级运维add elements in to any dataset(ex:trainInstances), we create Instance object and add like this:
Instance iExample = new Instance(3);
iExample.setValue((weka.core.Attribute)fvWekaAttributes.elementAt(0), 10);
iExample.setValue((weka.core.Attribute)fvWekaAttributes.elementAt(0), 15);
iExample.setValue((weka.core.Attribute)fvWekaAttributes.elementAt(2), "F1");
trainInstances.add(iExample);
this is ok, but what should i use to store Lists/collections instead of single nominal values. I want to do like this:
int[] list1={10,20,30,40};
int[] list2={90,80,70,60};
iExample.setValue((weka.core.Attribute)fvWekaAttributes.elementAt(0), **list1**);
iExample.setValue((weka.core.Attribute)fvWekaAttributes.elementAt(0), **list2**);
iExample.setValue((weka.core.Attribute)fvWekaAttributes.elementAt(2), "F1");
trainInstances.add(iExample);
to be more specific, these lists might change their sizes sometimes. i..e, in this example we see each list of length 4 in size but should support lists of different sizes in other Instance objects. Is that possible using WEKA or any learning API. If so, please provide me the resources. It is mandatory to my master thesis..
In order to keep their Instances (dataset) objects as compact as possible, weka uses an index-value method to represent each value of a string or nominal Attribute. Each weka Instance (row in a dataset) only stores the index associated with the value for the attribute.
You are probably going to have to decide if the list element (as a whole) is more important that the individual elements of the list. If so, you will need to enumerate each of the possible lists that can occur as a value for that Attribute, and this list will need to be provided to the Attribute when it is created. If this is reasonable, you may decide to convert the lists to strings (i.e. list1="10,20,30,40").
If the individual elements of the list have value, it may be easier to create separate Attributes to identify if elements occur in the list or not.
If there is a fixed limit to the number of elements that occur in a list (and especially if the order of the list is important), you may consider having a separate Attribute for each list element. (i.e. Attibute("first_element_of_list"), Attribute("second_element_of_list"), ... etc)
If there is a fixed number of values that may occur on those lists and/or if the order is not important, you may consider having boolean Attribute to indicate if a specified element occurs in the list. (i.e. Attribute("10_in_list"), Attribute("20_in_list"), ... etc)
精彩评论