API Reference / weka /

meta.py

Weka meta-learner wrappers.

Ensemble and wrapper schemes from weka.classifiers.meta, registered under weka. hub keys. Every learner here takes a base learner, named by its fully-qualified Weka class.

Notes

Requires the optional Weka extra: pip install 'tuiml[weka]' plus a Java runtime (11+) on PATH.

Weka's command line nests a base learner's own options after a -- separator:

-W weka.classifiers.trees.J48 -- -C 0.25 -M 2

_base_spec builds that tail, so a wrapper only needs base_classifier and base_options.

Classes

AdaBoostM1

class weka.meta.AdaBoostM1(_MetaBase, Classifier)

AdaBoostM1 — adaptive boosting (hub key weka.AdaBoostM1).

Wraps weka.classifiers.meta.AdaBoostM1.
Constructor
__init__(
    self,
    num_iterations: int = 10,
    weight_threshold: int = 100,
    seed: int = 1,
    use_resampling: bool = False,
    base_classifier: Optional[str] = None,
    base_options: Optional[Sequence[str]] = None,
    nominal_features: Optional[Sequence[int]] = None,
    options: Optional[Sequence[str]] = None,
)

Parameters

num_iterations
int = 10
Number of boosting rounds (Weka -I).
weight_threshold
int = 100
Weight pruning threshold as a percentage (Weka -P).
seed
int = 1
Random seed (Weka -S).
use_resampling
bool = False
Resample instead of reweighting (Weka -Q), for base learners that cannot use instance weights.
base_classifier
str or None = None
Base learner; defaults to weka.classifiers.trees.DecisionStump.
base_options
sequence of str or None = None
Options for the base learner.
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 AdaBoostM1
>>> from tuiml.datasets import load_iris
>>> data = load_iris()
>>> clf = AdaBoostM1(num_iterations=10).fit(data.X, data.y)
>>> clf.predict(data.X[:5]).shape
(5,)

Methods

get_parameter_schema (cls) -> Dict[str, Any]

Return JSON Schema for constructor parameters.

get_capabilities (cls) -> List[str]

Return the capability names this wrapper supports.

Bagging

class weka.meta.Bagging(_MetaBase, Classifier)

Bagging — bootstrap aggregating (hub key weka.Bagging).

Wraps weka.classifiers.meta.Bagging.
Constructor
__init__(
    self,
    num_iterations: int = 10,
    bag_size_percent: int = 100,
    seed: int = 1,
    calc_out_of_bag: bool = False,
    base_classifier: Optional[str] = None,
    base_options: Optional[Sequence[str]] = None,
    nominal_features: Optional[Sequence[int]] = None,
    options: Optional[Sequence[str]] = None,
)

Parameters

num_iterations
int = 10
Number of bags (Weka -I).
bag_size_percent
int = 100
Size of each bag as a percentage of the training set (Weka -P).
seed
int = 1
Random seed (Weka -S).
calc_out_of_bag
bool = False
Compute the out-of-bag error (Weka -O).
base_classifier
str or None = None
Base learner; defaults to weka.classifiers.trees.REPTree.
base_options
sequence of str or None = None
Options for the base learner.
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 Bagging
>>> from tuiml.datasets import load_iris
>>> data = load_iris()
>>> clf = Bagging(num_iterations=10).fit(data.X, data.y)
>>> clf.predict(data.X[:5]).shape
(5,)

Methods

get_parameter_schema (cls) -> Dict[str, Any]

Return JSON Schema for constructor parameters.

get_capabilities (cls) -> List[str]

Return the capability names this wrapper supports.

LogitBoost

class weka.meta.LogitBoost(_MetaBase, Classifier)

LogitBoost — additive logistic regression (hub key weka.LogitBoost).

Wraps weka.classifiers.meta.LogitBoost. Performs additive logistic regression by fitting a regression base learner to the working response at each round.
Constructor
__init__(
    self,
    num_iterations: int = 10,
    shrinkage: float = 1.0,
    seed: int = 1,
    base_classifier: Optional[str] = None,
    base_options: Optional[Sequence[str]] = None,
    nominal_features: Optional[Sequence[int]] = None,
    options: Optional[Sequence[str]] = None,
)

Parameters

num_iterations
int = 10
Number of boosting rounds (Weka -I).
shrinkage
float = 1.0
Shrinkage applied to each round (Weka -H).
seed
int = 1
Random seed (Weka -S).
base_classifier
str or None = None
Base learner, which must be a regressor; defaults to weka.classifiers.trees.DecisionStump.
base_options
sequence of str or None = None
Options for the base learner.
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 LogitBoost
>>> from tuiml.datasets import load_iris
>>> data = load_iris()
>>> clf = LogitBoost(num_iterations=10).fit(data.X, data.y)
>>> clf.predict(data.X[:5]).shape
(5,)

Methods

get_parameter_schema (cls) -> Dict[str, Any]

Return JSON Schema for constructor parameters.

get_capabilities (cls) -> List[str]

Return the capability names this wrapper supports.

RandomCommittee

class weka.meta.RandomCommittee(_MetaBase, Classifier)

RandomCommittee — average over randomized base learners (hub key weka.RandomCommittee).

Wraps weka.classifiers.meta.RandomCommittee. Builds several copies of a randomizable base learner, each with a different seed, and averages their predictions. Unlike bagging, every model sees the full training set; the only source of diversity is the base learner's own randomness.
Constructor
__init__(
    self,
    num_iterations: int = 10,
    seed: int = 1,
    base_classifier: Optional[str] = None,
    base_options: Optional[Sequence[str]] = None,
    nominal_features: Optional[Sequence[int]] = None,
    options: Optional[Sequence[str]] = None,
)

Parameters

num_iterations
int = 10
Number of committee members (Weka -I).
seed
int = 1
Random seed (Weka -S).
base_classifier
str or None = None
Base learner, which must be randomizable; defaults to weka.classifiers.trees.RandomTree.
base_options
sequence of str or None = None
Options for the base learner.
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 RandomCommittee
>>> from tuiml.datasets import load_iris
>>> data = load_iris()
>>> clf = RandomCommittee(num_iterations=10).fit(data.X, data.y)
>>> clf.predict(data.X[:5]).shape
(5,)

Methods

get_parameter_schema (cls) -> Dict[str, Any]

Return JSON Schema for constructor parameters.

get_capabilities (cls) -> List[str]

Return the capability names this wrapper supports.

RandomSubSpace

class weka.meta.RandomSubSpace(_MetaBase, Classifier)

RandomSubSpace — random feature subspace ensemble (hub key weka.RandomSubSpace).

Wraps weka.classifiers.meta.RandomSubSpace. Each member is trained on a random subset of the attributes.
Constructor
__init__(
    self,
    num_iterations: int = 10,
    subspace_size: float = 0.5,
    seed: int = 1,
    base_classifier: Optional[str] = None,
    base_options: Optional[Sequence[str]] = None,
    nominal_features: Optional[Sequence[int]] = None,
    options: Optional[Sequence[str]] = None,
)

Parameters

num_iterations
int = 10
Number of ensemble members (Weka -I).
subspace_size
float = 0.5
Fraction of attributes per member (Weka -P); values above 1 are read as an absolute count.
seed
int = 1
Random seed (Weka -S).
base_classifier
str or None = None
Base learner; defaults to weka.classifiers.trees.REPTree.
base_options
sequence of str or None = None
Options for the base learner.
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 RandomSubSpace
>>> from tuiml.datasets import load_iris
>>> data = load_iris()
>>> clf = RandomSubSpace(num_iterations=10).fit(data.X, data.y)
>>> clf.predict(data.X[:5]).shape
(5,)

Methods

get_parameter_schema (cls) -> Dict[str, Any]

Return JSON Schema for constructor parameters.

get_capabilities (cls) -> List[str]

Return the capability names this wrapper supports.

MultiClassClassifier

class weka.meta.MultiClassClassifier(_MetaBase, Classifier)

MultiClassClassifier — binary decomposition of a multiclass problem (hub key weka.MultiClassClassifier).

Wraps weka.classifiers.meta.MultiClassClassifier. Turns a binary base learner into a multiclass one by one-vs-rest, one-vs-one, or error-correcting output codes.
Constructor
__init__(
    self,
    method: str = 'ova',
    random_width: float = 2.0,
    seed: int = 1,
    base_classifier: Optional[str] = None,
    base_options: Optional[Sequence[str]] = None,
    nominal_features: Optional[Sequence[int]] = None,
    options: Optional[Sequence[str]] = None,
)

Parameters

method
{'ova', 'random_codes', 'exhaustive_codes', 'ovo'} = 'ova'
Decomposition method (Weka -M as 0-3).
random_width
float = 2.0
Code width multiplier for random error-correcting codes (Weka -R).
seed
int = 1
Random seed (Weka -S).
base_classifier
str or None = None
Base learner; defaults to weka.classifiers.functions.Logistic.
base_options
sequence of str or None = None
Options for the base learner.
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 MultiClassClassifier
>>> from tuiml.datasets import load_iris
>>> data = load_iris()
>>> clf = MultiClassClassifier(method='ovo').fit(data.X, data.y)
>>> clf.predict(data.X[:5]).shape
(5,)

Methods

get_parameter_schema (cls) -> Dict[str, Any]

Return JSON Schema for constructor parameters.

get_capabilities (cls) -> List[str]

Return the capability names this wrapper supports.

FilteredClassifier

class weka.meta.FilteredClassifier(_MetaBase, Classifier)

FilteredClassifier — filter then classify (hub key weka.FilteredClassifier).

Wraps weka.classifiers.meta.FilteredClassifier. Runs an arbitrary Weka filter over the data and trains the base learner on the result, with the filter fitted on training data only.
Constructor
__init__(
    self,
    filter_name: str = 'weka.filters.unsupervised.attribute.Standardize',
    filter_options: Optional[Sequence[str]] = None,
    base_classifier: Optional[str] = None,
    base_options: Optional[Sequence[str]] = None,
    nominal_features: Optional[Sequence[int]] = None,
    options: Optional[Sequence[str]] = None,
)

Parameters

filter_name
str = "weka.filters.unsupervised.attribute.Standardize"
Fully-qualified Weka filter class (Weka -F).
filter_options
sequence of str or None = None
Options for the filter, appended to its class name.
base_classifier
str or None = None
Base learner; defaults to weka.classifiers.trees.J48.
base_options
sequence of str or None = None
Options for the base learner.
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

TuiML's own Workflow covers the same ground for native components; this wrapper exists so a Weka filter can be used in the same position.
python
>>> from tuiml.weka import FilteredClassifier
>>> from tuiml.datasets import load_iris
>>> data = load_iris()
>>> clf = FilteredClassifier().fit(data.X, data.y)
>>> clf.predict(data.X[:5]).shape
(5,)

Methods

get_parameter_schema (cls) -> Dict[str, Any]

Return JSON Schema for constructor parameters.

get_capabilities (cls) -> List[str]

Return the capability names this wrapper supports.

AdditiveRegression

class weka.meta.AdditiveRegression(_MetaBase, Regressor)

AdditiveRegression — gradient boosting for regression (hub key weka.AdditiveRegression).

Wraps weka.classifiers.meta.AdditiveRegression. Fits the base regressor to the residuals of the current ensemble, round after round.
Constructor
__init__(
    self,
    num_iterations: int = 10,
    shrinkage: float = 1.0,
    base_classifier: Optional[str] = None,
    base_options: Optional[Sequence[str]] = None,
    nominal_features: Optional[Sequence[int]] = None,
    options: Optional[Sequence[str]] = None,
)

Parameters

num_iterations
int = 10
Number of boosting rounds (Weka -I).
shrinkage
float = 1.0
Shrinkage applied to each round's contribution (Weka -S). Values below 1 trade more rounds for better generalization.
base_classifier
str or None = None
Base regressor; defaults to weka.classifiers.trees.DecisionStump.
base_options
sequence of str or None = None
Options for the base learner.
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 AdditiveRegression
>>> import numpy as np
>>> rng = np.random.default_rng(0)
>>> X = rng.normal(size=(60, 3))
>>> y = 2.0 * X[:, 0] + rng.normal(scale=0.1, size=60)
>>> reg = AdditiveRegression(num_iterations=20).fit(X, y)
>>> reg.predict(X[:5]).shape
(5,)

Methods

get_parameter_schema (cls) -> Dict[str, Any]

Return JSON Schema for constructor parameters.

get_capabilities (cls) -> List[str]

Return the capability names this wrapper supports.

RegressionByDiscretization

class weka.meta.RegressionByDiscretization(_MetaBase, Regressor)

RegressionByDiscretization — regression via a classifier (hub key weka.RegressionByDiscretization).

Wraps weka.classifiers.meta.RegressionByDiscretization. Bins the numeric target, trains a classifier on the bins, and predicts the weighted mean of the bin centres — which lets any classifier tackle a regression problem.
Constructor
__init__(
    self,
    num_bins: int = 10,
    delete_empty_bins: bool = False,
    base_classifier: Optional[str] = None,
    base_options: Optional[Sequence[str]] = None,
    nominal_features: Optional[Sequence[int]] = None,
    options: Optional[Sequence[str]] = None,
)

Parameters

num_bins
int = 10
Number of bins the target is split into (Weka -B).
delete_empty_bins
bool = False
Drop bins that end up empty (Weka -E).
base_classifier
str or None = None
Base classifier; defaults to weka.classifiers.trees.J48.
base_options
sequence of str or None = None
Options for the base learner.
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 RegressionByDiscretization
>>> import numpy as np
>>> rng = np.random.default_rng(0)
>>> X = rng.normal(size=(60, 3))
>>> y = 2.0 * X[:, 0] + rng.normal(scale=0.1, size=60)
>>> reg = RegressionByDiscretization(num_bins=8).fit(X, y)
>>> reg.predict(X[:5]).shape
(5,)

Methods

get_parameter_schema (cls) -> Dict[str, Any]

Return JSON Schema for constructor parameters.

get_capabilities (cls) -> List[str]

Return the capability names this wrapper supports.

Vote

class weka.meta.Vote(_WekaSupervisedMixin, Classifier)

Vote — combine several classifiers by voting (hub key weka.Vote).

Wraps weka.classifiers.meta.Vote. Unlike the other metas this takes a list of base learners, each supplied with its own -B option.
Constructor
__init__(
    self,
    classifiers: Optional[Sequence[str]] = None,
    combination_rule: str = 'avg',
    seed: int = 1,
    nominal_features: Optional[Sequence[int]] = None,
    options: Optional[Sequence[str]] = None,
)

Parameters

classifiers
sequence of str or None = None
Fully-qualified Weka classes to combine. Defaults to J48, NaiveBayes and IBk. Each may carry its own options in the same string, e.g. "weka.classifiers.trees.J48 -C 0.1".
combination_rule
{'avg', 'product', 'majority', 'min', 'max', 'median'} = 'avg'
How member predictions are combined (Weka -R).
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 Vote
>>> from tuiml.datasets import load_iris
>>> data = load_iris()
>>> clf = Vote(combination_rule='majority').fit(data.X, data.y)
>>> clf.predict(data.X[:5]).shape
(5,)

Methods

get_parameter_schema (cls) -> Dict[str, Any]

Return JSON Schema for constructor parameters.

get_capabilities (cls) -> List[str]

Return the capability names this wrapper supports.

Stacking

class weka.meta.Stacking(_WekaSupervisedMixin, Classifier)

Stacking — combine classifiers with a meta-learner (hub key weka.Stacking).

Wraps weka.classifiers.meta.Stacking. Trains several base classifiers, then trains a meta-classifier on their cross-validated predictions.
Constructor
__init__(
    self,
    classifiers: Optional[Sequence[str]] = None,
    meta_classifier: str = 'weka.classifiers.functions.Logistic',
    num_folds: int = 10,
    seed: int = 1,
    nominal_features: Optional[Sequence[int]] = None,
    options: Optional[Sequence[str]] = None,
)

Parameters

classifiers
sequence of str or None = None
Fully-qualified Weka classes used as level-0 learners (Weka -B). Defaults to J48, NaiveBayes and IBk.
meta_classifier
str = "weka.classifiers.functions.Logistic"
Level-1 learner combining the base predictions (Weka -M).
num_folds
int = 10
Folds used to generate the level-1 training set (Weka -X).
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.

Notes

num_folds matters more than it looks: the meta-learner only ever sees the level-1 table built from these folds, so too few folds starve it. On iris, dropping from the default 10 to 3 takes accuracy from 0.98 to 0.67. Lower it only when training cost forces you to.
python
>>> from tuiml.weka import Stacking
>>> from tuiml.datasets import load_iris
>>> data = load_iris()
>>> clf = Stacking().fit(data.X, data.y)
>>> clf.predict(data.X[:5]).shape
(5,)

Methods

get_parameter_schema (cls) -> Dict[str, Any]

Return JSON Schema for constructor parameters.

get_capabilities (cls) -> List[str]

Return the capability names this wrapper supports.