Description
Computes the Jaccard similarity coefficient between two sets (lists). The Jaccard index measures the similarity between two sets by dividing the size of their intersection by the size of their union. It returns a value between 0 (no similarity) and 1 (identical sets).Syntax
Parameters
Returns
Type: number (float) A value between 0 and 1 representing the Jaccard similarity coefficient:1.0indicates identical sets0.0indicates no common elements- Returns
nullfor invalid inputs
Examples
Example 1: Basic Set Similarity
Example 2: Finding Similar Documents by Tags
Example 3: User Interest Matching
Notes
- Treats input lists as sets (duplicates within each list don’t affect the result)
- Returns
nullif either input is not an array - Order of elements doesn’t matter
- Works with any comparable data types (strings, numbers, etc.)
- Ideal for comparing categorical attributes, tags, or interest lists
See Also
- text.levenshtein - Edit distance for string comparison
- coll.intersection - Get common elements between sets
- coll.union - Combine sets
Frequently Asked Questions
What does a Jaccard score of 0.5 mean?
What does a Jaccard score of 0.5 mean?
It means half of the combined unique elements are shared between the two sets. The formula is
|intersection| / |union|.Does the order of elements matter?
Does the order of elements matter?
No. Jaccard treats inputs as sets, so element order and duplicates within a single list do not affect the result.
What types of elements can I compare?
What types of elements can I compare?
Any comparable data types including strings, numbers, and booleans. Both lists should contain the same type of elements for meaningful comparison.