예제 #1
0
def test_pairwise_distance_numpy_set():
	""" Test pairwise distance: using the Numpy (dense matrix) implementation for jaccard set coef """
	D = pairwise_proximity(W, metric='jaccard_set')
	true = np.array([
		[ 1.,          0.6,         0.4,         0.2,       ],
		[ 0.6,         1.,          0.75,        0.5,       ],
		[ 0.4,         0.75,        1.,          0.66666667,],
		[ 0.2,         0.5,         0.66666667,  1.,        ],
 		], dtype=float)
	assert np.isclose(D, true).all()
예제 #2
0
def test_pairwise_distance_numpy_weighted():
	""" Test pairwise distance: using Numpy (dense matrix) using weighted jaccard """
	D = pairwise_proximity(W, metric='weighted_jaccard', min_support=10)
	true = np.array([
		[ 1.,   0.6,  0.3,  0.1],
		[ 0.6,  1.,   0.,   0. ],
		[ 0.3,  0.,   1.,   0. ],
		[ 0.1,  0.,   0.,   1. ],
		], dtype=float)
	assert np.isclose(D, true).all()
예제 #3
0
def test_pairwise_distance_numpy_bitwise():
	""" Test pairwise distance: using the Numpy (dense matrix) implementation for jaccard bitwise coef """
	D = pairwise_proximity(B, metric='jaccard_bitwise')
	true = np.array([
		[ 1.,          0.75,        0.5,         0.25      ],
		[ 0.75,        1.,          0.66666667,  0.33333333],
		[ 0.5,         0.66666667,  1.,          0.5       ],
		[ 0.25,        0.33333333,  0.5,         1.        ],
		], dtype=float)
	assert np.isclose(D, true).all()
예제 #4
0
def test_pairwise_distance_sparse_set():
	""" Test pairwise distance: using the Scipy (sparse matrix) implementation for jaccard set coef """
	W_sparse = csr_matrix(W)
	D = pairwise_proximity(W_sparse, metric='jaccard_set')
	true = np.array([
		[ 1.,          0.75,        0.5,         0.25      ],
		[ 0.75,        1.,          0.66666667,  0.33333333],
		[ 0.5,         0.66666667,  1.,          0.5       ],
		[ 0.25,        0.33333333,  0.5,         1.        ],
		], dtype=float)
	assert np.isclose(D.todense(), true).all()
예제 #5
0
def test_pairwise_distance_sparse_weighted():
	""" Test pairwise distance: using the Scipy (sparse matrix) implementation for jaccard weighted coef """
	W_sparse = csr_matrix(W)
	D = pairwise_proximity(W_sparse, metric='jaccard_weighted')
	print D.todense()
	true = np.array([
		[ 1.,   0.6,  0.3,  0.1],
		[ 0.6,  1.,   0.,   0. ],
		[ 0.3,  0.,   1.,   0. ],
		[ 0.1,  0.,   0.,   1. ],
		], dtype=float)
	assert np.isclose(D.todense(), true).all()