Answers.Body: <p>Based on your description I think you should have a look at a technique called 'biclustering'. </p>
  
  <p>The example on <a href="https://en.wikibooks.org/wiki/Data_Mining_Algorithms_In_R/Clustering/Biclust" rel="nofollow noreferrer">this page</a> 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.'</p>
  
  <p>Since your examples are python-based, you could check out <a href="http://scikit-learn.org/stable/modules/biclustering.html" rel="nofollow noreferrer">scikit-learn's implementations of biclustering</a>.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-29T13:35:13.640Z
Answers.Text: 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
Answers.UserDisplayName: Johannes Schätzl
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-30T18:13:58.490Z
Answers.Text: I would second scitest-learn as the approach
Answers.UserDisplayName: M__
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-28T10:00:39.167Z
Answers.LastActivityDate: 2017-10-28T10:00:39.167Z
Answers.UserDisplayName: holmrenser
Body: <p>I have a heatmap and I would like to find some rectangles.
  <a href="https://i.sstatic.net/eUJrR.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/eUJrR.jpg" alt="enter image description here"></a></p>
  
  <p>I have already used <a href="http://seaborn.pydata.org/generated/seaborn.clustermap.html" rel="nofollow noreferrer">clustermap</a>. But here, I can not calculate these rectangles.
  The order of the data should not be changed.</p>
  
  <p>This Code is not working: </p>
  
  <pre><code>import pandas as pd
  import matplotlib.pyplot as plt
  import seaborn as sns
  tips2 = pd.read_csv('heatmapExport.csv')
  sns.set(color_codes=True)
  g = sns.clustermap(tips2, cbar="false")
  plt.show()
  </code></pre>
  
  <p>Does somebody have an idea?</p>
  
  <p>Thanks a lot</p>
  
  <p>Here is an example of what I want:</p>
  
  <p><a href="https://i.sstatic.net/3tgrc.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/3tgrc.jpg" alt="enter image description here"></a></p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-10-18T07:15:56.773Z
Comments.Text: 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...) ?
Comments.UserDisplayName: llrs
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-10-18T07:42:13.617Z
Comments.Text: Yes, pd is pandas. I want to calculate the sum of the rectangles. I have a 2d array with float values. In this array I would like to find clusters. Optical are these clusters to be recognized in the heatmap. It would be good now if I had an algorithm that recognizes these figures and calculates the sum in the clusters.
Comments.UserDisplayName: Johannes Schätzl
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-10-18T08:01:17.687Z
Comments.Text: It is therefore important that the points are not viewed independently of each other.
Comments.UserDisplayName: Johannes Schätzl
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-10-18T08:30:32.407Z
Comments.Text: Sorry, but I don't understand. Do you want an algorithm that for the manually selected rectangles sum the values? Why don't you calculate it manually selecting the positions of the rectangles? BTW, what is the purpose of this/the biological question ?
Comments.UserDisplayName: llrs
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-10-18T08:42:46.763Z
Comments.Text: Okay, I think I've said this wrong. Step 1: The algorithm is to form clusters. Step 2: The recheck should be entered into the heatmap. Step 3: Calculate the sum of the rectangles.
Comments.UserDisplayName: Johannes Schätzl
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-10-18T08:57:23.563Z
Comments.Text: What is "the recheck"?  How do you define the rectangles?A rectangle is a cluster of samples and genes?
Comments.UserDisplayName: llrs
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-10-18T09:17:10.177Z
Comments.Text: Oh sorry, recheck = rectangle... Sorry typo!
Comments.UserDisplayName: Johannes Schätzl
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-10-18T09:19:08.477Z
Comments.Text: A rectangle is to form the cluster in which n * m data points are located
Comments.UserDisplayName: Johannes Schätzl
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-10-18T14:37:14.663Z
Comments.Text: Can you give us a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) with some sample data, the rules to find the cluster ('recognizing optically' is not exact enough), and the expected results?
Comments.UserDisplayName: BioGeek
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-10-19T08:32:53.577Z
Comments.Text: See the edited question above
Comments.UserDisplayName: Johannes Schätzl
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-10-19T08:46:32.553Z
Comments.Text: 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.
Comments.UserDisplayName: bli
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-10-19T08:49:21.053Z
Comments.Text: Also, edit your question to add an explanation of what you mean by "This Code is not working". That's an important point.
Comments.UserDisplayName: bli
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-10-19T10:24:06.407Z
Comments.Text: I agree with @bli, If you could explain how do you want to make those clusters something could be done, but without knowing how do you want them we can't help you :(
Comments.UserDisplayName: llrs
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-10-19T12:34:32.023Z
Comments.Text: I do not exactly know how to Form this clusters. This is one part of my Question. The criteria would be to find a Minimum number of clusters that "fit" the  I mean if you look at the heatmap. You can See this clusters without having any criteria. This is what i Want i do. But the Algorithm can Not Look at the points Independent of each other.
Comments.UserDisplayName: Johannes Schätzl
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-10-23T09:25:11.667Z
Comments.Text: Does anyone have an idea how to deal with the problem?
Comments.UserDisplayName: Johannes Schätzl
Tags: <python><clustering>
Title: Find Patterns in Cluster
ThreadText: # Find Patterns in Cluster
  
  (Asked by: username_0 on 2017-10-17)
  
  I have a heatmap and I would like to find some rectangles.
  [![enter image description here](https://i.sstatic.net/eUJrR.jpg)](https://i.sstatic.net/eUJrR.jpg)
  
  I have already used [clustermap](http://seaborn.pydata.org/generated/seaborn.clustermap.html). 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
  tips2 = pd.read_csv('heatmapExport.csv')
  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:
  
  [![enter image description here](https://i.sstatic.net/3tgrc.jpg)](https://i.sstatic.net/3tgrc.jpg)
  
  **Tags:** python, clustering
  
  > **Comments:**
  > **username_1**: 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...) ?  
  > **username_0**: Yes, pd is pandas. I want to calculate the sum of the rectangles. I have a 2d array with float values. In this array I would like to find clusters. Optical are these clusters to be recognized in the heatmap. It would be good now if I had an algorithm that recognizes these figures and calculates the sum in the clusters.  
  > **username_0**: It is therefore important that the points are not viewed independently of each other.  
  > **username_1**: Sorry, but I don't understand. Do you want an algorithm that for the manually selected rectangles sum the values? Why don't you calculate it manually selecting the positions of the rectangles? BTW, what is the purpose of this/the biological question ?  
  > **username_0**: Okay, I think I've said this wrong. Step 1: The algorithm is to form clusters. Step 2: The recheck should be entered into the heatmap. Step 3: Calculate the sum of the rectangles.  
  > **username_1**: What is "the recheck"?  How do you define the rectangles?A rectangle is a cluster of samples and genes?  
  > **username_0**: Oh sorry, recheck = rectangle... Sorry typo!  
  > **username_0**: A rectangle is to form the cluster in which n * m data points are located  
  > **username_2**: Can you give us a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) with some sample data, the rules to find the cluster ('recognizing optically' is not exact enough), and the expected results?  
  > **username_0**: See the edited question above  
  > **username_3**: 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.  
  > **username_3**: Also, edit your question to add an explanation of what you mean by "This Code is not working". That's an important point.  
  > **username_1**: I agree with @username_3, If you could explain how do you want to make those clusters something could be done, but without knowing how do you want them we can't help you :(  
  > **username_0**: I do not exactly know how to Form this clusters. This is one part of my Question. The criteria would be to find a Minimum number of clusters that "fit" the  I mean if you look at the heatmap. You can See this clusters without having any criteria. This is what i Want i do. But the Algorithm can Not Look at the points Independent of each other.  
  > **username_0**: Does anyone have an idea how to deal with the problem?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_4 on 2017-10-28. Score: 3
  
  Based on your description I think you should have a look at a technique called 'biclustering'.
  
  The example on [this page](https://en.wikibooks.org/wiki/Data_Mining_Algorithms_In_R/Clustering/Biclust) 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](http://scikit-learn.org/stable/modules/biclustering.html).
  
  > **Comments:**
  > **username_0**: 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  
  > **username_5**: I would second scitest-learn as the approach  
  
  ---
  
  