Question: Expected Behavior Write a Python function seq_sim(seq1, seq2, k) that takes as arguments two strings seq1 and seq2 and an integer k , and returns

Expected Behavior

Write a Python function seq_sim(seq1, seq2, k) that takes as arguments two strings seq1 and seq2 and an integer k, and returns a floating point value between 0 and 1 (inclusive) giving the similarity between seq1 and seq2. The similarity value should be computed as the Jaccard index applied to the sets of k-grams of seq1 and seq2 (where k is the third argument to the function).

Jaccard index = Expected Behavior Write a Python function seq_sim(seq1, seq2, k) that takes as

HINT :

to create an empty set: set()

the set corresponding to a list L is given by: set(L)

the union of sets S1 and S2 is given by: S1.union(S2)

the intersection of sets S1 and S2 is given by: S1.intersection(S2)

You can assume that both seq1 and seq2 have length at least k.

Expected output:

Call: seq_sim('aaaaaaaaaa', 'aaaa', 3) Return value: 1.0

Call: seq_sim('aabaacaad', 'abaaba', 3) Return value: 0.42857142857142855

Call: seq_sim('aabaacaad', 'abaaba', 4) Return value: 0.2857142857142857

AnB AUB A. B)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!