问题
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.
回答1:
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!
回答2:
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..!
回答3:
The class index indicates the target attribute used for classification. By default, in an ARFF file, it is the last attribute, which explains why it's set to numAttributes-1.
来源:https://stackoverflow.com/questions/26734189/what-is-class-index-in-weka