Weka tree wrappers.
Decision and model trees from
weka.classifiers.trees, registered under weka. hub keys so they sit alongside the native TuiML trees family without colliding with it.Notes
Requires the optional Weka extra:
pip install 'tuiml[weka]' plus a Java runtime (11+) on PATH.Classes
J48 — Weka's C4.5 decision tree (hub key weka.J48).
Wraps
weka.classifiers.trees.J48, Weka's implementation of Quinlan's C4.5. Splits on the attribute with the highest gain ratio and prunes with subtree raising by default.
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). Lower values prune more aggressively.
min_num_obj
int
= 2
Minimum number of instances per leaf (Weka
-M).
unpruned
bool
= False
Build an unpruned tree (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 rather than numeric.
options
sequence of str or None
= None
Extra raw Weka options appended to the generated ones, for anything not exposed as a named parameter.
Attributes
model_
weka.classifiers.Classifier
The fitted backing Weka classifier.
classes_
np.ndarray
Class labels in the caller's original label space.
See Also
python
>>> from tuiml.weka import J48
>>> from tuiml.datasets import load_iris
>>> data = load_iris()
>>> clf = J48(confidence_factor=0.25).fit(data.X, data.y)
>>> clf.predict(data.X[:5]).shape
(5,)
REPTree — fast tree with reduced-error pruning (hub key weka.REPTree).
Wraps
weka.classifiers.trees.REPTree. Builds a decision/regression tree using information gain (variance for numeric targets) and prunes it with reduced-error pruning and backfitting.
Constructor
__init__( self, max_depth: int = ..., min_num: float = 2.0, num_folds: int = 3, no_pruning: bool = False, seed: int = 1, nominal_features: Optional[Sequence[int]] = None, options: Optional[Sequence[str]] = None, )
Parameters
max_depth
int
= -1
Maximum tree depth (Weka
-L); -1 means unlimited.
min_num
float
= 2.0
Minimum total instance weight in a leaf (Weka
-M).
num_folds
int
= 3
Folds used for pruning; one is held out (Weka
-N).
no_pruning
bool
= False
Disable pruning entirely (Weka
-P).
seed
int
= 1
Random seed (Weka
-S).
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.
Attributes
model_
weka.classifiers.Classifier
The fitted backing Weka classifier.
python
>>> from tuiml.weka import REPTree
>>> from tuiml.datasets import load_iris
>>> data = load_iris()
>>> clf = REPTree(max_depth=5).fit(data.X, data.y)
>>> clf.predict(data.X[:5]).shape
(5,)
RandomTree — tree over a random attribute subset (hub key weka.RandomTree).
Wraps
weka.classifiers.trees.RandomTree. Considers k randomly chosen attributes at each node and performs no pruning. Mainly used as the base learner inside RandomForest.
Constructor
__init__( self, k_value: int = 0, max_depth: int = 0, min_num: float = 1.0, seed: int = 1, nominal_features: Optional[Sequence[int]] = None, options: Optional[Sequence[str]] = None, )
Parameters
k_value
int
= 0
Attributes sampled per split (Weka
-K); 0 means :math:`\lfloor \log_2(p) \rfloor + 1`.
max_depth
int
= 0
Maximum depth (Weka
-depth); 0 means unlimited.
min_num
float
= 1.0
Minimum total instance weight in a leaf (Weka
-M).
seed
int
= 1
Random seed (Weka
-S).
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 RandomTree
>>> from tuiml.datasets import load_iris
>>> data = load_iris()
>>> clf = RandomTree(seed=42).fit(data.X, data.y)
>>> clf.predict(data.X[:5]).shape
(5,)
RandomForest — Weka's random forest (hub key weka.RandomForest).
Wraps
weka.classifiers.trees.RandomForest, a bagged ensemble of RandomTree.
Constructor
__init__( self, num_iterations: int = 100, num_features: int = 0, max_depth: int = 0, seed: int = 1, nominal_features: Optional[Sequence[int]] = None, options: Optional[Sequence[str]] = None, )
Parameters
num_iterations
int
= 100
Number of trees (Weka
-I).
num_features
int
= 0
Attributes sampled per split (Weka
-K); 0 means :math:`\lfloor \log_2(p) \rfloor + 1`, which is Weka's default and differs from scikit-learn's :math:`\sqrt{p}`.
max_depth
int
= 0
Maximum depth (Weka
-depth); 0 means unlimited.
seed
int
= 1
Random seed (Weka
-S).
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 RandomForest
>>> from tuiml.datasets import load_iris
>>> data = load_iris()
>>> clf = RandomForest(num_iterations=20, seed=42).fit(data.X, data.y)
>>> clf.predict(data.X[:5]).shape
(5,)
DecisionStump — one-level decision tree (hub key weka.DecisionStump).
Wraps
weka.classifiers.trees.DecisionStump. Splits on a single attribute; normally used as a weak learner inside a boosting ensemble.
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 DecisionStump
>>> from tuiml.datasets import load_iris
>>> data = load_iris()
>>> clf = DecisionStump().fit(data.X, data.y)
>>> clf.predict(data.X[:5]).shape
(5,)
LMT — Logistic Model Tree (hub key weka.LMT).
Wraps
weka.classifiers.trees.LMT. A decision tree carrying a logistic regression model at each leaf, fitted with LogitBoost.
Constructor
__init__( self, min_num_instances: int = 15, fast_regression: bool = True, nominal_features: Optional[Sequence[int]] = None, options: Optional[Sequence[str]] = None, )
Parameters
min_num_instances
int
= 15
Minimum instances at which a node is considered for splitting (Weka
-M).
fast_regression
bool
= True
Use the heuristic that speeds up LogitBoost fitting. Passing False emits Weka's
-R 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.
Notes
LMT is considerably slower to train than
J48, because every candidate node fits a boosted logistic model.
python
>>> from tuiml.weka import LMT
>>> from tuiml.datasets import load_iris
>>> data = load_iris()
>>> clf = LMT().fit(data.X, data.y)
>>> clf.predict(data.X[:5]).shape
(5,)
M5P — M5 model tree for regression (hub key weka.M5P).
Wraps
weka.classifiers.trees.M5P. Builds a regression tree whose leaves hold linear regression models rather than constants.
Constructor
__init__( self, min_num_instances: float = 4.0, unpruned: bool = False, use_unsmoothed: bool = False, build_regression_tree: 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 an unpruned tree (Weka
-N).
use_unsmoothed
bool
= False
Skip the smoothing step applied to leaf predictions (Weka
-U).
build_regression_tree
bool
= False
Produce a plain regression tree — constants at the leaves instead of linear models (Weka
-R).
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 M5P
>>> 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 = M5P().fit(X, y)
>>> reg.predict(X[:5]).shape
(5,)