GridSearch 问题 Python-weka-wrapper3

Problem Python-weka-wrapper3 with GridSearch

您好,我在使用这段代码时遇到问题,我正在尝试进行网格搜索以优化某些属性

from weka.classifiers import GridSearch

grid = GridSearch(options=["-sample-size", "100.0", "-traversal", "ROW-WISE", "-num-slots", "1", "-S", "1"])
grid.evaluation = "CC"
grid.y = {"property": "kernel.gamma", "min": -3.0, "max": 3.0, "step": 1.0, "base": 10.0, "expression": "pow(BASE,I)"}
grid.x = {"property": "C", "min": -3.0, "max": 3.0, "step": 1.0, "base": 10.0, "expression": "pow(BASE,I)"}
cls = Classifier(
    classname="weka.classifiers.functions.SMOreg",
    options=["-K", "weka.classifiers.functions.supportVector.RBFKernel"])
grid.classifier = cls
grid.build_classifier(train)
print("Model:\n" + str(grid))
print("\nBest setup:\n" + grid.best.to_commandline())

我遇到了这个问题:

Failed to get class weka.classifiers.meta.GridSearch

Exception in thread "Thread-0" java.lang.NoClassDefFoundError: weka.classifiers.meta.GridSearch

Caused by: java.lang.ClassNotFoundException: weka.classifiers.meta.GridSearch
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
/tmp/ipykernel_11771/802912337.py in <module>
      9     options=["-K", "weka.classifiers.functions.supportVector.RBFKernel"])
     10 grid.classifier = cls
---> 11 grid.build_classifier(train)
     12 print("Model:\n" + str(grid))
     13 print("\nBest setup:\n" + grid.best.to_commandline())

NameError: name 'train' is not defined


有什么建议吗?

GridSearch and MultiSearch 元分类器可通过 Weka 包获得,它们不是核心 Weka 发行版的一部分。为了使用它们,您需要安装相应的软件包。

如果您想将 pww3 用于 installing/managing 软件包,请查看 examples on packages