Using+Weka+via+Jepp

toc

Jepp embeds [|CPython] in Java. It is safe to use in a heavily threaded environment, it is quite fast and its stability is a main feature and goal.

//--taken from the [|Jepp homepage]//

= Prerequisites =
 * Java 6 (jepp makes use of the package)
 * Jepp 2.2 or higher
 * [|suggested fix] for the //missing sys.argv// problem

= Limitations = Jepp doesn't seem to be able to import third-party libraries like, or  (pure Python modules can be imported, though).

= Accessing Weka classes within Jepp = Java classes are imported in one's Python script as follows: code format="python" from import code E.g., importing J48 looks like this: code format="python" from weka.classifiers.trees import J48 code In the following a little example script for loading a dataset, cross-validating J48 with it and outputting the results of the cross-validation in the console: code format="python" from weka.core import Instances from weka.classifiers import Evaluation from weka.classifiers.trees import J48 from java.io import BufferedReader from java.io import FileReader from java.util import Random reader = BufferedReader(FileReader('/some/where/file.arff')) data  = Instances(reader) data.setClassIndex(data.numAttributes - 1) reader.close j48 = J48 eval = Evaluation(data) rand = Random(1) eval.crossValidateModel(j48, data, 10, rand) print eval.toSummaryString code The script can be started like this (you will have to adjust the paths for the jars and the Python script): code format="bash" java -classpath jep.jar:weka.jar some_script.py code
 * 1) import classes
 * 1) load data
 * 1) train classifier
 * 1) output summary

= See also =
 * Use Weka in your Java code - for general information on how to use the Weka API
 * Using Weka from Jython

= Links =
 * [|Jepp homepage]
 * [|Python homepage]
 * [|Linux.com] - more examples