awojna / Rseslib

Rough set and machine learning data structures, algorithms and tools, including algorithms for discernibility matrix, reducts, decision rules, classification (RoughSet, KNN, RIONIDA, AQ15, C4.5, SVM, NeuralNetwork and many others), discretization (1R, Entropy Minimization, ChiMerge, MD), and tool for interactive and explainable machine learning.
http://rseslib.mimuw.edu.pl
GNU General Public License v3.0
15 stars 5 forks source link

Extracting rules from a trained model #1

Closed nebfield closed 6 years ago

nebfield commented 6 years ago

Hello,

I have a simple question, and I have probably overlooked something obvious: is there a way to extract the rules generated by a trained model?

weka.classifiers.rules.JRip has the useful method getRuleset(). Is there an equivalent for weka.classifiers.rules.RoughSet?

I know the rules can be visualised with Qmak, but I would like to extract the list of rules into a text based format for further analysis and optimisation.

Thanks, Ben

rlatkows commented 6 years ago

I'm afraid you are right. Needs to be added. For temporary solution you can use native implementation of rseslib.processing.classification.rules.roughset.RoughSetRuleClassifier with e.g. getRules(),toString().

nebfield commented 6 years ago

Thanks! As I already have a trained model is there a way to cast a weka.classifiers.rules.RoughSet to a rseslib.processing.classification.rules.roughset.RoughSetRuleClassifier? Or am I best starting from scratch with rseslib?

awojna commented 6 years ago

Hi,

You need to start from scratch by training the native rseslib classifier. It needs to be fixed too.

Arek

nebfield commented 6 years ago

OK, no problem. Thank you both for all the help.

awojna commented 6 years ago

Hi Ben,

Let us keep the issue open until it is fixed. We will fix it soon in master and close the issue then.

Arek

nebfield commented 6 years ago

Sorry about that! I have another question:

Thanks to your help I have trained a RoughSetRuleClassifier and extracted the rules. However, I can't work out how to extract the statistics for each rule (e.g. the support). getRules() returns a collection of Rule objects. I think I need RuleWithStatistics objects, but I don't know if it's possible to extract RuleWithStatistics objects from a RoughSetRuleClassifier. calculateStatistics() appears to only return the number of rules in the RoughSetRuleClassifier. Am I missing anything obvious?

awojna commented 6 years ago

Each Rule object from the rough set classifier is actually EqulityDescriptorsRule which implements RuleWithStatistics interface. So you can just use casting:

Rule r = <a rule from rough set classifier>
((RuleWithStatistics)r).getSupport()
nebfield commented 6 years ago

That works perfectly, thank you.