Question

In: Computer Science

Write a simple matching coefficient and jaccard similarity code in python. For a example x =...

Write a simple matching coefficient and jaccard similarity code in python.

For a example x = 10101 and y = 00101 what is the code to check those similarities in python?

Solutions

Expert Solution

Simple matching coefficient is useful when both positive and negative values carried equal information. In case of binary number, it is 0 or 1

The Jaccard similarity measures the similarity between finite sample sets and is defined as the cardinality of the intersection of sets divided by the cardinality of the union of the sample sets.

The python program

from math import*

#x = 10101 and y = 00101
x = [1,0,1,0,1]
y = [0,0,1,0,1]

def simple_matching_coeff(a, b):
d1=d2=d12=0
for i in range(0,len(x)):
d1 += x[i]
d2 += y[i]
d12 += x[i]*y[i]
return d12/(d1*d2)
  
c = simple_matching_coeff(x,y)
print("Simple matching coefficient:", c)


def jaccard_matching_coeff(x,y):
intersection_card = len(set.intersection(*[set(x), set(y)]))
union_card = len(set.union(*[set(x), set(y)]))
return intersection_card/float(union_card)

print ("Jaccard Simalirity coefficent", jaccard_matching_coeff(x,y))

The program output as below:


Related Solutions

I'm working on python code which is substring matching. For example, the given string is input...
I'm working on python code which is substring matching. For example, the given string is input "CTTGTGATCTCGTGTCGTGGGTAG", and a substring we want to find in the main one is "GTGG". So the code will print out the position and the substrings in the main which has exactly one different position. For example, start at position 4 the substring is GTGA since there is only one letter different, and so on. Even though we know that string index starts at 0,...
please answer this in a simple python code 1. Write a Python program to construct the...
please answer this in a simple python code 1. Write a Python program to construct the following pattern (with alphabets in the reverse order). It will print the following if input is 5 that is, print z one time, y two times … v five times. The maximum value of n is 26. z yy xxx wwww vvvvvv
Write the following Python code: A string X is an anagram of string Y if X...
Write the following Python code: A string X is an anagram of string Y if X can be obtained by arranging all characters of Y in some order, without removing any characters and without adding new characters. For example, each of the strings "baba", "abab", "aabb" and "abba" is an anagram of "aabb", and strings "aaab", "aab" and "aabc" are not anagrams of "aabb". A set of strings is anagram-free if it contains no pair of strings which are anagrams...
CODE IN PYTHON: Your task is to write a simple program that would allow a user...
CODE IN PYTHON: Your task is to write a simple program that would allow a user to compute the cost of a road trip with a car. User will enter the total distance to be traveled in miles along with the miles per gallon (MPG) information of the car he drives and the per gallon cost of gas. Using these 3 pieces of information you can compute the gas cost of the trip. User will also enter the number of...
please write simple python code Write a program to replicate the behavior of UNIX utility “tail”....
please write simple python code Write a program to replicate the behavior of UNIX utility “tail”. It takes one or more files and displays requested number of lines from the ending. If number is not specified, then it print 10 lines by default.
In python make a simple code. You are writing a code for a program that converts...
In python make a simple code. You are writing a code for a program that converts Celsius and Fahrenheit degrees together. The program should first ask the user in which unit they are entering the temperature degree (c or C for Celcius, and f or F for Fahrenheit). Then it should ask for the temperature and call the proper function to do the conversion and display the result in another unit. It should display the result with a proper message....
In Python: 0) Explain (with a non-trivial example that uses start, stop, and increment) the similarity...
In Python: 0) Explain (with a non-trivial example that uses start, stop, and increment) the similarity between the range() function and slicing. 1) Convert: for i in range(2, 12, 3): print(i) into a while loop. 2) Explain the circumstances where a for loop makes more sense versus when a while loop makes more sense. 4) How do you create an empty tuple? 5) What is the difference between the string methods find and index?
1. Define the classification problem 2. What is the main difference between Simple Matching Coefficient (SMC)...
1. Define the classification problem 2. What is the main difference between Simple Matching Coefficient (SMC) Similarity and Jaccard Similarity? 3. Explain in your own words how the Decision Tree Classifier works. 4. Explain in your own words how the SVM Classifier works.
python code Write a simple calculator: This program must have 9 functions: •main() Controls the flow...
python code Write a simple calculator: This program must have 9 functions: •main() Controls the flow of the program (calls the other modules) •userInput() Asks the user to enter two numbers •add() Accepts two numbers, returns the sum •subtract() Accepts two numbers, returns the difference of the first number minus the second number •multiply() Accepts two numbers, returns the product •divide() Accepts two numbers, returns the quotient of the first number divided by the second number •modulo() Accepts two numbers,...
Write a python program for the following question. Complete the symptom similarity function, which measures the...
Write a python program for the following question. Complete the symptom similarity function, which measures the similarity between the symptoms of two patients. See below for an explanation of how the similarity is computed. def symptom_similarity(symptoms_A: Tuple[Set], symptoms_B: Tuple[Set]) -> int: '''Returns the similarity between symptoms_A and symptoms_B. symptoms_A and symptoms_B are tuples of a set of symptoms present and a set of symptoms absent. The similarity measure is computed by the following equations: present_present + absent_absent - present_absent -...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT