What is cluster map?

What is cluster map?#

Plot a matrix dataset as a hierarchically-clustered heatmap.

http://seaborn.pydata.org/generated/seaborn.clustermap.html?highlight=clustermap#seaborn.clustermap

import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

%matplotlib inline
# laod flight data set
iris = sns.load_dataset("iris")
iris.head()
sepal_length sepal_width petal_length petal_width species
0 5.1 3.5 1.4 0.2 setosa
1 4.9 3.0 1.4 0.2 setosa
2 4.7 3.2 1.3 0.2 setosa
3 4.6 3.1 1.5 0.2 setosa
4 5.0 3.6 1.4 0.2 setosa
# Plot a clustered heatmap:
species = iris.pop("species")
sns.clustermap(iris)
<seaborn.matrix.ClusterGrid at 0x163cdf926d0>
../../../_images/9d046e32c5178963d3451d5456072345593dcf76058e4f17c1a4d96a76ee45c9.png
## Use a different similarity metric:
sns.clustermap(iris_data,metric = 'correlation')
<seaborn.matrix.ClusterGrid at 0x1be276a14a8>
../../../_images/0a163ab51cdf1194bf1127b47ea3a81c831c3478e4fc684dd2148a09b862d80c.png
# Use a different clustering method:
sns.clustermap(iris,method = 'single')
<seaborn.matrix.ClusterGrid at 0x163ce3245e0>
../../../_images/e81d6148a05f6e70f71abcbc9a02fb0d08df34ee6fcb61c2d4363d234c41261f.png
# Use a different colormap and ignore outliers in colormap limits:

sns.clustermap(iris, cmap="mako", robust=True)
<seaborn.matrix.ClusterGrid at 0x163ca247070>
../../../_images/a09ce8068f86ec06d72f2adba9cc6d646264a37762a07456a24f53e80a59dd3d.png
# Change the size of the figure:
sns.clustermap(iris, figsize=(6, 7))
<seaborn.matrix.ClusterGrid at 0x163cfcc79d0>
../../../_images/6fb0d697c3e461a971030e838936ea104b7f8feba32b511c8c288ed86e3b7405.png
# Plot one of the axes in its original organization:

sns.clustermap(iris, col_cluster=False)
<seaborn.matrix.ClusterGrid at 0x163d0288250>
../../../_images/3991acc0c5c7c2c6f82cf25e40feb7811d5afad4dc98b688c13d15bae6dc5f31.png
# Add colored labels:

lut = dict(zip(species.unique(), "rbg"))
row_colors = species.map(lut)
g = sns.clustermap(iris, row_colors=row_colors)
../../../_images/691880320b6781733e7dab160665e262ff5bd6c57f4ae673dc5cf955f46d68c5.png
# Standardize the data within the columns:

sns.clustermap(iris, standard_scale=1)
<seaborn.matrix.ClusterGrid at 0x163d05bfa60>
../../../_images/ead569915f14cb3a767fe2b346f4d166d713ec2ceebde832f6034e4ef72e583f.png
# Normalize the data within the rows:

sns.clustermap(iris, z_score=0)
<seaborn.matrix.ClusterGrid at 0x163d0f2ae20>
../../../_images/a93a1e7292a732209f9d4d2c53c65834308d02aa3ed632e61cd0bbc3789df86f.png