I have to use WEKA in my java code for prediction. Basically I have to study a given code and reuse it.
testdata.setClassIndex(data.numAttributes() - 1);
I am unable to understand what the above line means. What is a Class Index?
testdata
and data
are Intances object.
This type of attribute represents a dynamically expanding set of nominal values. String attributes are not used by the learning schemes in Weka. They can be used, for example, to store an identifier with each instance in a dataset.
A classifier identifies an instance's class, based on a training set of data. Weka makes it very easy to build classifiers. There are many different kinds, and here we use a scheme called “J48” (regrettably a rather obscure name, whose derivation is explained at the end of the video) that produces decision trees.
java.lang.Object | +----weka.core.Instance public class Instance extends Object implements Copyable, Serializable. Class for handling an instance. All values (numeric, nominal, or string) are internally stored as floating-point numbers.
The process of converting a real-valued attribute into an ordinal attribute or bins is called discretization. You can discretize your real valued attributes in Weka using the Discretize filter.
As outlined here, setClassIndex is used to define the attribute that will represent the class (for prediction purposes). Given that the index starts at zero, data.numAttributes() - 1 represents the last attribute of the testdata set.
Hope this Helps!
When you use a classifier to classify a set of data to some class values, you gives an instance which has attributes of the data and an attribute which has the class values. For a example think you have set of e-mails as data, you have to classify those into spam/not-spam. So your class attribute has two class values(spam,not-spam).
Usually, the class attribute add as the last attribute of the instance(not a must). So you have to indicate the classifier which attribute is the class attribute and which are other attributes. So the line you mentioned does this job. Indicating what is the class index of your data instances object.
If you want more explanation, please post your code here. cheers..!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With