API Reference / weka /

lazy.py

Weka instance-based (lazy) learner wrappers.

Learners from weka.classifiers.lazy, which store the training data and defer all work to prediction time. Registered under weka. hub keys.

Notes

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

Classes

IBk

class weka.lazy.IBk(_WekaSupervisedMixin, Classifier)

IBk — k-nearest-neighbour classifier (hub key weka.IBk).

Wraps weka.classifiers.lazy.IBk, Weka's implementation of Aha's instance-based learner.
Constructor
__init__(
    self,
    k: int = 1,
    distance_weighting: str = 'none',
    cross_validate: bool = False,
    nominal_features: Optional[Sequence[int]] = None,
    options: Optional[Sequence[str]] = None,
)

Parameters

k
int = 1
Number of neighbours (Weka -K).
distance_weighting
{'none', 'inverse', 'similarity'} = 'none'
How neighbour votes are weighted: uniformly, by 1/distance (Weka -I), or by 1 - distance (Weka -F).
cross_validate
bool = False
Select the best k up to the given value by leave-one-out cross-validation (Weka -X).
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 IBk
>>> from tuiml.datasets import load_iris
>>> data = load_iris()
>>> clf = IBk(k=3).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.

KStar

class weka.lazy.KStar(_WekaSupervisedMixin, Classifier)

K\* — entropy-based instance classifier (hub key weka.KStar).

Wraps weka.classifiers.lazy.KStar. Instead of a geometric distance it uses an entropic measure — the complexity of transforming one instance into another — which handles mixed numeric and symbolic attributes coherently.
Constructor
__init__(
    self,
    global_blend: int = 20,
    missing_mode: str = 'average',
    entropic_auto_blend: bool = False,
    nominal_features: Optional[Sequence[int]] = None,
    options: Optional[Sequence[str]] = None,
)

Parameters

global_blend
int = 20
Blending parameter as a percentage (Weka -B), between 0 and 100. 0 behaves like nearest-neighbour, 100 weights all instances equally.
missing_mode
{'average', 'ignore', 'max', 'normal'} = 'average'
How missing values are treated (Weka -M with a/d/m/n).
entropic_auto_blend
bool = False
Set the blend automatically from the data (Weka -E).
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.

References

Cleary1995
Cleary, J.G. and Trigg, L.E. (1995). *K: An Instance-based Learner Using an Entropic Distance Measure.* Proceedings of the 12th International Conference on Machine Learning*, 108-114.
python
>>> from tuiml.weka import KStar
>>> from tuiml.datasets import load_iris
>>> data = load_iris()
>>> clf = KStar(global_blend=20).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.

LWL

class weka.lazy.LWL(_WekaSupervisedMixin, Regressor)

LWL — locally weighted learning (hub key weka.LWL).

Wraps weka.classifiers.lazy.LWL. For each query it weights the training instances by their distance to that query and fits the base learner on the weighted set, which turns a global model into a local one.
Constructor
__init__(
    self,
    k_nn: int = ...,
    weighting_kernel: int = 0,
    base_classifier: str = 'weka.classifiers.trees.DecisionStump',
    nominal_features: Optional[Sequence[int]] = None,
    options: Optional[Sequence[str]] = None,
)

Parameters

k_nn
int = -1
Neighbours used for setting the kernel bandwidth (Weka -K); -1 uses all training instances.
weighting_kernel
int = 0
Weighting kernel (Weka -U): 0 linear, 1 epanechnikov, 2 tricube, 3 inverse, 4 gaussian, 5 constant.
base_classifier
str = "weka.classifiers.trees.DecisionStump"
Fully-qualified Weka class used as the local model (Weka -W).
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

All the work happens at prediction time: every query refits the base learner, so prediction is far more expensive than training.
python
>>> from tuiml.weka import LWL
>>> import numpy as np
>>> rng = np.random.default_rng(0)
>>> X = rng.normal(size=(60, 2))
>>> y = 2.0 * X[:, 0] + rng.normal(scale=0.1, size=60)
>>> reg = LWL(k_nn=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.