WEKA J48 Classifier Example Using Jython
“”“ Jython-WEKA data mining example Author: Pradeep Kishore Gowda This Program demonstrates the use of Simple Classification Algorithm (Using j48 decision Tree) on Iris Data set “”“ import java.io.FileReader as FR import weka.core.Instances as Instances import weka.classifiers.trees.J48 as J48file = FR('iris.arff’) data = Instances(file) “”“ The sample data reads like this
- Load Data File
relation irisattribute sepallength numericattribute sepalwidth numericattribute petallength numericattribute petalwidth numericattribute class {Iris-setosa,Iris-versicolor,Iris-virginica} @data 5.1,3.5,1.4,0.2,Iris-setosa “”“ #set the class Index – the index of the dependent variable data.setClassIndex(4) #create the model j48 = J48 j48.buildClassifier(data) #print out the built model print j48#.toString Internally. ?
- you do not have to call the j48.toString(),
- My guess is Python’s default str method calls
myinstance = data.instance(0) klass = j48.classifyInstance(myinstance) #0.0 #what does 0.0 mean? print data.attribute(data.classIndex()).value(klass) #'Iris-setosa’
- let us classify an instance and verify the result
Update: This thread on wekalist gives a similar example.
— 29 Nov 2005 (updated 04 Nov 2008) • machine-learning code weka python jython j-48 decision-trees