CLUSTERING
SpectralBiclustering
Spectral biclustering (Kluger, 2003) [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 SpectralBiclustering
# Build the numeric feature matrix from named customer attributes.
# Fit or evaluate the requested clustering technique.
# Study a segment/product purchase matrix, not a geometric point cloud.
purchases_matrix = np.array(purchases["values"], dtype=float)
model = SpectralBiclustering(n_clusters=(2,2), random_state=0).fit(purchases_matrix)
assert len(model.row_labels_) == 4 and len(set(model.row_labels_)) == 2 and len(set(model.column_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 SpectralBiclustering
# Build the numeric feature matrix from named customer attributes.
# Fit or evaluate the requested clustering technique.
# Study a segment/product purchase matrix, not a geometric point cloud.
purchases_matrix = np.array(purchases["values"], dtype=float)
model = SpectralBiclustering(n_clusters=(2,2), random_state=0).fit(purchases_matrix)
assert len(model.row_labels_) == 4 and len(set(model.row_labels_)) == 2 and len(set(model.column_labels_)) == 2
# All checks passed; no exception was raised.
print("Expected output verified")