categorical-distance

raw JSON →
1.9 verified Fri May 01 auth: no python

Python library for measuring distances between categorical variables. Supports a variety of distance metrics including Hamming, Jaccard, and Dice coefficients. Version 1.9, stable.

pip install categorical-distance
error ValueError: arrays must have same length
cause Input sequences have different lengths.
fix
Ensure both input lists have the same length.
error AttributeError: module 'categorical_distance' has no attribute 'categorical_distance'
cause Importing the module directly instead of the function.
fix
Use 'from categorical_distance import categorical_distance' to import the function.
error ImportError: No module named 'categorical_distance'
cause Library not installed.
fix
Run 'pip install categorical-distance'.
gotcha The function `categorical_distance` expects lists or arrays of equal length; if lengths differ, it raises a ValueError.
fix Ensure input lists have the same length.
gotcha The library does not handle missing values (NaN/None). Input must be clean categorical values.
fix Preprocess data to remove or impute missing values before calling the function.
deprecated The `distances` module is deprecated and has been replaced by `metrics`.
fix Use `from categorical_distance import metrics` instead.

Compute the distance matrix between two lists of categorical values.

from categorical_distance import categorical_distance
distance_matrix = categorical_distance(['a','b','c'], ['a','c','b'])
print(distance_matrix)