首页 > 解决方案 > NLPlot 同现网络可视化返回

问题描述

我正在使用以下 NLPlot 来可视化单词共现网络。我尝试以下代码:

import nlplot

npt = nlplot.NLPlot(df, target_col='text')
stopwords = npt.get_stopword(top_n=30, min_freq=0) 
npt.build_graph(stopwords=stopwords, min_edge_frequency=10)
npt.co_network(title='Co-occurrence network')

但它返回一个 IndexError 和 NetworkXError。我将我的装饰器降级到 4.3.0 但仍然无法正常工作。知道是什么导致了问题以及如何解决吗?

我也愿意接受其他执行相同可视化的 Python 包的建议。

谢谢

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
~\Anaconda3\lib\site-packages\networkx\utils\decorators.py in _random_state(func, *args, **kwargs)
    456         try:
--> 457             random_state_arg = args[random_state_index]
    458         except TypeError as e:

IndexError: tuple index out of range

The above exception was the direct cause of the following exception:

NetworkXError                             Traceback (most recent call last)
<ipython-input-99-4563e2cacbef> in <module>
----> 1 npt.build_graph(stopwords=stopwords, min_edge_frequency=10)
      2 
      3 # npt.co_network(title='Co-occurrence network')

~\Anaconda3\lib\site-packages\nlplot\nlplot.py in build_graph(self, stopwords, min_edge_frequency)
    491         self.G = self.get_graph()
    492         self.adjacencies = dict(self.G.adjacency())
--> 493         self.betweeness = nx.betweenness_centrality(self.G)
    494         self.clustering_coeff = nx.clustering(self.G)
    495         self.node_df.loc[:, 'adjacency_frequency'] = self.node_df['id_code'].map(lambda x: len(self.adjacencies[x]))

~\Anaconda3\lib\site-packages\decorator.py in fun(*args, **kw)
    229         func, "return _call_(_func_, %s%%(shortsignature)s)" % es,
    230         evaldict, __wrapped__=func)
--> 231     if hasattr(func, '__qualname__'):
    232         fun.__qualname__ = func.__qualname__
    233     return fun

~\Anaconda3\lib\site-packages\networkx\utils\decorators.py in _random_state(func, *args, **kwargs)
    459             raise nx.NetworkXError("random_state_index must be an integer") from e
    460         except IndexError as e:
--> 461             raise nx.NetworkXError("random_state_index is incorrect") from e
    462 
    463         # Create a numpy.random.RandomState instance

NetworkXError: random_state_index is incorrect

标签: pythonnlp

解决方案


推荐阅读