38. row 10, col 2, df.corr() and sns.cluster for brain networks
info
- plotting label: clustermap
- title: Discovering structure in heatmap data
- download file name: structureed_heatmap.py
description
- It is a brain network hierachy.
- There are three levels - network, node, and hemi(left or right).
- There are many rows in the input csv file in wide-form format.
- From function corr, the matrix of correlations are created
- all the pair between itself and the rest hemis.
- For itself, the correlation value is 1.
- The values are mapped into color for easy visualization.
- The method is high-level.
- The plotting information is in detail.
- In later plotting #40, a distribution plotting will be addressed for the the same data, not in detail.
------------- step 1: examine the data... ------------------------------
df = sns.load_dataset("brain_networks", header=[0, 1, 2], index_col=0)
used_networks = [1, 5, 6, 7, 8, 12, 13, 17]
used_columns = (df.columns.get_level_values("network")
.astype(int)
.isin(used_networks))
df = df.loc[:, used_columns]
print('df')
'''
network 1 5 ...17
node 1 1 ...
hemi lh rh lh rh ...
0 56.055744 92.031036 -35.898861 -1.889181...
1 55.547253 43.690075 19.568010 15.902983...
'''
note 1: There are 3 lines for dataframe heading.
note 2: The hierarchy of brain networks data are network, node, left or right.
note 3: the values are like 56.0, 15.90... for each hemi
-------------------- step 2: generate the corrections form the data ----
df.corr() is the function argument in method sns.clustermap.
It genenerates correlations from the data.
'''
network 1 5
node 1 1
hemi lh rh lh rh
network node hemi
1 1 lh 1.000000 0.881516 0.431619 0.418708
rh 0.881516 1.000000 0.431953 0.519916
5 1 lh 0.431619 0.431953 1.000000 0.822897
rh 0.418708 0.519916 0.822897 1.000000
'''
note 1: The values are like 0.88, 0.5, 1...
note 2: 1 means 100% correlation, it refers itself.
note 3: 0 means no correlation.
note 4: minus means opposite correlations.
----------------- step 3: code for plotting -------
- method: sns.clustermap
- It maps all the hemi and convert its corr values to the cell colors
- Also, the hierachy is provided to group many clusters.