# Find Patterns in Cluster

I have a heatmap and I would like to find some rectangles.

I have already used clustermap. But here, I can not calculate these rectangles. The order of the data should not be changed.

This Code is not working:

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(color_codes=True)
g = sns.clustermap(tips2, cbar="false")
plt.show()


Does somebody have an idea?

Thanks a lot

Here is an example of what I want:

• What is pd, pandas? And sns? What are the reasons to select those rectangles and not others (without the reasons it will be hard to find a solution)? Why do you say the code is not working, how does it fail (which error, what is the output compared to the expected output...) ?
– llrs
Oct 18, 2017 at 7:15
• What is "the recheck"? How do you define the rectangles?A rectangle is a cluster of samples and genes?
– llrs
Oct 18, 2017 at 8:57
• Can you give us a Minimal, Complete, and Verifiable example with some sample data, the rules to find the cluster ('recognizing optically' is not exact enough), and the expected results? Oct 18, 2017 at 14:37
• Your example says "Cluster (for example)". Did you have criteria in mind to delimit the rectangles this way? Has the delimitation of rectangles an influence on the delimitation of others (for instance, by forbidding overlaps)? I think your question amounts to being able to formalize an intuition you have about how to form those rectangles.
– bli
Oct 19, 2017 at 8:46
• Also, edit your question to add an explanation of what you mean by "This Code is not working". That's an important point.
– bli
Oct 19, 2017 at 8:49

Based on your description I think you should have a look at a technique called 'biclustering'.

The example on this page defines the goal of this technique as 'Finding subgroups of rows and columns which are as similar as possible to each other and as different as possible to the rest.'

Since your examples are python-based, you could check out scikit-learn's implementations of biclustering.

• Many thanks for your response. I have implemented the algorithm as described. He does (almost) what I want. Now I have only one problem: I would not re-sort the rows and columns. For example, the algorithm says: Cluster 1 [line 1,3,4; Columns 1, 2, 3] Cluster 2 [line 2; Column 4]. I would like to know the result, however, the other way around. Lines 1.2 Columns 1 -> cluster 1; Lines 3.4 columns 2,3 -> clusters 2, ... etc. At all, it is important that the different Clusters Switch between rows and cols. If one Cluster has finished, no Datapoint should be add to this cluster Oct 29, 2017 at 13:35
• I would second scitest-learn as the approach
– M__
Jan 30, 2019 at 18:13