How to deliver split data to Jrip using split

17 views
Skip to first unread message

Dario Martinez

unread,
Feb 23, 2024, 6:44:56 AMFeb 23
to python-weka-wrapper
Hello again, I have been testing with the JRip algorithm, obtaining the rules as follows:
labor_file = data_dir + file_name
loader = Loader("weka.core.converters.ArffLoader")
labor_data = loader.load_file(labor_file)
labor_data.class_is_last()
jrip.build_classifier(labor_data)
rset = jrip.jwrapper.getRuleset()
for i in range(rset.size()):
     r = rset.get(i)
     print(str(r.toString(labor_data.class_attribute.jobject)))

But I am giving you the entire data set, now I want to segment them with split, I found two ways, the first:
evaluation = Evaluation(labor_data)
evaluation.evaluate_train_test_split(jrip, labor_data, 70, rnd=None, output=None)
rset = evaluation.jwrapper.getRuleset()
print(evaluation.summary())

But I didn't find how to extract the rules, only summary and other things but not the rules.
The second:
jrip = Classifier(classname="weka.classifiers.rules.JRip")
# generate train/test spli
train, test = labor_data.train_test_split(70.0, None)
jrip.build_classifier(train)
rset = jrip.jwrapper.getRuleset()
for i in range(rset.size()):
       r = rset.get(i)
       print(str(r.toString(labor_data.class_attribute.jobject)))

In this last way I can now obtain the rules, I am giving the builder the train data, but I don't know how to tell it before extracting the rules, to test the model with the test data, if you can guide me with this I would greatly appreciate it

Peter Reutemann

unread,
Feb 23, 2024, 10:05:56 PMFeb 23
to python-we...@googlegroups.com
The Evaluation is, just like the name suggests, for evaluating a
classifier's performance. Whatever model is being generated is not
important.

Once you have train a classifier you can simply evaluate it on the tests set:

# create classifier object
jrip = Classifier(classname="weka.classifiers.rules.JRip")
# generate train/test split
train, test = labor_data.train_test_split(70.0, None)
# build classifier
jrip.build_classifier(train)
# evaluate on test set
evl = Evaluation(test)
evl.test_model(jrip, test)
print(evl.summary())

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/

Dario Martinez

unread,
Feb 24, 2024, 7:55:24 AMFeb 24
to python-we...@googlegroups.com
Hello Peter, thank you for your response, but what I want is to choose the rules, not the summary, but nevertheless they already shared with me a way to do this, it is the following:
labor_data.train_test_split(70, Random(1))

jrip.build_classifier(labor_data)
rset = jrip.jwrapper.getRuleset()
for i in range(rset.size()):
       r = rset.get(i)
       print(str(r.toString(labor_data.class_attribute.jobject)))

As for the rules that it generates, I have other doubts but in a moment I will put them up in another thread.

--
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/CAHoQ12%2B95F-2O%3DpzKErRpQEY5D8QhNBKEC53zbsdahEWiD0P4w%40mail.gmail.com.

Peter Reutemann

unread,
Feb 25, 2024, 2:31:18 PMFeb 25
to python-we...@googlegroups.com
> Hello Peter, thank you for your response, but what I want is to choose the rules, not the summary, but nevertheless they already shared with me a way to do this, it is the following:
> labor_data.train_test_split(70, Random(1))
> jrip.build_classifier(labor_data)
> rset = jrip.jwrapper.getRuleset()
> for i in range(rset.size()):
> r = rset.get(i)
> print(str(r.toString(labor_data.class_attribute.jobject)))
>
> As for the rules that it generates, I have other doubts but in a moment I will put them up in another thread.

Since you already had a way of extracting the rules (from the trained
jrip model), I didn't need to show you that. I only demonstrated how
to evaluate a trained classifier on a test set.
Reply all
Reply to author
Forward
0 new messages