Bird
0
0

Given two sets A = {'apple', 'banana', 'cherry'} and B = {'banana', 'cherry', 'date', 'fig'}, what is the Jaccard similarity computed by this code?

medium📝 Predict Output Q13 of 15
NLP - Text Similarity and Search
Given two sets A = {'apple', 'banana', 'cherry'} and B = {'banana', 'cherry', 'date', 'fig'}, what is the Jaccard similarity computed by this code?
len(A & B) / len(A | B)
A0.4
B0.5
C0.6
D0.75
Step-by-Step Solution
Solution:
  1. Step 1: Calculate intersection and union of sets A and B

    Intersection: {'banana', 'cherry'} has 2 elements.
    Union: {'apple', 'banana', 'cherry', 'date', 'fig'} has 5 elements.
  2. Step 2: Compute Jaccard similarity

    Similarity = 2 / 5 = 0.4.
  3. Final Answer:

    0.4 -> Option A
  4. Quick Check:

    2 / 5 = 0.4 [OK]
Quick Trick: Count common and total unique items, then divide [OK]
Common Mistakes:
MISTAKES
  • Counting union incorrectly
  • Using addition instead of division
  • Mixing up intersection and union counts

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NLP Quizzes