From 985c50ff3b1e77165e254fc46786eafa3998047a Mon Sep 17 00:00:00 2001 From: Gael Varoquaux Date: Sun, 22 Sep 2013 05:18:57 +0200 Subject: [PATCH] DOC: tweak the cheng_church example Add a visualization of the recovered bi-clustering --- examples/bicluster/plot_cheng_church.py | 28 +++++++++++++++++-------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/examples/bicluster/plot_cheng_church.py b/examples/bicluster/plot_cheng_church.py index 99973fae982ca..8df95b9dc5e2c 100644 --- a/examples/bicluster/plot_cheng_church.py +++ b/examples/bicluster/plot_cheng_church.py @@ -19,6 +19,7 @@ # License: BSD 3 clause from matplotlib import pyplot as plt +import numpy as np from sklearn.datasets import make_msr_biclusters from sklearn.datasets import samples_generator as sg @@ -30,14 +31,30 @@ shuffle=False, random_state=0) +data, row_idx, col_idx = sg._shuffle(data, random_state=0) + +# Fit the biclustering model +model = ChengChurch(n_clusters=3, max_msr=100, random_state=0) +model.fit(data) +score = consensus_score(model.biclusters_, + (rows[:, row_idx], columns[:, col_idx])) + +print "consensus score: {:.1f}".format(score) + +# Plot the affinity matrix + plt.matshow(data, cmap=plt.cm.Blues) plt.title("Original dataset") -data, row_idx, col_idx = sg._shuffle(data, random_state=0) - plt.matshow(data, cmap=plt.cm.Blues) plt.title("Shuffled dataset") +row_order = np.argsort(np.argmax(model.rows_, axis=0), kind='mergesort') +column_order = np.argsort(np.argmax(model.columns_, axis=0), kind='mergesort') +plt.matshow(data[row_order].T[column_order].T[:300], cmap=plt.cm.Blues) +plt.title("Reordered dataset using biclustering") + +# Plot profiles plt.figure() n_cols = data.shape[1] for row in data: @@ -46,13 +63,6 @@ plt.xlabel('column numbers') plt.ylabel('value') -model = ChengChurch(n_clusters=3, max_msr=100, random_state=0) -model.fit(data) -score = consensus_score(model.biclusters_, - (rows[:, row_idx], columns[:, col_idx])) - -print "consensus score: {:.1f}".format(score) - plt.figure() bicluster = model.get_submatrix(0, data)