ct4_count_distance#
- skfp.distances.ct4_count_distance(vec_a: ndarray | csr_array, vec_b: ndarray | csr_array) float #
Consonni–Todeschini distance for vectors of count values.
Computes the Consonni–Todeschini 4 distance [1] [2] [3] for count data between two input arrays or sparse matrices by subtracting the similarity from 1, using the formula:
\[dist(a, b) = 1 - sim(a, b)\]See also
ct4_count_similarity()
. The calculated distance falls within the range \([0, 1]\). Vectors with 0 or 1 elements in their intersection or union (which would cause numerical problems with logarithm) have distance 1.- Parameters:
vec_a ({ndarray, sparse matrix}) – First count input array or sparse matrix.
vec_b ({ndarray, sparse matrix}) – Second count input array or sparse matrix.
References
- Returns:
distance – CT4 distance between
vec_a
andvec_b
.- Return type:
float
Examples
>>> from skfp.distances import ct4_count_distance >>> import numpy as np >>> vec_a = np.array([7, 1, 1]) >>> vec_b = np.array([7, 1, 2]) >>> dist = ct4_count_distance(vec_a, vec_b) >>> dist 0.004685938272491197
>>> from scipy.sparse import csr_array >>> vec_a = csr_array([[7, 1, 1]]) >>> vec_b = csr_array([[7, 1, 2]]) >>> dist = ct4_count_distance(vec_a, vec_b) >>> dist 0.004685938272491197