Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelDiai committed Apr 1, 2021
1 parent ed437ce commit b834652
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion cancer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,24 @@ def Cancer(df_cancer, y_cancer, alpha, beta, k, n_iter):
A = graph['adjacency']
G = nx.from_numpy_matrix(A)
pos = nx.spring_layout(G)

# normalize edge weights to plot edges strength
all_weights = []
for (node1,node2,data) in G.edges(data=True):
all_weights.append(data['weight'])
max_weight = max(all_weights)
norm_weights = [3* w / max_weight for w in all_weights]
norm_weights = norm_weights


fig = plt.figure(figsize=(12,12))
# Color labels
color_map = []
color_dict = {'PRAD' : 'blue', 'LUAD' : 'red', 'BRCA' : 'green', 'KIRC' : 'orange', 'COAD' : 'purple'}
for i in range(y_cancer.shape[0]):
color_map.append(color_dict[y_cancer['Class'][i]])
# Plot graph
nx.draw(G, node_color=color_map, with_labels=True, pos = pos, font_weight='bold')
nx.draw(G, node_color=color_map, width=norm_weights, pos = pos, font_weight='bold')
plt.title("Learned graph for the cancer dataset k=%s n_iter=%s alpha=%.3f beta=%.3f" % (k , n_iter, alpha, beta))
filename = os.path.join(plots_dir, 'cancer', 'graph')
fig.savefig(filename)
Expand Down

0 comments on commit b834652

Please sign in to comment.