当我有连接的节点时,无法检索未连接的节点对

时间:2021-05-11 11:50:07

标签: python machine-learning hierarchy

我无法从这里进一步进行链接预测模型的数据集准备工作,我也创建了邻接矩阵,但是我不知道如何进一步前进或让我知道我哪里出错了。< /p>

这是下面的代码:-

import networkx as nx
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.preprocessing import LabelEncoder
from tqdm import tqdm

# G = nx.Graph()

# G.add_node(1)
# G.add_nodes_from([2,3])



df = pd.read_csv('/content/Untitled spreadsheet.csv')

#df.head(5)

#G = nx.from_pandas_edgelist(fb_df, "node_1", "node_2", create_using=nx.Graph())

parent_disease_name = df['Parent_Disease_name']
print(parent_disease_name)
child_disease_name = df['Child_Disease_name']
print(child_disease_name)

label_encoder = LabelEncoder()

parent_disease = label_encoder.fit_transform(parent_disease_name)
#print(parent_disease)

child_disease = label_encoder.fit_transform(child_disease_name)
#print(child_disease)

d={"parent": parent_disease_name, "child":child_disease_name, 'labeled_parent':parent_disease, 'labeled_child':child_disease}
#df = pd.DataFrame(d)
#print(df['labeled_parent'])
node_list1 = df['labeled_parent']
node_list2 = df['labeled_child']
node_list = node_list1 + node_list2

df_node_list = pd.DataFrame({'node_1': node_list1, 'node_2': node_list2})
df_node_list.head()
#print(node_list)

G = nx.from_pandas_edgelist(df_node_list, "node_1", "node_2", create_using=nx.Graph())
plt.figure(figsize=(10,10))
pos = nx.random_layout(G, seed=23)
nx.draw(G, with_labels=True,  pos = pos, node_size = 40, alpha = 0.6, width = 0.7)

plt.show()

node_list = list(dict.fromkeys(node_list))
#print(node_list)

adj_G = nx.to_numpy_matrix(G, nodelist = node_list)

adj_G.shape

0 个答案:

没有答案