【发布时间】:2020-04-12 17:45:47
【问题描述】:
目前,我已经创建了一个将疾病映射到症状的二分网络图。因此,一种疾病可能与一种或多种症状有关。 另外,我有一些基本统计数据,例如,至少有一种疾病的症状等。
import networkx as nx
csv_dictionary = {"Da": ["A", "C"], "Db": ["B"], "Dc": ["A", "C", "F"], "Dd": ["D"], "De": ["E", "B"], "Df":["F"], "Dg":["F"], "Dh":["F"]}
G = nx.Graph()
all_symptoms = set()
for disorder, symptoms in csv_dictionary.items():
for i in range (0, len(symptoms)):
G.add_edge(disorder, symptoms[i])
all_symptoms.add(symptoms[i])
symptoms_with_multiple_diseases = [symptom for symptom in all_symptoms if G.degree(symptom) > 1]
sorted_symptoms = list(sorted(symptoms_with_multiple_diseases, key= lambda symptom:
G.degree(symptom)))
我需要找到至少有两种症状的疾病。因此,具有两个共同症状的疾病。 我做了一些研究,我认为我应该根据它们的连接方式为我的边缘添加权重,但我无法绕开它。
因此,在上面的示例中,Da 和 Dc 共享两个症状(A 和 C)。
【问题讨论】:
标签: data-science networkx graph-theory bipartite