【问题标题】:python-weka-wrapper3 M5P return Java ERROrpython-weka-wrapper3 M5P 返回 Java 错误
【发布时间】:2018-01-24 08:06:05
【问题描述】:

我正在使用 python-weka-wrapper3。在尝试运行分类器 M5P 时,我得到了下一个异常:

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

【问题讨论】:

    标签: python weka


    【解决方案1】:

    Java 库 mtl.jarcore.jararpack_combined_all.jar 按原样添加到 3.9.1 版本中的 weka.jar(来自 sourceforge.net 的 zip 存档),而不是向其中添加它们的内容。重新打包 weka.jar 以解决此问题并发布新版本:

    • python-weka-wrapper: 0.3.11
    • python-weka-wrapper3: 0.1.3

    感谢您报告错误!

    【讨论】:

    • 感谢您的帮助。但是我现在遇到了一个新问题。对于同样的classifier.py代码,我在pycharm中可以很好的运行,但是在jupyter中运行会报错。我使用相同的 python 解释器。错误是 \\packages/javabridge/jutil.py", line 312, in start_vm raise RuntimeError("Failed to start Java VM") RuntimeError: Failed to start Java VM
    • 从未在 Jupyter 中尝试过。但是jvm只能在一个进程中启动一次。也许这就是你的问题。
    猜你喜欢
    • 1970-01-01
    • 2019-05-19
    • 2021-12-08
    • 2016-10-30
    • 1970-01-01
    • 1970-01-01
    • 2013-07-20
    • 1970-01-01
    • 2017-11-04
    相关资源
    最近更新 更多