本筆記來源于B站Up主: 有Li 的影像組學(xué)的系列教學(xué)視頻
本節(jié)(26)主要講解: 影像組學(xué)特征相關(guān)系數(shù)熱圖heatmap的Python實(shí)現(xiàn)
- 導(dǎo)入工具包
# The code below is modified from
# https://www.machinelearningplus.com/plots/top-50-matplotlib-visualizations-the-master-plots-python/
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
- 導(dǎo)入并查看數(shù)據(jù)
# import dataset
df = pd.read_csv('https://raw.githubusercontent.com/selva86/datasets/master/mtcars.csv')
print(df.head(5))
print(df.corr().head(5))
# method 參數(shù)默認(rèn)計(jì)算 pearson相關(guān)系數(shù),其它還可以計(jì)算“spearman”,"kendall"相關(guān)系數(shù)
- 繪制相關(guān)系數(shù)熱圖
# Heatmap plot
plt.figure(figsize = (12,10),dpi = 80)
sns.heatmap(df.corr(),xticklabels = df.corr().columns, yticklabels = df.corr().columns,
cmap = "RdYlGn",center = 0, annot = True)
# Decoration
plt.title('Correlogram of mtcars',fontsize = 22)
plt.xticks(fontsize = 12)
plt.yticks(fontsize = 12)
plt.show()
結(jié)果如圖:
heatmap.png
- 繪制聚類熱圖
# clustermap
plt.figure(figsize = (12,10),dpi = 80)
sns.clustermap(df.corr(),xticklabels = df.corr().columns, yticklabels = df.corr().columns,
cmap = "RdYlGn",center = 0)
顯示如下:
clustermap.png
視頻中李博士參考的帖子也是學(xué)習(xí)Python繪圖的極佳資料: Top 50 matplotlib Visualizations – The Master Plots (with full python code)