减少二分投影的数据集大小

时间:2020-10-13 14:30:25

标签: python networkx graph-theory bipartite sna

我有一个从熊猫数据框创建的图形。图表的长度约为450k边。当我尝试运行projected_graph函数时,它运行了很长时间(我还没有看到它完成),大概是因为该数据集的大小。在创建二部图之前减小该数据集大小的一种好方法是什么?

reviews = pd.read_csv(r"\BX-Book-Ratings.csv", sep=";", encoding = "ISO-8859-1")
users = reviews['User-ID'].values.tolist()
books = reviews['ISBN'].values.tolist()

g=net.from_pandas_edgelist(reviews,'User-ID','ISBN',['Book-Rating'])

print(len(g))
>>> 445839

p = bi.projected_graph(g, users)

我尝试使用连接最多的组件来缩小范围:

trim1 = len([c for c in net.connected_component_subgraphs(g) if len(c) > 10])
gg = sorted(net.connected_component_subgraphs(g), key=len, reverse=True)[trim1]
p = bi.projected_graph(gg, users)

但是我不认为这会给我想要的结果,而且,我不确定这是一种分析上合理的策略。还有其他人建议减少此集的大小吗?

reviews.head()

    User-ID ISBN        Book-Rating
------------------------------
0   276725  034545104X  0
1   276726  0155061224  5
2   276727  0446520802  0
3   276729  052165615X  3
4   276729  0521795028  6

0 个答案:

没有答案