Peter Reutemann
unread,Dec 1, 2024, 3:53:12 PM12/1/24Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to python-we...@googlegroups.com
> I'm trying to use the python-weka-wrapper3 for the following call:
> weka.classifiers.meta.Bagging -P 100 -S 1 -num-slots 1 -I 10 -W weka.classifiers.functions.SMO -- -C 1.0 -L 0.001 -P 1.0E-12 -N 0 -V -1 -W 1 -K "weka.classifiers.functions.supportVector.PolyKernel -E 1.0 -C 250007"
>
> This way it worked fine for me:
> cmdline = 'weka.classifiers.meta.Bagging -P 100 -S 1 -num-slots 1 -I 10 -W weka.classifiers.functions.SMO -- -C 1.0 -L 0.001 -P 1.0E-12 -N 0 -V -1 -W 1 -K "weka.classifiers.functions.supportVector.PolyKernel -E 1.0 -C 250007"'
> classifier = from_commandline(cmdline, classname="weka.classifiers.Classifier")
>
> But I couldn't make it to adapt it to the options list, which would be my prefered way to instantiate the classifier.
>
> This I tried:
> classifier = Classifier(classname='weka.classifiers.meta.Bagging')
> classifier.options = [
> '-P', '100',
> '-S', '1',
> '-num-slots', '1',
> '-I', '10',
> '-W', 'weka.classifiers.functions.SMO',
> '--', '-C', '1.0',
> '-L', '0.001',
> '-P', '1.0E-12',
> '-N', '0',
> '-V', '-1',
> '-W', '1',
> '-K', '\"weka.classifiers.functions.supportVector.PolyKernel',
> '-E', '1.0',
> '-C', '250007\"'
> ]
> Gives me a Quote parse error.
You've split the atomic string of options for the kernel, hence the
quote parse error.
> classifier = Classifier(classname='weka.classifiers.meta.Bagging')
> classifier.options = [
> '-P', '100',
> '-S', '1',
> '-num-slots', '1',
> '-I', '10',
> '-W', 'weka.classifiers.functions.SMO',
> '--', '-C', '1.0',
> '-L', '0.001',
> '-P', '1.0E-12',
> '-N', '0',
> '-V', '-1',
> '-W', '1',
> '-K', '\"weka.classifiers.functions.supportVector.PolyKernel -E 1.0 -C 250007\"'
> ]
> This gives me a java.lang.ClassNotFoundException: weka.classifiers.functions.supportVector.PolyKernel -E 1.0 -C 250007
You would need to remove the backslashes around the kernel options.
You don't have to split these options yourself, you can let Weka do
that for you. E.g., using the "split_options" method (module:
weka.core.classes):
import weka.core.jvm as jvm
from weka.core.classes import split_options
jvm.start()
cmdline = 'weka.classifiers.meta.Bagging -P 100 -S 1 -num-slots 1 -I
10 -W weka.classifiers.functions.SMO -- -C 1.0 -L 0.001 -P 1.0E-12 -N
0 -V -1 -W 1 -K "weka.classifiers.functions.supportVector.PolyKernel
-E 1.0 -C 250007"'
parts = split_options(cmdline)
for part in parts:
print(part)
jvm.stop()
The above code will output the following:
weka.classifiers.meta.Bagging
-P
100
-S
1
-num-slots
1
-I
10
-W
weka.classifiers.functions.SMO
--
-C
1.0
-L
0.001
-P
1.0E-12
-N
0
-V
-1
-W
1
-K
weka.classifiers.functions.supportVector.PolyKernel -E 1.0 -C 250007
Weka's option handling has undergone a number of changes during the early years:
Initially, there were only simple options like -P 100 and such like.
Something most people familiar with command-line utilities are
familiar with.
Then, meta-schemes like Bagging required supplying options to the base
scheme. These options came after the "--" meta-option.
But that only gave you one extra level rather than arbitrary nesting.
For arbitrary nesting, compound options that took a complete
command-line string consisting of class and options were introduced,
like the -K option for the kernel.
When things get nested, then compound options like these have double
quotes around and if deeper nested, they get escaped by backslashes
(depending on the nesting level).
Hope this helps.
Cheers, Peter