0
votes

I am trying to apply the j48 classifier on a dataset, but I am not understanding how to actually select the right attribute as the class. I found a method called class_is_last() which sets the last attribute as the class, but what if I want to select my attribute called say 'name' as the class?

jvm.start()
loader = Loader(classname="weka.core.converters.ArffLoader")
dataweka = loader.load_file("enumeratedremovedtest-arff.arff")
dataarff = arff.load(open('enumeratedremovedtest-arff.arff', 'rb'))

from weka.classifiers import Classifier
dataweka.class_is_last()
cls = Classifier(classname="weka.classifiers.trees.J48", options=["-C","0.25", "-B", "-M", "2"])
print dataweka.class_attribute
cls.build_classifier(dataweka)

print(cls)

jvm.stop()

All required modules have been imported, and this works as expected and uses the last attribute in the list as the class.

2

2 Answers

0
votes

Your question is how to select class index in Weka. First off, Let's see what class index is in here. My suggestion is to use function setClassIndex(int)

0
votes

Let's imagine that attribute "name" is in column 5 of your dataset, you can set the class as:

label = 5    
dataweka.class_index = label - 1