2017-08-16 13 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