Weka rule-learner wrappers.
Rule and decision-table learners from
weka.classifiers.rules, registered under weka. hub keys. These are the models to reach for when the result has to be readable by a person: every one of them can be printed with to_weka_string().Notes
Requires the optional Weka extra:
pip install 'tuiml[weka]' plus a Java runtime (11+) on PATH.Classes
ZeroR — majority-class baseline (hub key weka.ZeroR).
Wraps
weka.classifiers.rules.ZeroR. Predicts the majority class (or the mean, for a numeric target) and ignores every attribute. Its only real use is as the floor any serious model must beat.
Constructor
__init__( self, nominal_features: Optional[Sequence[int]] = None, options: Optional[Sequence[str]] = None, )
Parameters
nominal_features
sequence of int or None
= None
0-based indices of columns to treat as categorical.
options
sequence of str or None
= None
Extra raw Weka options.
python
>>> from tuiml.weka import ZeroR
>>> from tuiml.datasets import load_iris
>>> data = load_iris()
>>> clf = ZeroR().fit(data.X, data.y)
>>> clf.predict(data.X[:5]).shape
(5,)
OneR — one-attribute rule classifier (hub key weka.OneR).
Wraps
weka.classifiers.rules.OneR. Builds a single rule on the one attribute that yields the lowest training error — Holte's demonstration that very simple rules often perform surprisingly well.
Constructor
__init__( self, min_bucket_size: int = 6, nominal_features: Optional[Sequence[int]] = None, options: Optional[Sequence[str]] = None, )
Parameters
min_bucket_size
int
= 6
Minimum bucket size used when discretizing numeric attributes (Weka
-B). Larger values give simpler, more general rules.
nominal_features
sequence of int or None
= None
0-based indices of columns to treat as categorical.
options
sequence of str or None
= None
Extra raw Weka options.
python
>>> from tuiml.weka import OneR
>>> from tuiml.datasets import load_iris
>>> data = load_iris()
>>> clf = OneR(min_bucket_size=6).fit(data.X, data.y)
>>> clf.predict(data.X[:5]).shape
(5,)
JRip — Weka's RIPPER rule learner (hub key weka.JRip).
Wraps
weka.classifiers.rules.JRip, Weka's implementation of Cohen's RIPPER: grow a rule set, prune it, then optimize it over several passes.
Constructor
__init__( self, folds: int = 3, min_no: float = 2.0, optimizations: int = 2, seed: int = 1, prune: bool = True, nominal_features: Optional[Sequence[int]] = None, options: Optional[Sequence[str]] = None, )
Parameters
folds
int
= 3
Folds used for reduced-error pruning; one is held out (Weka
-F).
min_no
float
= 2.0
Minimum total instance weight covered by a rule (Weka
-N).
optimizations
int
= 2
Number of optimization passes over the rule set (Weka
-O).
seed
int
= 1
Random seed (Weka
-S).
prune
bool
= True
Run pruning. Passing False emits Weka's
-P flag to disable it.
nominal_features
sequence of int or None
= None
0-based indices of columns to treat as categorical.
options
sequence of str or None
= None
Extra raw Weka options.
python
>>> from tuiml.weka import JRip
>>> from tuiml.datasets import load_iris
>>> data = load_iris()
>>> clf = JRip().fit(data.X, data.y)
>>> clf.predict(data.X[:5]).shape
(5,)
PART — partial decision tree rule learner (hub key weka.PART).
Wraps
weka.classifiers.rules.PART. Repeatedly builds a partial C4.5 tree and turns its best leaf into a rule, which avoids RIPPER's global optimization step while still producing a compact rule list.
Constructor
__init__( self, confidence_factor: float = 0.25, min_num_obj: int = 2, unpruned: bool = False, binary_splits: bool = False, nominal_features: Optional[Sequence[int]] = None, options: Optional[Sequence[str]] = None, )
Parameters
confidence_factor
float
= 0.25
Confidence threshold for pruning (Weka
-C).
min_num_obj
int
= 2
Minimum instances per rule (Weka
-M).
unpruned
bool
= False
Build unpruned rules (Weka
-U).
binary_splits
bool
= False
Use binary splits on nominal attributes (Weka
-B).
nominal_features
sequence of int or None
= None
0-based indices of columns to treat as categorical.
options
sequence of str or None
= None
Extra raw Weka options.
See Also
python
>>> from tuiml.weka import PART
>>> from tuiml.datasets import load_iris
>>> data = load_iris()
>>> clf = PART().fit(data.X, data.y)
>>> clf.predict(data.X[:5]).shape
(5,)
DecisionTable — simple decision table majority classifier (hub key weka.DecisionTable).
Wraps
weka.classifiers.rules.DecisionTable. Selects a feature subset by search, then predicts using a lookup table of majority classes over that subset, falling back to the global majority for unseen combinations.
Constructor
__init__( self, cross_val: int = 1, use_ibk: bool = False, nominal_features: Optional[Sequence[int]] = None, options: Optional[Sequence[str]] = None, )
Parameters
cross_val
int
= 1
Cross-validation setting used to evaluate subsets (Weka
-X); 1 means leave-one-out.
use_ibk
bool
= False
Fall back to a nearest-neighbour prediction rather than the global majority for combinations missing from the table (Weka
-I).
nominal_features
sequence of int or None
= None
0-based indices of columns to treat as categorical.
options
sequence of str or None
= None
Extra raw Weka options.
python
>>> from tuiml.weka import DecisionTable
>>> from tuiml.datasets import load_iris
>>> data = load_iris()
>>> clf = DecisionTable().fit(data.X, data.y)
>>> clf.predict(data.X[:5]).shape
(5,)
M5Rules — regression rules from M5 model trees (hub key weka.M5Rules).
Wraps
weka.classifiers.rules.M5Rules. Repeatedly builds an M5 model tree and converts its best branch into a rule, giving a rule list whose consequents are linear models.
Constructor
__init__( self, min_num_instances: float = 4.0, unpruned: bool = False, use_unsmoothed: bool = False, nominal_features: Optional[Sequence[int]] = None, options: Optional[Sequence[str]] = None, )
Parameters
min_num_instances
float
= 4.0
Minimum instances allowed at a leaf (Weka
-M).
unpruned
bool
= False
Build unpruned rules (Weka
-N).
use_unsmoothed
bool
= False
Skip the smoothing step (Weka
-U).
nominal_features
sequence of int or None
= None
0-based indices of columns to treat as categorical.
options
sequence of str or None
= None
Extra raw Weka options.
python
>>> from tuiml.weka import M5Rules
>>> import numpy as np
>>> rng = np.random.default_rng(0)
>>> X = rng.normal(size=(80, 3))
>>> y = 2.0 * X[:, 0] + rng.normal(scale=0.1, size=80)
>>> reg = M5Rules().fit(X, y)
>>> reg.predict(X[:5]).shape
(5,)