SoftKSC (Soft Kernel Spectral Clustering) Documentationο
π Overviewο
SoftKSC is a semi-supervised kernel spectral clustering algorithm that separates data using two non-parallel hyperplanes. It combines kernel learning with soft clustering logic by modeling confidence scores for both classes.
βοΈ Class Definitionο
Class Name: SoftKSC
This class implements the Soft Kernel Spectral Clustering using a dual-space solution and RBF kernel similarity.
class SoftKSC:
def __init__(self, gamma: float = 1.0, C: float = 1.0):
...
π Parametersο
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
float |
1.0 |
RBF kernel coefficient |
|
float |
1.0 |
Regularization term in the dual formulation |
π Usage Examplesο
from soft_clustering._soft_ksc._soft_ksc import SoftKSC
from sklearn.datasets import make_moons
import numpy as np
X, y = make_moons(n_samples=200, noise=0.1, random_state=42)
y = np.where(y == 0, -1, 1)
# Use 20% labeled, 80% unlabeled
X_labeled = X[:40]
y_labeled = y[:40]
X_unlabeled = X[40:]
model = SoftKSC(gamma=2.0, C=1.0)
model.fit(X_labeled, y_labeled, X_unlabeled)
print("Predicted Labels:", model.predict(X))
print("Soft Probabilities:", model.predict_proba(X))
π₯ Input / π€ Outputο
Input to
fit(X_labeled, y_labeled, X_unlabeled):X_labeled (np.ndarray): Labeled training data (N_l x D)y_labeled (np.ndarray): Class labels in {-1, 1} (N_l,)X_unlabeled (np.ndarray): Unlabeled data (N_u x D)
Returns:
Soft membership probabilities:
predict_proba(X)β (N x 2)Hard cluster predictions:
predict(X)β (N,)
π οΈ Methodsο
fit(X_labeled, y_labeled, X_unlabeled): Fits the model using both labeled and unlabeled datapredict_proba(X): Returns soft membership scores to both classespredict(X): Returns predicted class labels {-1, 1}
π Implementation Notesο
Uses RBF kernel similarity matrix for dual formulation
Solves two linear systems for class-specific projections
Uses relative distance to compute soft assignments
Designed for semi-supervised clustering with partial labels
π Referenceο
Faraki, M., et al. (2013). Soft Kernel Spectral Clustering.