Options of Furia

13 views
Skip to first unread message

kamal idrissi Assia

unread,
Oct 15, 2023, 3:08:09 PM10/15/23
to python-weka-wrapper
Hi,

I'm trying to run Furia of python-weka-wrapper but I got the error 

JavaException: CVParameter -F: four or five components expected!

The code that I am used as follows:

Thanks you.
from weka.classifiers import Classifier,Evaluation
from weka.core.classes import Random
def return_classifier_and_estimate(cls_name,options,plot_roc=True):
    cvp=Classifier(classname='weka.classifiers.meta.CVParameterSelection')
    opt=['-W',cls_name,'-X','10']
    for par in options:
        opt.append('-P')
        opt.append(par)
    cvp.options=opt
    evl=Evaluation(data)
    evl.crossvalidate_model(cvp,data,10,Random(1))
    print(evl.percent_correct)
    print(evl.summary())
    print(evl.class_details()) # add detailed accuracy by class
    print(evl.matrix())
    if(plot_roc):
        import weka.plot.classifiers as plcls  # NB: matplotlib is required
        plcls.plot_roc(evl, class_index=[0, 1], wait=True)
    return cvp

def get_ytest_yprediction(test,classifier):
    evl=Evaluation(test)
    evl.test_model(classifier,test)
    ytest=[]
    ypred=[]
    for index, inst in enumerate(test):
        pred = classifier.classify_instance(inst)
        ypred.append(pred)
    return ytest,ypred
cvrp=return_classifier_and_estimate("weka.classifiers.rules.Furia", ["-F", "5", "-N","2.0","-O","3","-S","1234"])

Peter Reutemann

unread,
Oct 15, 2023, 8:30:16 PM10/15/23
to python-we...@googlegroups.com
The handling of base-classifier options of
SingleClassifierEnhancer-derived classes, which use the "-W" and "--"
approach, is a bit tricky.
I recommend to use the Python class "SingleClassifierEnhancer" to make
your life easier:

from weka.classifiers import Classifier, Evaluation, SingleClassifierEnhancer
...
cls = Classifier(classname=cls_name, options=options)
cvp = SingleClassifierEnhancer(classname='weka.classifiers.meta.CVParameterSelection',
options=["-X", "10"])
cvp.classifier = cls
...

Attached is a full example.

Also, the class name is "FURIA" and not "Furia":
https://weka.sourceforge.io/doc.packages/fuzzyUnorderedRuleInduction/weka/classifiers/rules/FURIA.html

Cheers, Peter
> --
> You received this message because you are subscribed to the Google Groups "python-weka-wrapper" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to python-weka-wra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/python-weka-wrapper/fe0e74d5-f32b-4258-b3ab-64fed65b37a9n%40googlegroups.com.



--
Peter Reutemann
Dept. of Computer Science
University of Waikato, Hamilton, NZ
Mobile +64 22 190 2375
https://www.cs.waikato.ac.nz/~fracpete/
http://www.data-mining.co.nz/
furia.py

kamal idrissi Assia

unread,
Oct 16, 2023, 5:10:42 AM10/16/23
to python-weka-wrapper
Thank you for you reply. I tried the script above but I got the following error regarding this line:
cls = Classifier(classname=cls_name, options=options)

Failed to instantiate weka.classifiers.rules.FURIA: weka.classifiers.rules.FURIA Class 'weka.classifiers.rules.FURIA' is available from package: fuzzyUnorderedRuleInduction Also, you need to start up the JVM with package support: jvm.start(packages=True)
--------------------------------------------------------------------------- AssertionError Traceback (most recent call last) <ipython-input-7-919c38ada4c8> in <cell line: 30>() 28 29 data = load_any_file("iris.arff", class_index="last") ---> 30 cvp, evl = return_classifier_and_estimate(data, "weka.classifiers.rules.FURIA", ["-F", "5", "-N","2.0","-O","3","-S","1234"]) 31 32 jvm.stop()

7 frames
<ipython-input-7-919c38ada4c8> in return_classifier_and_estimate(data, cls_name, options, plot_roc) 12 13 def return_classifier_and_estimate(data, cls_name, options, plot_roc=True): ---> 14 cls = Classifier(classname=cls_name, options=options) 15 cvp = SingleClassifierEnhancer(classname='weka.classifiers.meta.CVParameterSelection', options=["-X", "10"]) 16 cvp.classifier = cls /usr/local/lib/python3.10/dist-packages/weka/classifiers.py in __init__(self, classname, jobject, options) 56 if jobject is None: 57 jobject = Classifier.new_instance(classname) ---> 58 self.enforce_type(jobject, "weka.classifiers.Classifier") 59 self.is_updateable = self.check_type(jobject, "weka.classifiers.UpdateableClassifier") 60 self.is_drawable = self.check_type(jobject, "weka.core.Drawable") /usr/local/lib/python3.10/dist-packages/weka/core/classes.py in enforce_type(cls, jobject, intf_or_class) 591 :type intf_or_class: str 592 """ --> 593 if not cls.check_type(jobject, intf_or_class): 594 raise TypeError("Object does not implement or subclass " + intf_or_class + ": " + get_classname(jobject)) 595 /usr/local/lib/python3.10/dist-packages/weka/core/classes.py in check_type(cls, jobject, intf_or_class) 579 :rtype: bool 580 """ --> 581 return is_instance_of(jobject, intf_or_class) 582 583 @classmethod /usr/local/lib/python3.10/dist-packages/weka/core/classes.py in is_instance_of(obj, class_or_intf_name) 285 classname = get_classname(obj) 286 # array? retrieve component type and check that --> 287 if is_array(obj): 288 jarray = JavaArray(jobject=obj) 289 classname = jarray.component_type() /usr/local/lib/python3.10/dist-packages/weka/core/classes.py in is_array(obj) 309 :rtype: bool 310 """ --> 311 cls = javabridge.call(obj, "getClass", "()Ljava/lang/Class;") 312 return javabridge.call(cls, "isArray", "()Z") 313 /usr/local/lib/python3.10/dist-packages/javabridge/jutil.py in call(o, method_name, sig, *args) 886 ''' 887 env = get_env() --> 888 fn = make_call(o, method_name, sig) 889 args_sig = split_sig(sig[1:sig.find(')')]) 890 ret_sig = sig[sig.find(')')+1:] /usr/local/lib/python3.10/dist-packages/javabridge/jutil.py in make_call(o, method_name, sig) 834 835 ''' --> 836 assert o is not None 837 env = get_env() 838 if isinstance(o, basestring): AssertionError:

Could you please help me to solve this issue?

Thank you

Peter Reutemann

unread,
Oct 16, 2023, 5:18:11 AM10/16/23
to python-we...@googlegroups.com
Did you install the package, like my attached script did and also start the jvm with package support?

Cheers, Peter
--
Peter Reutemann
Dept. of Computer Science
University of Waikato, Hamilton, NZ
Mobile +64 22 190 2375
https://www.cs.waikato.ac.nz/~fracpete/
http://www.data-mining.co.nz/

16/10/2023 22:10:46 kamal idrissi Assia <kamalidri...@gmail.com>:

Reply all
Reply to author
Forward
0 new messages