Need help running JRip

52 views
Skip to first unread message

Juan José Expósito González

unread,
Jan 13, 2024, 6:02:37 PMJan 13
to python-weka-wrapper
Hi!

After having installed python-weka-wrapper, I want to run RIPPER on a dataset. The data is already filtered and features removed and all saved into a .csv file.

I have followed the steps in the docs but I get errors:

from weka.core.classes import from_commandline
from weka.core.converters import Loader
from weka.classifiers import Classifier
from random import randint

def load_file_to_classify(url:str) -> Any:
    """Load the file to classify"""
    loader = Loader(classname = 'weka.core.converters.CSVLoader')
    data = loader.load_file(url)  # type: ignore
    data.class_is_last()
    return data

def run_weka_Jrip(url:str, num_iterations: int = 1) -> None:
    """Run the weka JRip algorithm"""
    data = load_file_to_classify(url)
    seed = randint(1, num_iterations)
   
    jrip = Classifier("weka.classifiers.rules.JRip")
    jrip.build_classifier(data)
    rset = jrip.wrapper.getRuleset()
    for i in range(rset.size()):
        print(rset.get(i))


I get the error: AttributeError: 'Classifier' object has no attribute 'build_classifier'. And I can't import Evaluation from weka.classifiers.

Any ideas?

Kindest Regards,

JJ

Peter Reutemann

unread,
Jan 13, 2024, 6:06:47 PMJan 13
to python-we...@googlegroups.com
Please post the output of "pip freeze" from the environment that you are running the script with.

And the full error message output from the console.

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/

14/01/2024 12:02:38 Juan José Expósito González <jjeg...@gmail.com>:

--
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/43401cbb-c9cb-45ed-8106-5491221c56d0n%40googlegroups.com.

Juan José Expósito González

unread,
Jan 13, 2024, 8:37:18 PMJan 13
to python-weka-wrapper
Hi Peter, already solved! I don't know why I had done pip install weka...that messed up everything! Returned to normal and now it is working fine. I am using this code to get RIPPER rules:

def run_weka_Jrip(url: str, num_iterations: int = 1) -> list[str]:
    """Run the weka JRip algorithm"""
    data = load_file_to_classify(url)
    seed = 1
    optimizations = 2
    options = f"-F 3 -N 2.0 -O {optimizations} -S {seed}".split()
    # cmdline: str = "weka.classifiers.rules.JRip -F 3 -N 2.0 -O 2 -S 1"

    # jrip = from_commandline(cmdline)  # type: ignore
    jrip = Classifier(classname="weka.classifiers.rules.JRip", options=options)
    jrip.build_classifier(data)
    print(jrip)

And I get 4 rules, but they are different from the same rules obtained from the GUI: I have done the data split with pandas (not sure if this is correct or I should do the split in the same fashion as with WEKA GUI). These are the options I have in the GUI:
Captura.GIF

How can I get the rules in a list of strings?

Thanks!

JJ

Peter Reutemann

unread,
Jan 14, 2024, 12:53:12 AMJan 14
to python-we...@googlegroups.com

Peter Reutemann

unread,
Jan 14, 2024, 2:38:53 PMJan 14
to python-we...@googlegroups.com
If you're just after evaluating a dataset, you can also use this method for performing a train/test split:

Cheers, Peter
--
My Open Source Blog - http://open.fracpete.org

Juanjo

unread,
Jan 14, 2024, 3:05:20 PMJan 14
to python-we...@googlegroups.com
Thanks! It works like a charm!

Kindest Regards,

JJ

You received this message because you are subscribed to a topic in the Google Groups "python-weka-wrapper" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python-weka-wrapper/gkWas7XsATo/unsubscribe.
To unsubscribe from this group and all its topics, 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/8cfa40ac-f288-4b8f-8643-a4658fc9130a%40gmail.com.
Reply all
Reply to author
Forward
0 new messages