CLUSTERING
SpectralCoclustering
Spectral Co-Clustering algorithm (Dhillon, 2001) [1]_.
Example of usage
Python API reference included; executable data demonstration pending review.
Usage / limitations
+Use when: Discover latent groups.
−Limitations: Check input requirements, mathematical assumptions and version-specific behaviour before using.
Mathematical formula
See method documentation: implementation and assumptions vary.
Sample dataShow
{
"variable": "purchases",
"domain": "Retail product affinity analysis",
"rows": [
"new_customers",
"casual_customers",
"members",
"loyal_members"
],
"columns": [
"food",
"beverages",
"electronics",
"homewares"
],
"values": [
[
9,
8,
1,
1
],
[
8,
9,
1,
1
],
[
1,
1,
9,
8
],
[
1,
1,
8,
9
]
]
}
Code example (Python)
# DataLens.ai example — sample retail product data
purchases = {'variable': 'purchases', 'domain': 'Retail product affinity analysis', 'rows': ['new_customers', 'casual_customers', 'members', 'loyal_members'], 'columns': ['food', 'beverages', 'electronics', 'homewares'], 'values': [[9, 8, 1, 1], [8, 9, 1, 1], [1, 1, 9, 8], [1, 1, 8, 9]]}
# DataLens.ai example
# Domain: Retail product affinity analysis.
# The sample data above are included automatically when copied.
import numpy as np
from sklearn.cluster import SpectralCoclustering
# Build the numeric feature matrix from named customer attributes.
# Fit or evaluate the requested clustering technique.
# Segment customer cohorts and product groups at the same time.
purchases_matrix = np.array(purchases["values"], dtype=float)
model = SpectralCoclustering(n_clusters=2, random_state=0).fit(purchases_matrix)
assert len(model.row_labels_) == 4 and len(set(model.row_labels_)) == 2
# All checks passed; no exception was raised.
print("Expected output verified")
# DataLens.ai example
# Domain: Retail product affinity analysis.
# The sample data above are included automatically when copied.
import numpy as np
from sklearn.cluster import SpectralCoclustering
# Build the numeric feature matrix from named customer attributes.
# Fit or evaluate the requested clustering technique.
# Segment customer cohorts and product groups at the same time.
purchases_matrix = np.array(purchases["values"], dtype=float)
model = SpectralCoclustering(n_clusters=2, random_state=0).fit(purchases_matrix)
assert len(model.row_labels_) == 4 and len(set(model.row_labels_)) == 2
# All checks passed; no exception was raised.
print("Expected output verified")