def _extract_pairwise(self, X, y, n, is_train=True):
if self.cache is not None and (n, True, is_train) in self.cache:
return self.cache[n, True, is_train]
if not hasattr(X, "shape"):
raise ValueError("Precomputed kernels or affinity matrices have "
"to be passed as arrays or sparse matrices.")
if X.shape[0] != X.shape[1]:
raise ValueError("X should be a square kernel matrix")
train, test = self.splits[n]
result = X[np.ix_(train if is_train else test, train)]
if self.cache is not None:
self.cache[n, True, is_train] = result
return result
评论列表
文章目录