/ Python And R Data science skills: 91 clustered maps

Sunday 18 February 2018

91 clustered maps

91 clustered maps
In [1]:
import seaborn as sns
%matplotlib inline
flights = sns.load_dataset('flights')
tips = sns.load_dataset('tips')

clustermap

The clustermap uses hierarchal clustering to produce a clustered version of the heatmap. For example:

In [2]:
fpt = flights.pivot_table(values='passengers',index='month',columns='year')
sns.heatmap(fpt)
Out[2]:
<matplotlib.axes._subplots.AxesSubplot at 0xb6bac88>
In [7]:
sns.clustermap(fpt)
Out[7]:
<seaborn.matrix.ClusterGrid at 0x8316f28>

Notice now how the years and months are no longer in order, instead they are grouped by similarity in value (passenger count). That means we can begin to infer things from this plot, such as August and July being similar (makes sense, since they are both summer travel months)

In [6]:
# More options to get the information a little clearer like normalization
sns.clustermap(fpt,cmap='coolwarm',standard_scale=1)
Out[6]:
<seaborn.matrix.ClusterGrid at 0x8316ef0>

No comments:

Post a Comment