node2vec python_Node2vec和networkx

在尝试使用node2vec对自定义的networkx有向网络进行节点嵌入时,遇到了错误:ValueError: a must be non-empty。错误源于`np.random.choice`在空集合上执行时要求输入非空。问题可能在于节点邻居的选择或预计算概率阶段。解决方案可能包括检查网络结构,确保节点有连接,并正确设置参数。
摘要由CSDN通过智能技术生成

我正在尝试在我创建的定向networkx网络上运行node2vec。网络如下所示:OutEdgeDataView([(7, 1, {'senderId': 7, 'weight': 273}), (7, 8, {'senderId': 7, 'weight': 319}), (7, 9, {'senderId': 7, 'weight': 137})....

每个节点都有一个整数ID和一个连接一个节点到另一个节点的权重。在

我尝试将此网络上的node2vec模块用作:

^{pr2}$

我带着这个错误回来了,如果你能帮我解释一下这个错误,我将不胜感激:---------------------------------------------------------------------------

_RemoteTraceback Traceback (most recent call last)

_RemoteTraceback:

"""

Traceback (most recent call last):

File "C:\Users\Andrew\Anaconda3\lib\site-packages\joblib\externals\loky\process_executor.py", line 398, in _process_worker

r = call_item.fn(*call_item.args, **call_item.kwargs)

File "C:\Users\Andrew\Anaconda3\lib\site-packages\joblib\_parallel_backends.py", line 561, in __call__

return self.func(*args, **kwargs)

File "C:\Users\Andrew\Anaconda3\lib\site-packages\joblib\parallel.py", line 224, in __call__

for func, args, kwargs in self.items]

File "C:\Users\Andrew\Anaconda3\lib\site-packages\joblib\parallel.py", line 224, in

for func, args, kwargs in self.items]

File "C:\Users\Andrew\Anaconda3\lib\site-packages\node2vec\node2vec.py", line 51, in parallel_generate_walks

walk_to = np.random.choice(walk_options, size=1)[0]

File "mtrand.pyx", line 1126, in mtrand.RandomState.choice

ValueError: a must be non-empty

"""

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

ValueError Traceback (most recent call last)

in ()

1

----> 2 node2vec = Node2Vec(mail_n_basic, dimensions=64, walk_length=30, num_walks=200, workers=4)

~\Anaconda3\lib\site-packages\node2vec\node2vec.py in __init__(self, graph, dimensions, walk_length, num_walks, p, q, weight_key, workers, sampling_strategy)

111

112 self.d_graph = self._precompute_probabilities()

--> 113 self.walks = self._generate_walks()

114

115 def _precompute_probabilities(self):

~\Anaconda3\lib\site-packages\node2vec\node2vec.py in _generate_walks(self)

178 self.NEIGHBORS_KEY,

179 self.PROBABILITIES_KEY) for idx, num_walks

--> 180 in enumerate(num_walks_lists, 1))

181

182 walks = flatten(walk_results)

~\Anaconda3\lib\site-packages\joblib\parallel.py in __call__(self, iterable)

960

961 with self._backend.retrieval_context():

--> 962 self.retrieve()

963 # Make sure that we get a last message telling us we are done

964 elapsed_time = time.time() - self._start_time

~\Anaconda3\lib\site-packages\joblib\parallel.py in retrieve(self)

863 try:

864 if getattr(self._backend, 'supports_timeout', False):

--> 865 self._output.extend(job.get(timeout=self.timeout))

866 else:

867 self._output.extend(job.get())

~\Anaconda3\lib\site-packages\joblib\_parallel_backends.py in wrap_future_result(future, timeout)

513 AsyncResults.get from multiprocessing."""

514 try:

--> 515 return future.result(timeout=timeout)

516 except LokyTimeoutError:

517 raise TimeoutError()

~\Anaconda3\lib\site-packages\joblib\externals\loky\_base.py in result(self, timeout)

429 raise CancelledError()

430 elif self._state == FINISHED:

--> 431 return self.__get_result()

432 else:

433 raise TimeoutError()

~\Anaconda3\lib\site-packages\joblib\externals\loky\_base.py in __get_result(self)

380 def __get_result(self):

381 if self._exception:

--> 382 raise self._exception

383 else:

384 return self._result

ValueError: a must be non-empty

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值