python-weka-wrapper3 M5P 返回 Java 错误

标签 python weka

我正在使用 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

最佳答案

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

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

感谢您报告错误!

关于python-weka-wrapper3 M5P 返回 Java 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45709168/

相关文章:

java - 具有自定义距离的层次聚类

android - 如何在 Weka-for-Android 中反序列化保存的模型

java - 从java对象获取WEKA实例

python - lambda 函数中的 python 和 python-jose 错误

python - 将包含日期信息作为对象的列转换为日期时间时出现问题

python - 如何在 IPython 笔记本中打开交互式 matplotlib 窗口?

java - 在运行时使用 Class.forName 加载 Weka 类

java - 为分类创建实例-Weka

python - Xpath获取标签后面的文本

python - 根据条件合并行