-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcancer.py
32 lines (29 loc) · 1.01 KB
/
cancer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import numpy as np
from sgl import LearnGraphTopolgy
from metrics import ModelSelection, Metrics
import networkx as nx
import matplotlib.pyplot as plt
import csv
with open('data/cancer/data.csv', 'r') as f:
csv_reader = csv.reader(f, delimiter=',')
line_count = 0
data = [[row[i] for i in range(len(row))] for row in csv_reader]
data = np.asarray(data)
data = data[1:, 1:]
data = data.astype('float')
n = data.shape[0]
p = data.shape[1]
print(data.shape)
with open('data/cancer/labels.csv', 'r') as f:
csv_reader = csv.reader(f, delimiter=',')
names = [[str(row[i]) for i in range(len(row))] for row in csv_reader]
names = np.asarray(names)
names = names[1:, 1]
# cov_emp = (data.T @ data)/ n
sgl = LearnGraphTopolgy( data , maxiter=10, record_objective = False, record_weights = False)
graph = sgl.learn_k_component_graph(w0 = 'qp', k=5, beta=1e2)
# build network
A = graph['adjacency']
G = nx.from_numpy_matrix(A)
print('Graph statistics:')
print('Nodes: ', G.number_of_nodes(), 'Edges: ', G.number_of_edges() )