2017-08-16 50 views
3

我正在使用python-weka-wrapper3。当试图运行分类M5P,我得到了一个异常:python-weka-wrapper3 M5P返回Java ERROr

Training M5P classifier on iris 
=============================== 
Exception in thread "Thread-0" java.lang.NoClassDefFoundError: no/uib/cipr/matrix/Matrix 
     at weka.classifiers.trees.m5.M5Base.getCapabilities(M5Base.java:433) 
     at weka.classifiers.trees.m5.M5Base.buildClassifier(M5Base.java:445) 
Caused by: java.lang.ClassNotFoundException: no.uib.cipr.matrix.Matrix 
     at java.net.URLClassLoader.findClass(URLClassLoader.java:381) 
     at java.lang.ClassLoader.loadClass(ClassLoader.java:424) 
     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) 
     at java.lang.ClassLoader.loadClass(ClassLoader.java:357) 
     ... 2 more 
Traceback (most recent call last): 
    File "classifiers.py", line 272, in <module> 
    main() 
    File "classifiers.py", line 83, in main 
    classifier.build_classifier(iris_data) 
    File "/home/v-yuan15/software/anaconda3/lib/python3.6/site-packages/weka/classifiers.py", line 82, in build_classifier 
    javabridge.call(self.jobject, "buildClassifier", "(Lweka/core/Instances;)V", data.jobject) 
    File "/home/v-yuan15/software/anaconda3/lib/python3.6/site-packages/javabridge/jutil.py", line 885, in call 
    result = fn(*nice_args) 
    File "/home/v-yuan15/software/anaconda3/lib/python3.6/site-packages/javabridge/jutil.py", line 852, in fn 
    raise JavaException(x) 
javabridge.jutil.JavaException: no/uib/cipr/matrix/Matrix 

我只是使用的代码https://github.com/fracpete/python-weka-wrapper3-examples/blob/master/src/wekaexamples/classifiers/classifiers.py并更改分类器M5P和数据集的数据源bodyfat.arff。 我的代码是

# load a dataset 
    bodyfat_file = helper.get_data_dir() + os.sep + "bodyfat.arff" 
    helper.print_info("Loading dataset: " + bodyfat_file) 
    loader = Loader("weka.core.converters.ArffLoader") 
    bodyfat_data = loader.load_file(bodyfat_file) 
    bodyfat_data.class_is_last() 

    # classifier help 
    helper.print_title("Creating help string") 
    classifier = Classifier(classname="weka.classifiers.trees.M5P",options=["-M","4.0"]) 
    print(classifier.to_help()) 
    helper.print_title("Training M5P classifier on bodyfat") 
    # classifier = Classifier(classname="weka.classifiers.trees.J48") 
    # Instead of using 'options=["-C", "0.3"]' in the constructor, we can also set the "confidenceFactor" 
    # property of the J48 classifier itself. However, being of type float rather than double, we need 
    # to convert it to the correct type first using the double_to_float function: 
    # classifier.set_property("confidenceFactor", types.double_to_float(0.3)) 
    # classifier.set_property("confidenceFactor", 0.3) 
    classifier.build_classifier(bodyfat_data) 
    print(classifier) 
    print(classifier.graph) 
    plot_graph.plot_dot_graph(classifier.graph) 

和我的Java环境是:

openjdk version "1.8.0_102" 
OpenJDK Runtime Environment (build 1.8.0_102-8u102-b14.1-1~bpo8+1-b14) 
OpenJDK 64-Bit Server VM (build 25.102-b14, mixed mode) 

echo $JAVA_HOME 
/usr/lib/jvm/java-1.8.0-openjdk-amd64 

回答

0

的Java库mtl.jarcore.jararpack_combined_all.jar添加为的就是能在weka.jar在SourceForge上3.9.1版本(zip压缩包.net)而不是将它们的内容添加到它。重新包装weka.jar来解决这个问题,取得了新的版本:

  • 蟒蛇,秧鸡,包装:0.3.11
  • 蟒蛇,秧鸡,wrapper3:0.1.3

感谢报告这个错误!

+0

感谢您的帮助。但我现在有一个新问题。对于相同的classifier.py代码,我可以在pycharm中很好地运行它,但是它会在jupyter中运行时报告错误。我使用相同的Python解释器。错误是\\ packages/javabridge/jutil.py“,第312行,在start_vm中 raise RuntimeError(”启动Java VM失败“) RuntimeError:未能启动Java VM –

+0

从未在Jupyter中试过它但jvm只能在一个过程中启动一次,也许这就是你的问题。 – fracpete