API Reference / weka /

functions.py

Weka function-based learner wrappers.

Learners from weka.classifiers.functions — support vector machines, logistic and linear regression, neural networks — registered under weka. hub keys.

Notes

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

These learners apply their own internal preprocessing: SMO and MultilayerPerceptron normalize numeric attributes and binarize nominal ones by default, so results differ from the same nominal encoding fed to a tree.

Classes

SMO

class weka.functions.SMO(_WekaSupervisedMixin, Classifier)

SMO — support vector classifier (hub key weka.SMO).

Wraps weka.classifiers.functions.SMO, Weka's sequential minimal optimization trainer for support vector machines.
Constructor
__init__(
    self,
    c: float = 1.0,
    kernel: str = 'weka.classifiers.functions.supportVector.PolyKernel',
    kernel_options: Optional[Sequence[str]] = None,
    nominal_features: Optional[Sequence[int]] = None,
    options: Optional[Sequence[str]] = None,
)

Parameters

c
float = 1.0
Complexity / regularization constant (Weka -C).
kernel
str = "weka.classifiers.functions.supportVector.PolyKernel"
Fully-qualified Weka kernel class (Weka -K). The common alternatives are ...supportVector.RBFKernel and ...supportVector.Puk.
kernel_options
sequence of str or None = None
Options passed to the kernel, e.g. ["-E", "2"] for a quadratic polynomial or ["-G", "0.01"] for an RBF gamma.
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

SMO is a binary learner; Weka handles multiclass targets internally by pairwise coupling, so no extra wrapping is needed here.

By default SMO normalizes the training data itself and fits a linear PolyKernel, which is why its numbers differ from an unnormalized scikit-learn SVC with the same C.

python
>>> from tuiml.weka import SMO
>>> from tuiml.datasets import load_iris
>>> data = load_iris()
>>> clf = SMO(c=1.0).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.

SMOreg

class weka.functions.SMOreg(_WekaSupervisedMixin, Regressor)

SMOreg — support vector regressor (hub key weka.SMOreg).

Wraps weka.classifiers.functions.SMOreg, the regression counterpart of SMO.
Constructor
__init__(
    self,
    c: float = 1.0,
    kernel: str = 'weka.classifiers.functions.supportVector.PolyKernel',
    kernel_options: Optional[Sequence[str]] = None,
    nominal_features: Optional[Sequence[int]] = None,
    options: Optional[Sequence[str]] = None,
)

Parameters

c
float = 1.0
Complexity / regularization constant (Weka -C).
kernel
str = "weka.classifiers.functions.supportVector.PolyKernel"
Fully-qualified Weka kernel class (Weka -K).
kernel_options
sequence of str or None = None
Options passed to the kernel.
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 SMOreg
>>> 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 = SMOreg().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.

Logistic

class weka.functions.Logistic(_WekaSupervisedMixin, Classifier)

Logistic — multinomial logistic regression (hub key weka.Logistic).

Wraps weka.classifiers.functions.Logistic, ridge-penalized multinomial logistic regression fitted by quasi-Newton optimization.
Constructor
__init__(
    self,
    ridge: float = 1e-08,
    max_its: int = ...,
    nominal_features: Optional[Sequence[int]] = None,
    options: Optional[Sequence[str]] = None,
)

Parameters

ridge
float = 1e-8
Ridge penalty (Weka -R).
max_its
int = -1
Maximum optimizer iterations (Weka -M); -1 runs until convergence.
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 Logistic
>>> from tuiml.datasets import load_iris
>>> data = load_iris()
>>> clf = Logistic().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.

SimpleLogistic

class weka.functions.SimpleLogistic(_WekaSupervisedMixin, Classifier)

SimpleLogistic — logistic regression fitted by LogitBoost (hub key weka.SimpleLogistic).

Wraps weka.classifiers.functions.SimpleLogistic. Fits linear logistic models with LogitBoost over simple regression functions, using cross-validation to pick the number of boosting iterations, which performs built-in attribute selection.
Constructor
__init__(
    self,
    num_boosting_iterations: int = 0,
    use_cross_validation: bool = True,
    heuristic_stop: int = 50,
    nominal_features: Optional[Sequence[int]] = None,
    options: Optional[Sequence[str]] = None,
)

Parameters

num_boosting_iterations
int = 0
Fixed number of boosting iterations (Weka -I); 0 selects the count by cross-validation.
use_cross_validation
bool = True
Choose the iteration count by cross-validation. Passing False emits Weka's -S flag to use the training error instead.
heuristic_stop
int = 50
Stop early if the minimum has not moved for this many iterations (Weka -H). Set to 0 to disable the heuristic.
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 SimpleLogistic
>>> from tuiml.datasets import load_iris
>>> data = load_iris()
>>> clf = SimpleLogistic().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.

LinearRegression

class weka.functions.LinearRegression(_WekaSupervisedMixin, Regressor)

LinearRegression — least squares with attribute selection (hub key weka.LinearRegression).

Wraps weka.classifiers.functions.LinearRegression.
Constructor
__init__(
    self,
    attribute_selection: str = 'm5',
    ridge: float = 1e-08,
    eliminate_colinear: bool = True,
    nominal_features: Optional[Sequence[int]] = None,
    options: Optional[Sequence[str]] = None,
)

Parameters

attribute_selection
{'m5', 'none', 'greedy'} = 'm5'
Attribute selection method (Weka -S as 0/1/2).
ridge
float = 1e-8
Ridge penalty (Weka -R).
eliminate_colinear
bool = True
Remove collinear attributes. Passing False emits Weka's -C flag to keep them.
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

Weka's default runs M5 attribute selection and collinearity removal, so it does not reproduce a plain ordinary-least-squares fit. Pass attribute_selection='none' and eliminate_colinear=False for that.
python
>>> from tuiml.weka import LinearRegression
>>> 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 = LinearRegression().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.

SimpleLinearRegression

class weka.functions.SimpleLinearRegression(_WekaSupervisedMixin, Regressor)

SimpleLinearRegression — least squares on one attribute (hub key weka.SimpleLinearRegression).

Wraps weka.classifiers.functions.SimpleLinearRegression. Fits a straight line on whichever single attribute yields the lowest squared error — the regression counterpart of OneR.
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 SimpleLinearRegression
>>> 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 = SimpleLinearRegression().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.

MultilayerPerceptron

class weka.functions.MultilayerPerceptron(_WekaSupervisedMixin, Classifier)

MultilayerPerceptron — backpropagation neural network (hub key weka.MultilayerPerceptron).

Wraps weka.classifiers.functions.MultilayerPerceptron.
Constructor
__init__(
    self,
    hidden_layers: str = 'a',
    learning_rate: float = 0.3,
    momentum: float = 0.2,
    training_time: int = 500,
    seed: int = 0,
    nominal_features: Optional[Sequence[int]] = None,
    options: Optional[Sequence[str]] = None,
)

Parameters

hidden_layers
str = "a"
Hidden layer specification (Weka -H). A comma-separated list of node counts, or one of Weka's shorthands: "a" for (attribs + classes) / 2, "i", "o", "t".
learning_rate
float = 0.3
Learning rate (Weka -L).
momentum
float = 0.2
Momentum (Weka -M).
training_time
int = 500
Number of epochs (Weka -N).
seed
int = 0
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

Weka normalizes attributes and the numeric class internally by default, and training runs for the full training_time epochs, which makes this the slowest learner in the package on large data.
python
>>> from tuiml.weka import MultilayerPerceptron
>>> from tuiml.datasets import load_iris
>>> data = load_iris()
>>> clf = MultilayerPerceptron(training_time=50).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.

GaussianProcesses

class weka.functions.GaussianProcesses(_WekaSupervisedMixin, Regressor)

GaussianProcesses — Gaussian process regression (hub key weka.GaussianProcesses).

Wraps weka.classifiers.functions.GaussianProcesses.
Constructor
__init__(
    self,
    noise: float = 1.0,
    kernel: str = 'weka.classifiers.functions.supportVector.PolyKernel',
    kernel_options: Optional[Sequence[str]] = None,
    nominal_features: Optional[Sequence[int]] = None,
    options: Optional[Sequence[str]] = None,
)

Parameters

noise
float = 1.0
Noise level, as a fraction of the target standard deviation (Weka -N).
kernel
str = "weka.classifiers.functions.supportVector.PolyKernel"
Fully-qualified Weka kernel class (Weka -K).
kernel_options
sequence of str or None = None
Options passed to the kernel.
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

Fitting inverts an n \times n matrix, so cost grows as O(n^3) and memory as O(n^2) — impractical beyond a few thousand training rows.
python
>>> from tuiml.weka import GaussianProcesses
>>> 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 = GaussianProcesses().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.