tanimoto_count_distance#
- skfp.distances.tanimoto_count_distance(vec_a: ndarray | csr_array, vec_b: ndarray | csr_array) float #
Tanimoto distance for vectors of count values.
Computes the Tanimoto distance [1] for binary data between two input arrays or sparse matrices by subtracting similarity value from 1, using the formula:
\[dist(a, b) = 1 - sim(a, b)\]See also
tanimoto_count_similarity()
. Calculated distance falls within the range from \([0, 1]\). Passing all-zero vectors to this function results in distance of 0.- 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 – Tanimoto distance between
vec_a
andvec_b
.- Return type:
float
Examples
>>> from skfp.distances import tanimoto_count_distance >>> import numpy as np >>> vec_a = np.array([7, 1, 1]) >>> vec_b = np.array([7, 1, 2]) >>> dist = tanimoto_count_distance(vec_a, vec_b) >>> dist 0.018867924528301883
>>> from scipy.sparse import csr_array >>> vec_a = csr_array([[7, 1, 1]]) >>> vec_b = csr_array([[7, 1, 2]]) >>> dist = tanimoto_count_distance(vec_a, vec_b) >>> dist 0.018867924528301883