def weka_version(): """ Determines the version of Weka in use. :return: the version :rtype: str """ jobj = JavaObject(JavaObject.new_instance(classname="weka.core.Version")) return str(jobj)
def system_info(): """ Returns a dictionary generated from the output of weka.core.SystemInfo. :return: the system info as dictionary :rtype: dict """ jobj = JavaObject.new_instance("weka.core.SystemInfo") info = javabridge.call(jobj, "getSystemInfo", "()Ljava/util/Hashtable;") return javabridge.jdictionary_to_string_dictionary(info)
def generate_thresholdcurve_data(evaluation, class_index): """ Generates the threshold curve data from the evaluation object's predictions. :param evaluation: the evaluation to obtain the predictions from :type evaluation: Evaluation :param class_index: the 0-based index of the class-label to create the plot for :type class_index: int :return: the generated threshold curve data :rtype: Instances """ jtc = JavaObject.new_instance("weka.classifiers.evaluation.ThresholdCurve") pred = javabridge.call(evaluation.jobject, "predictions", "()Ljava/util/ArrayList;") result = Instances( javabridge.call(jtc, "getCurve", "(Ljava/util/ArrayList;I)Lweka/core/Instances;", pred, class_index)) return result
def main(): """ Just runs some example code. """ # generic JavaObject stuff helper.print_title("Generic stuff using weka.core.SystemInfo") info = JavaObject(JavaObject.new_instance(classname="weka.core.SystemInfo")) jwrapper = info.jwrapper print("toString() method:") print(jwrapper.toString()) # random helper.print_title("Random") rnd = Random(1) for i in range(10): print(rnd.next_double()) for i in range(10): print(rnd.next_int(100)) # single index helper.print_title("SingleIndex") si = SingleIndex(index="first") upper = 10 si.upper(upper) print(str(si) + " (upper=" + str(upper) + ")\n -> " + str(si.index())) si.single_index = "3" si.upper(upper) print(str(si) + " (upper=" + str(upper) + ")\n -> " + str(si.index())) si.single_index = "last" si.upper(upper) print(str(si) + " (upper=" + str(upper) + ")\n -> " + str(si.index())) # range helper.print_title("Range") rng = Range(ranges="first") upper = 10 invert = False rng.upper(upper) rng.invert = invert print(str(rng.ranges) + " (upper=" + str(upper) + ", invert=" + str(invert) + ")\n -> " + str(rng.selection())) rng.ranges = "3" rng.upper(upper) rng.invert = invert print(str(rng.ranges) + " (upper=" + str(upper) + ", invert=" + str(invert) + ")\n -> " + str(rng.selection())) rng.ranges = "last" rng.upper(upper) rng.invert = invert print(str(rng.ranges) + " (upper=" + str(upper) + ", invert=" + str(invert) + ")\n -> " + str(rng.selection())) rng.ranges = "first-last" rng.upper(upper) rng.invert = invert print(str(rng.ranges) + " (upper=" + str(upper) + ", invert=" + str(invert) + ")\n -> " + str(rng.selection())) rng.ranges = "3,4,7-last" rng.upper(upper) rng.invert = invert print(str(rng.ranges) + " (upper=" + str(upper) + ", invert=" + str(invert) + ")\n -> " + str(rng.selection())) rng.ranges = "3,4,7-last" rng.upper(upper) invert = True rng.invert = invert print(str(rng.ranges) + " (upper=" + str(upper) + ", invert=" + str(invert) + ")\n -> " + str(rng.selection())) # tag helper.print_title("Tag") tag = Tag(ident=1, ident_str="one") print("tag=" + str(tag) + ", ident=" + str(tag.ident) + ", readable=" + tag.readable) tag.ident = 3 print("tag=" + str(tag) + ", ident=" + str(tag.ident) + ", readable=" + tag.readable) tag = Tag(ident=2, ident_str="two", readable="2nd tag") print("tag=" + str(tag) + ", ident=" + str(tag.ident) + ", readable=" + tag.readable)
def main(): """ Just runs some example code. """ # generic JavaObject stuff helper.print_title("Generic stuff using weka.core.SystemInfo") info = JavaObject(JavaObject.new_instance("weka.core.SystemInfo")) jwrapper = info.jwrapper print("toString() method:") print(jwrapper.toString()) # random helper.print_title("Random") rnd = Random(1) for i in xrange(10): print(rnd.next_double()) for i in xrange(10): print(rnd.next_int(100)) # single index helper.print_title("SingleIndex") si = SingleIndex(index="first") upper = 10 si.upper(upper) print(str(si) + " (upper=" + str(upper) + ")\n -> " + str(si.index())) si.single_index = "3" si.upper(upper) print(str(si) + " (upper=" + str(upper) + ")\n -> " + str(si.index())) si.single_index = "last" si.upper(upper) print(str(si) + " (upper=" + str(upper) + ")\n -> " + str(si.index())) # range helper.print_title("Range") rng = Range(ranges="first") upper = 10 invert = False rng.upper(upper) rng.invert = invert print(str(rng.ranges) + " (upper=" + str(upper) + ", invert=" + str(invert) + ")\n -> " + str(rng.selection())) rng.ranges = "3" rng.upper(upper) rng.invert = invert print(str(rng.ranges) + " (upper=" + str(upper) + ", invert=" + str(invert) + ")\n -> " + str(rng.selection())) rng.ranges = "last" rng.upper(upper) rng.invert = invert print(str(rng.ranges) + " (upper=" + str(upper) + ", invert=" + str(invert) + ")\n -> " + str(rng.selection())) rng.ranges = "first-last" rng.upper(upper) rng.invert = invert print(str(rng.ranges) + " (upper=" + str(upper) + ", invert=" + str(invert) + ")\n -> " + str(rng.selection())) rng.ranges = "3,4,7-last" rng.upper(upper) rng.invert = invert print(str(rng.ranges) + " (upper=" + str(upper) + ", invert=" + str(invert) + ")\n -> " + str(rng.selection())) rng.ranges = "3,4,7-last" rng.upper(upper) invert = True rng.invert = invert print(str(rng.ranges) + " (upper=" + str(upper) + ", invert=" + str(invert) + ")\n -> " + str(rng.selection())) # tag helper.print_title("Tag") tag = Tag(ident=1, ident_str="one") print("tag=" + str(tag) + ", ident=" + str(tag.ident) + ", readable=" + tag.readable) tag.ident = 3 print("tag=" + str(tag) + ", ident=" + str(tag.ident) + ", readable=" + tag.readable) tag = Tag(ident=2, ident_str="two", readable="2nd tag") print("tag=" + str(tag) + ", ident=" + str(tag.ident) + ", readable=" + tag.readable)