Skip to content

Commit b8beed8

Browse files
committed
Fixed issue with old code
1 parent 4c70143 commit b8beed8

1 file changed

Lines changed: 21 additions & 16 deletions

File tree

Hiearchical_Clustering/hierarchical_clustering.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,35 @@
22
import pandas as pd
33
import matplotlib.pyplot as plt
44
import scipy.cluster.hierarchy as shc
5-
from sklearn.cluster import AgglomerativeClustering
65
import seaborn as sns
76

7+
# Clean data a bit
88
data_scaled = pd.read_csv("SurvivalNormal.csv", sep=",")
9-
# Remove row numbers
109
data_scaled = data_scaled.drop("Unnamed: 0", axis=1)
1110
data_scaled.head()
1211

13-
print(data_scaled)
14-
print(data_scaled.columns)
15-
16-
# Create Graphs
12+
# Dendogram
1713
plt.figure(figsize=(100, 7))
18-
plt.title("Dendrograms")
19-
dend = shc.dendrogram(shc.linkage(data_scaled, method='ward'))
20-
plt.show()
21-
22-
cluster = AgglomerativeClustering(n_clusters=5, affinity='euclidean', linkage='ward')
23-
cluster.fit_predict(data_scaled)
24-
25-
fig, ax = plt.subplots(figsize=(20, 10))
26-
sns.heatmap(data_scaled.corr(), center=0, annot=False, ax=ax)
14+
plt.title("Dendrogram: Gene Expression & Survival")
15+
matrix = shc.linkage(data_scaled.transpose(), method='ward', metric='euclidean')
16+
dend = shc.dendrogram(matrix, labels=data_scaled.columns)
2717
plt.show()
2818

29-
sns.clustermap(data_scaled, metric='correlation', xticklabels=True)
19+
# Clustermap
20+
rowcolors = data_scaled["SURVIVAL"].map({0: "blue", 1: "red"})
21+
cmap = sns.clustermap(data_scaled, method='ward', metric='euclidean', row_colors=rowcolors, xticklabels=True,
22+
dendrogram_ratio=0.05)
23+
# Hide dendograms
24+
cmap.ax_col_dendrogram.set_visible(False)
25+
cmap.ax_row_dendrogram.set_visible(False)
26+
cmap.ax_cbar.set_visible(False)
27+
# Set text sizes on labels
28+
for label in cmap.ax_row_colors.get_xticklabels():
29+
label.set(fontsize='x-small')
30+
for label in cmap.ax_heatmap.get_xticklabels():
31+
label.set(fontsize='x-small')
32+
for label in cmap.ax_heatmap.get_yticklabels():
33+
label.set(fontsize='xx-small')
34+
cmap.fig.suptitle('Heatmap: Gene Expression & Survival')
3035
plt.show()
3136

0 commit comments

Comments
 (0)