Home > Blockchain >  how should i deal with this error on gridsearch and multisearch with pyweka?
how should i deal with this error on gridsearch and multisearch with pyweka?

Time:02-23

I have this code for gridsearch:

from weka.classifiers import GridSearch

data = loader.load_file(data_dir   "bolts.arff")
data.class_is_last()

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(data)
print("Model:\n"   str(grid))
print("\nBest setup:\n"   grid.best.to_commandline())

and it raise to me this error:

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)

also on the case of multisearch i have this code:

from weka.classifiers import MultiSearch


multi = MultiSearch(options=["-S", "1"])           
multi.evaluation = "CC"
mparam = MathParameter()
mparam.prop = "classifier.kernel.gamma"
mparam.minimum = -3.0
mparam.maximum = 3.0
mparam.step = 1.0
mparam.base = 10.0
mparam.expression = "pow(BASE,I)"
lparam = ListParameter()
lparam.prop = "classifier.C"
lparam.values = ["-2.0", "-1.0", "0.0", "1.0", "2.0"]
multi.parameters = [mparam, lparam]
cls = Classifier(
    classname="weka.classifiers.functions.SMOreg",
    options=["-K", "weka.classifiers.functions.supportVector.RBFKernel"])
multi.classifier = cls
multi.build_classifier(data)
print("Model:\n"   str(multi))
print("\nBest setup:\n"   multi.best.to_commandline())

and also rise this error:

Exception in thread "Thread-0" java.lang.ClassNotFoundException: weka.core.setupgenerator.AbstractParameter
...

I saw that everybody just say that to solve this error, you need to install the packages, but i have all installed.

checked with:

items = packages.installed_packages()
for item in items:
    print(item.name   " "   item.url)

that gives me:

gridSearch http://prdownloads.sourceforge.net/weka/gridSearch1.0.12.zip?download
timeseriesForecasting http://prdownloads.sourceforge.net/weka/timeseriesForecasting1.1.27.zip?download
LibSVM http://prdownloads.sourceforge.net/weka/LibSVM1.0.10.zip?download
multisearch https://github.com/fracpete/multisearch-weka-package/releases/download/v2020.2.17/multisearch-2020.2.17.zip

and checked if all packages have installed the latest version and its correct, with:

success, exit_required = install_missing_packages([("gridSearch", LATEST),("multisearch", LATEST)])
if exit_required:
    jvm.stop()
    sys.exit(0)

so I don't know if i should pass of this errors or I should do something.

I have to say that when i execute it, it gives me a solution but also raise this errors so don't know what to do.

Thank you guys.

CodePudding user response:

The exceptions that you listed do not affect the script execution, as they get handled internally by pww3 (error output could not be suppressed, unfortunately, despite catching the exceptions; this gets output by the underlying javabridge library).

A bit of background: Since pww3 can run with and without package support, it first tries to load classes using the Java classloader. If that fails (that's the error message that you see), it will try loading them using Weka's mechanism for loading classes.

The just released version 0.2.7 of pww3 approaches this a bit more intelligent and avoids the output of these exceptions.

Final note: you need to drop the classifier. prefix in your property names when using MultiSearch.

  • Related