-
Notifications
You must be signed in to change notification settings - Fork 103
Open
Labels
Description
Describe the bug
When try to use NeighborhoodSubgraphPairwiseDistance as a base kernel to the WeisfeilerLehman, get the error that AttributeError: 'int' object has no attribute 'flags'.
To Reproduce
gk = WeisfeilerLehman(n_iter=2, normalize=True,
base_graph_kernel=(NeighborhoodSubgraphPairwiseDistance, {"verbose":True}), )
gk.fit(all_graphs) # all_graphs is a list of any `Graph` objects
gk.transform(all_graphs)Expected behavior
A similarity matrix.
Stack Trace
---------------------------------------------------------------------------
NotFittedError Traceback (most recent call last)
File /usr/local/lib/python3.10/dist-packages/grakel/kernels/weisfeiler_lehman.py:483, in WeisfeilerLehman.diagonal(self)
482 try:
--> 483 check_is_fitted(self, ['_X_diag'])
484 if self._is_transformed:
File /usr/local/lib/python3.10/dist-packages/sklearn/utils/validation.py:1661, in check_is_fitted(estimator, attributes, msg, all_or_any)
1660 if not _is_fitted(estimator, attributes, all_or_any):
-> 1661 raise NotFittedError(msg % {"name": type(estimator).__name__})
NotFittedError: This WeisfeilerLehman instance is not fitted yet. Call 'fit' with appropriate arguments before using this estimator.
During handling of the above exception, another exception occurred:
AttributeError Traceback (most recent call last)
Cell In[19], line 1
----> 1 gk.transform(all_graphs)
File /usr/local/lib/python3.10/dist-packages/sklearn/utils/_set_output.py:313, in _wrap_method_output.<locals>.wrapped(self, X, *args, **kwargs)
311 @wraps(f)
312 def wrapped(self, X, *args, **kwargs):
--> 313 data_to_wrap = f(self, X, *args, **kwargs)
314 if isinstance(data_to_wrap, tuple):
315 # only wrap the first output for cross decomposition
316 return_tuple = (
317 _wrap_data_with_container(method, data_to_wrap[0], X, self),
318 *data_to_wrap[1:],
319 )
File /usr/local/lib/python3.10/dist-packages/grakel/kernels/weisfeiler_lehman.py:452, in WeisfeilerLehman.transform(self, X)
450 self._is_transformed = True
451 if self.normalize:
--> 452 X_diag, Y_diag = self.diagonal()
453 old_settings = np.seterr(divide='ignore')
454 K = np.nan_to_num(np.divide(K, np.sqrt(np.outer(Y_diag, X_diag))))
File /usr/local/lib/python3.10/dist-packages/grakel/kernels/weisfeiler_lehman.py:493, in WeisfeilerLehman.diagonal(self)
491 X_diag, Y_diag = self.X[0].diagonal()
492 # X_diag is considered a mutable and should not affect the kernel matrix itself.
--> 493 X_diag.flags.writeable = True
494 for i in range(1, self._n_iter):
495 x, y = self.X[i].diagonal()
AttributeError: 'int' object has no attribute 'flags'Possible solution
If I haven't mistaken, and it's allowed to use this kernel with WeisfeilerLehman, so maybe the error goes from the fact that diagonal method of NeighborhoodSubgraphPairwiseDistance returns int and not numpy.array. I've done this, all works fine, but I'm not sure whether it is actually feasible.
Reactions are currently unavailable