Weka clusterer wrappers.
Unsupervised learners from
weka.clusterers, registered under weka. hub keys.Notes
Requires the optional Weka extra:
pip install 'tuiml[weka]' plus a Java runtime (11+) on PATH.Classes
SimpleKMeans — k-means clustering (hub key weka.SimpleKMeans).
Wraps
weka.clusterers.SimpleKMeans.
Constructor
__init__( self, n_clusters: int = 2, max_iterations: int = 500, seed: int = 10, nominal_features: Optional[Sequence[int]] = None, options: Optional[Sequence[str]] = None, )
Parameters
n_clusters
int
= 2
Number of clusters (Weka
-N).
max_iterations
int
= 500
Maximum iterations (Weka
-I).
seed
int
= 10
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
labels_
np.ndarray of shape (n_samples,)
Cluster assignment for each training row.
n_clusters_
int
Number of clusters produced.
python
>>> from tuiml.weka import SimpleKMeans
>>> from tuiml.datasets import load_iris
>>> data = load_iris()
>>> km = SimpleKMeans(n_clusters=3, seed=42).fit(data.X)
>>> km.labels_.shape
(150,)
EM — expectation-maximization clustering (hub key weka.EM).
Wraps
weka.clusterers.EM. Fits a mixture of Gaussians and can choose the number of clusters itself by cross-validation.
Constructor
__init__( self, n_clusters: int = ..., max_iterations: int = 100, seed: int = 100, nominal_features: Optional[Sequence[int]] = None, options: Optional[Sequence[str]] = None, )
Parameters
n_clusters
int
= -1
Number of clusters (Weka
-N); -1 selects it by cross-validation.
max_iterations
int
= 100
Maximum EM iterations (Weka
-I).
seed
int
= 100
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 EM
>>> from tuiml.datasets import load_iris
>>> data = load_iris()
>>> em = EM(n_clusters=3, seed=42).fit(data.X)
>>> em.n_clusters_
3
Canopy — cheap approximate pre-clustering (hub key weka.Canopy).
Wraps
weka.clusterers.Canopy. Uses two distance thresholds to form overlapping "canopies" in a single cheap pass, normally as a seeding step for a more expensive algorithm.
Constructor
__init__( self, n_clusters: int = ..., t2: float = ..., t1: float = ..., seed: int = 1, nominal_features: Optional[Sequence[int]] = None, options: Optional[Sequence[str]] = None, )
Parameters
n_clusters
int
= -1
Requested number of clusters (Weka
-N); -1 lets the thresholds decide.
t2
float
= -1.0
Loose distance threshold (Weka
-t2); a negative value asks Weka to derive it from the data.
t1
float
= -1.25
Tight distance threshold (Weka
-t1); a negative value is interpreted as a multiple of t2.
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.
References
McCallum2000
McCallum, A., Nigam, K. and Ungar, L.H. (2000).
Efficient Clustering of High-Dimensional Data Sets with Application
to Reference Matching. KDD '00, 169-178.
python
>>> from tuiml.weka import Canopy
>>> from tuiml.datasets import load_iris
>>> data = load_iris()
>>> cp = Canopy(n_clusters=3, seed=42).fit(data.X)
>>> cp.labels_.shape
(150,)
FarthestFirst — farthest-first traversal clustering (hub key weka.FarthestFirst).
Wraps
weka.clusterers.FarthestFirst. Picks each new centre as the point farthest from the existing ones, which is fast and gives well-separated seeds for k-means.
Constructor
__init__( self, n_clusters: int = 2, seed: int = 1, nominal_features: Optional[Sequence[int]] = None, options: Optional[Sequence[str]] = None, )
Parameters
n_clusters
int
= 2
Number of clusters (Weka
-N).
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 FarthestFirst
>>> from tuiml.datasets import load_iris
>>> data = load_iris()
>>> ff = FarthestFirst(n_clusters=3, seed=42).fit(data.X)
>>> ff.labels_.shape
(150,)
Cobweb — incremental conceptual clustering (hub key weka.Cobweb).
Wraps
weka.clusterers.Cobweb. Builds a hierarchy one instance at a time, guided by category utility. The number of clusters emerges from the data rather than being requested.
Constructor
__init__( self, acuity: float = 1.0, cutoff: float = 0.002, seed: int = 42, nominal_features: Optional[Sequence[int]] = None, options: Optional[Sequence[str]] = None, )
Parameters
acuity
float
= 1.0
Minimum standard deviation allowed for a numeric attribute (Weka
-A).
cutoff
float
= 0.002
Category utility threshold below which a node is pruned (Weka
-C).
seed
int
= 42
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 Cobweb
>>> from tuiml.datasets import load_iris
>>> data = load_iris()
>>> cw = Cobweb().fit(data.X)
>>> cw.labels_.shape
(150,)
HierarchicalClusterer — agglomerative clustering (hub key weka.HierarchicalClusterer).
Wraps
weka.clusterers.HierarchicalClusterer. Merges the closest pair of clusters repeatedly under the chosen linkage until the requested number of clusters remains.
Constructor
__init__( self, n_clusters: int = 2, link_type: str = 'SINGLE', nominal_features: Optional[Sequence[int]] = None, options: Optional[Sequence[str]] = None, )
Parameters
n_clusters
int
= 2
Number of clusters (Weka
-N).
link_type
str
= "SINGLE"
Linkage criterion (Weka
-L): one of SINGLE, COMPLETE, AVERAGE, MEAN, CENTROID, WARD, ADJCOMPLETE, NEIGHBOR_JOINING.
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 HierarchicalClusterer
>>> from tuiml.datasets import load_iris
>>> data = load_iris()
>>> hc = HierarchicalClusterer(n_clusters=3, link_type="COMPLETE").fit(data.X)
>>> hc.labels_.shape
(150,)