Rough K-Means (RoughKMeans)ο
A clustering method where points can belong to multiple clusters, and centers are updated using both definite and possible members.
π Overviewο
RoughKMeans is a clustering algorithm based on rough-set theory. Instead of assigning each sample to exactly one cluster, it defines:
Lower approximation (L): samples that definitely belong to a cluster.
Upper approximation (U): samples that possibly belong to a cluster (including the lower set).
It computes per-cluster thresholds (alpha and beta) to distinguish core vs. fringe members, then updates cluster centroids by mixing core and fringe means.
βοΈ Class Definitionο
class rough_kmeans.RoughKMeans(
n_clusters: int = 2,
weight_lower: float = 0.7,
max_iter: int = 100,
tol: float = 1e-4
)
π Parametersο
Parameter |
Type |
Default |
Description |
|---|---|---|---|
n_clusters |
|
|
Number of clusters to form. |
weight_lower |
|
|
Weight for averaging between lower and fringe regions when updating means. |
max_iter |
|
|
Maximum number of iterations for convergence. |
tol |
|
|
Tolerance for centroid movement to declare convergence. |
π Usage Examplesο
from soft_clustering import RoughKMeans
import numpy as np
# Create sample dataset
X = np.array([
[1.0, 2.0],
[1.2, 1.9],
[0.8, 2.1],
[8.0, 8.0],
[8.2, 7.8],
[7.9, 8.3]
])
# Initialize and fit the model
model = RoughKMeans(n_clusters=2, weight_lower=0.6, max_iter=50, tol=1e-3)
results = model.fit_predict(X)
print("Lower approximation:\n", results['lower_approx'])
print("Upper approximation:\n", results['upper_approx'])
print("Centroids:\n", results['centroids'])
print("Iterations:", results['n_iter'])
π οΈ Methodsο
fit_predict(X)ο
Perform Rough K-Means clustering using interval-set approximations.
Parameters:
X(np.ndarray, shape(n_samples, n_features)): Feature matrix of input data.
Returns:
result(dict) with:lower_approx(np.ndarray, shape(n_samples, n_clusters)): Binary matrix indicating definite membership.upper_approx(np.ndarray, shape(n_samples, n_clusters)): Binary matrix indicating possible membership.centroids(np.ndarray, shape(n_clusters, n_features)): Final cluster centers.n_iter(int): Total number of iterations executed.
π Implementation Notesο
Centroid Initialization: Centroids are randomly initialized from the dataset.
π Referenceο
Lingras, P., & West, C. (2004). Interval Set Clustering of Web Users with Rough K-Means. Journal of Intelligent Information Systems, 23(1), 5-16.(https://link.springer.com/article/10.1023/B:JIIS.0000029668.88665.1a)