milia.cluster.consensus#
Consensus (ensemble) clustering through a co-association matrix (Fred and Jain, 2005).
Several clusterings of the same rows vote on whether each pair belongs
together; the share of votes is a similarity, and average-linkage clustering of
1 - share gives the consensus partition. Pairs that the members disagree
on end up between clusters rather than forced into one.
Functions
|
Share of labellings that put each pair of rows in the same (non-noise) cluster. |
Classes
|
Consensus of several clusterers, or of one clusterer over several seeds. |
- milia.cluster.consensus.coassociation(labelings)#
Share of labellings that put each pair of rows in the same (non-noise) cluster.
- Parameters:
labelings (
list[ndarray]) – Several labellings of the same rows.- Return type:
- Returns:
Square matrix of shares,
1on the diagonal for non-noise rows.
Examples
>>> coassociation([np.array([0, 0, 1]), np.array([0, 1, 1])])[0].tolist() [1.0, 0.5, 0.0]
- class milia.cluster.consensus.Consensus(estimators=None, n_clusters=3)#
Bases:
BaseClustererConsensus of several clusterers, or of one clusterer over several seeds.
- Parameters:
estimators (
list[BaseEstimator] |None) – Member clusterers; k-means with five seeds by default.n_clusters (
int) – Clusters in the consensus partition (also set on members that taken_clusters).
- Variables:
coassociation – The co-association matrix of the training rows.
Examples
>>> rng = np.random.default_rng(0) >>> X = np.repeat(np.array([[0.0, 0.0], [6.0, 6.0], [0.0, 6.0]]), 20, axis=0) + rng.normal( ... scale=0.4, size=(60, 2) ... ) >>> model = Consensus(n_clusters=3).fit(X) >>> model.n_clusters_, model.coassociation_.shape (3, (60, 60))