本文整理汇总了Python中sklearn.utils.check_symmetric方法的典型用法代码示例。如果您正苦于以下问题:Python utils.check_symmetric方法的具体用法?Python utils.check_symmetric怎么用?Python utils.check_symmetric使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.utils
的用法示例。
在下文中一共展示了utils.check_symmetric方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_check_symmetric
# 需要导入模块: from sklearn import utils [as 别名]
# 或者: from sklearn.utils import check_symmetric [as 别名]
def test_check_symmetric():
arr_sym = np.array([[0, 1], [1, 2]])
arr_bad = np.ones(2)
arr_asym = np.array([[0, 2], [0, 2]])
test_arrays = {'dense': arr_asym,
'dok': sp.dok_matrix(arr_asym),
'csr': sp.csr_matrix(arr_asym),
'csc': sp.csc_matrix(arr_asym),
'coo': sp.coo_matrix(arr_asym),
'lil': sp.lil_matrix(arr_asym),
'bsr': sp.bsr_matrix(arr_asym)}
# check error for bad inputs
assert_raises(ValueError, check_symmetric, arr_bad)
# check that asymmetric arrays are properly symmetrized
for arr_format, arr in test_arrays.items():
# Check for warnings and errors
assert_warns(UserWarning, check_symmetric, arr)
assert_raises(ValueError, check_symmetric, arr, raise_exception=True)
output = check_symmetric(arr, raise_warning=False)
if sp.issparse(output):
assert_equal(output.format, arr_format)
assert_array_equal(output.toarray(), arr_sym)
else:
assert_array_equal(output, arr_sym)
示例2: _spectral_clustering
# 需要导入模块: from sklearn import utils [as 别名]
# 或者: from sklearn.utils import check_symmetric [as 别名]
def _spectral_clustering(self):
affinity_matrix_ = check_symmetric(self.affinity_matrix_)
random_state = check_random_state(self.random_state)
laplacian = sparse.csgraph.laplacian(affinity_matrix_, normed=True)
_, vec = sparse.linalg.eigsh(sparse.identity(laplacian.shape[0]) - laplacian,
k=self.n_clusters, sigma=None, which='LA')
embedding = normalize(vec)
_, self.labels_, _ = cluster.k_means(embedding, self.n_clusters,
random_state=random_state, n_init=self.n_init)