DIANA: Bisecting Kmeans¶
toyml.clustering.bisect_kmeans.BisectingKmeans
dataclass
¶
Bisecting K-means algorithm. Belong to Divisive hierarchical clustering (DIANA) algorithm.(top-down)
Examples:
>>> from toyml.clustering import BisectingKmeans
>>> dataset = [[1.0, 1.0], [1.0, 2.0], [2.0, 1.0], [10.0, 1.0], [10.0, 2.0], [11.0, 1.0]]
>>> bisect_kmeans = BisectingKmeans(k=3)
>>> labels = bisect_kmeans.fit_predict(dataset)
>>> clusters = bisect_kmeans.cluster_tree_.get_clusters()
References
- Harrington
- Tan
See Also
- K-means algorithm: toyml.clustering.kmeans
cluster_tree_
class-attribute
instance-attribute
¶
cluster_tree_: ClusterTree = field(default_factory=ClusterTree)
The cluster tree
labels_
class-attribute
instance-attribute
¶
The cluster labels of the dataset.
fit
¶
Fit the dataset with Bisecting K-means algorithm.
PARAMETER | DESCRIPTION |
---|---|
dataset |
The set of data points for clustering. |
RETURNS | DESCRIPTION |
---|---|
'BisectingKmeans'
|
self. |
Source code in toyml/clustering/bisect_kmeans.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
|
fit_predict
¶
Fit and predict the cluster label of the dataset.
PARAMETER | DESCRIPTION |
---|---|
dataset |
The set of data points for clustering. |
RETURNS | DESCRIPTION |
---|---|
list[int]
|
Cluster labels of the dataset samples. |
Source code in toyml/clustering/bisect_kmeans.py
210 211 212 213 214 215 216 217 218 219 220 |
|
predict
¶
Predict the cluster label of the given points.
PARAMETER | DESCRIPTION |
---|---|
points |
A list of data points to predict. |
RETURNS | DESCRIPTION |
---|---|
list[int]
|
A list of predicted cluster labels for the input points. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the model has not been fitted yet. |
Source code in toyml/clustering/bisect_kmeans.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
|