Weka meta-learner wrappers.
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 — adaptive boosting (hub key weka.AdaBoostM1).
weka.classifiers.meta.AdaBoostM1.__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
-I).
weight_threshold
-P).
seed
-S).
use_resampling
-Q), for base learners that cannot use instance weights.
base_classifier
weka.classifiers.trees.DecisionStump.
base_options
nominal_features
options
>>> 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,)
Bagging — bootstrap aggregating (hub key weka.Bagging).
weka.classifiers.meta.Bagging.__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
-I).
bag_size_percent
-P).
seed
-S).
calc_out_of_bag
-O).
base_classifier
weka.classifiers.trees.REPTree.
base_options
nominal_features
options
>>> 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,)
LogitBoost — additive logistic regression (hub key weka.LogitBoost).
weka.classifiers.meta.LogitBoost. Performs additive logistic regression by fitting a regression base learner to the working response at each round.__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
-I).
shrinkage
-H).
seed
-S).
base_classifier
weka.classifiers.trees.DecisionStump.
base_options
nominal_features
options
>>> 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,)
RandomCommittee — average over randomized base learners (hub key weka.RandomCommittee).
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.__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
-I).
seed
-S).
base_classifier
weka.classifiers.trees.RandomTree.
base_options
nominal_features
options
>>> 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,)
RandomSubSpace — random feature subspace ensemble (hub key weka.RandomSubSpace).
weka.classifiers.meta.RandomSubSpace. Each member is trained on a random subset of the attributes.__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
-I).
subspace_size
-P); values above 1 are read as an absolute count.
seed
-S).
base_classifier
weka.classifiers.trees.REPTree.
base_options
nominal_features
options
>>> 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,)
MultiClassClassifier — binary decomposition of a multiclass problem (hub key weka.MultiClassClassifier).
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.__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
-M as 0-3).
random_width
-R).
seed
-S).
base_classifier
weka.classifiers.functions.Logistic.
base_options
nominal_features
options
>>> 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,)
FilteredClassifier — filter then classify (hub key weka.FilteredClassifier).
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.__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
-F).
filter_options
base_classifier
weka.classifiers.trees.J48.
base_options
nominal_features
options
Notes
Workflow covers the same ground for native components; this wrapper exists so a Weka filter can be used in the same position.>>> 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,)
AdditiveRegression — gradient boosting for regression (hub key weka.AdditiveRegression).
weka.classifiers.meta.AdditiveRegression. Fits the base regressor to the residuals of the current ensemble, round after round.__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
-I).
shrinkage
-S). Values below 1 trade more rounds for better generalization.
base_classifier
weka.classifiers.trees.DecisionStump.
base_options
nominal_features
options
>>> 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,)
RegressionByDiscretization — regression via a classifier (hub key weka.RegressionByDiscretization).
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.__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
-B).
delete_empty_bins
-E).
base_classifier
weka.classifiers.trees.J48.
base_options
nominal_features
options
>>> 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,)
Vote — combine several classifiers by voting (hub key weka.Vote).
weka.classifiers.meta.Vote. Unlike the other metas this takes a list of base learners, each supplied with its own -B option.__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
"weka.classifiers.trees.J48 -C 0.1".
combination_rule
-R).
seed
-S).
nominal_features
options
>>> 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,)
Stacking — combine classifiers with a meta-learner (hub key weka.Stacking).
weka.classifiers.meta.Stacking. Trains several base classifiers, then trains a meta-classifier on their cross-validated predictions.__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
-B). Defaults to J48, NaiveBayes and IBk.
meta_classifier
-M).
num_folds
-X).
seed
-S).
nominal_features
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.>>> 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,)