Question

In: Computer Science

Python code def overlap(user1, user2, interests): """ Return the number of interests that user1 and user2...

Python code

def overlap(user1, user2, interests):
""" Return the number of interests that user1 and user2
have in common """
return 0

  
def most_similar(user, interests):
""" Determine the name of user who is most similar
to the input user defined by having the most interests
in common. Return a tuple: (most_similar_user, num_interests_in_common) """
return ("", 0)
  

def recommendations(user, interests):
""" Find the user who shares the most interests with the specified user.
Recommend to user any interests that his or her closest match has
that are not already in the user's list of interests.
Return a list of recommendations. """
return []

#%% Don't change this:
  
interests = {
"Pam":["Hadoop", "Big Data", "HBase", "Java", "Spark", "Storm", "Cassandra"],
"Ann":["NoSQL", "MongoDB", "Cassandra", "HBase", "Postgres"],
"Raj":["Python", "scikit-learn", "scipy", "numpy", "statsmodels", "pandas"],
"Jim":["R", "Python", "statistics", "regression", "probability", "programming languages"],
"Eve":["machine learning", "regression", "decision trees", "libsvm"],
"Carl Yastrzemski":["Python", "R", "Java", "C++", "Haskell", "programming languages"],
"Sam":["statistics", "probability", "mathematics", "theory"],
"Una":["machine learning", "scikit-learn", "Mahout", "neural networks"],
"Liv":["neural networks", "deep learning", "Big Data", "artificial intelligence"],
"Bob":["Hadoop", "Java", "MapReduce", "Big Data"],
"Jon":["statistics", "R", "statsmodels"],
"Tom":["pandas", "R", "Python"],
"Tim":["databases", "HBase", "Postgres", "MySQL", "MongoDB"],
"Hal":["libsvm", "regression", "support vector machines"],
"Joe":["C++", "deep learning", "artificial intelligence", "probability"]
}


#%% Don't change this either!

for user in interests.keys():
print(user, recommendations(user, interests))


#%% Put output here

"""
Your output
"""

Solutions

Expert Solution

Code:-

""" Return the number of interests that user1 and user2
have in common """
def overlap(user1, user2, interests):
num_of_interests = 0;
# Iterates through each value of user1
for user1_values in interests[user1]:
# if true, num_of_interests will be incremented by 1
if (user1_values in interests[user2] ):
num_of_interests += 1;
return num_of_interests;
""" Determine the name of user who is most similar
to the input user defined by having the most interests
in common. Return a tuple: (most_similar_user, num_interests_in_common) """
def most_similar(user, interests):
user_count = {};
# Iterates through each user in the interest dictionary
for dict_user in interests.keys():
# Ignores the input user
if (user != dict_user ):
count = overlap(user, dict_user, interests);
# All the count values with user names are stored as key and value in user_count
user_count[dict_user] = count;
count = 0;
# maximum value in the user_count dict is found and returned
most_similar_user = max(user_count, key = user_count.get);
return (most_similar_user, user_count[most_similar_user])
""" Find the user who shares the most interests with the specified user.
Recommend to user any interests that his or her closest match has
that are not already in the user's list of interests.
Return a list of recommendations. """
def recommendations(user, interests):
recommendation = [];
# input_user_interests has the interests of the input user of type set
input_user_interests = set(interests[user]);
# Calls the most_similar function
most_similar_user = most_similar(user, interests);
# most_similar_user_interests has the interests of the most similar user of type set
most_similar_user_interests = set(interests[most_similar_user[0]]);
# UnionSet now has all the interests of both the users
UnionSet = input_user_interests.union(most_similar_user_interests);
# UnionSet now has only the interest of most similar user (common interests not included)
UnionSet = UnionSet - input_user_interests;
return list(UnionSet);
interests = {
"Pam":["Hadoop", "Big Data", "HBase", "Java", "Spark", "Storm", "Cassandra"],
"Ann":["NoSQL", "MongoDB", "Cassandra", "HBase", "Postgres"],
"Raj":["Python", "scikit-learn", "scipy", "numpy", "statsmodels", "pandas"],
"Jim":["R", "Python", "statistics", "regression", "probability", "programming languages"],
"Eve":["machine learning", "regression", "decision trees", "libsvm"],
"Carl Yastrzemski":["Python", "R", "Java", "C++", "Haskell", "programming languages"],
"Sam":["statistics", "probability", "mathematics", "theory"],
"Una":["machine learning", "scikit-learn", "Mahout", "neural networks"],
"Liv":["neural networks", "deep learning", "Big Data", "artificial intelligence"],
"Bob":["Hadoop", "Java", "MapReduce", "Big Data"],
"Jon":["statistics", "R", "statsmodels"],
"Tom":["pandas", "R", "Python"],
"Tim":["databases", "HBase", "Postgres", "MySQL", "MongoDB"],
"Hal":["libsvm", "regression", "support vector machines"],
"Joe":["C++", "deep learning", "artificial intelligence", "probability"]
}
#%% Don't change this either!
for user in interests.keys():
print(user, recommendations(user, interests))
print("Pam and Ann have",overlap("Pam", "Ann", interests), "interests in common");
print(most_similar("Pam", interests)[0], "is the most similar to Pam");

Code Screenshot:-

Output:-

Please UPVOTE thank you...!!!


Related Solutions

Using Python def specialAverage():    Print the number of 0s and then return the average of...
Using Python def specialAverage():    Print the number of 0s and then return the average of either the positive values in the list (if the optional parameter has value 1) or the negative values in the list (if the optional parameter has value 0).    Arguments: a list of numbers : the list can contain any numeric values an integer : this integer is an optional parameter and only takes value 0 or 1, and defaults to 1 if the...
In Python The following code is intentionally done in poor style but runs as intended. def...
In Python The following code is intentionally done in poor style but runs as intended. def main(): c = 10 print("Welcome to Roderick's Chikkin and Gravy") e = False while not e: x = input("Would you like some chikkin?") if x == "Y" or x == "y": c = f(c) else: e = True if c == 0: e = True print("I hope you enjoyed your chikkin!") def f(c): if c > 0: print("Got you some chikkin! Enjoy") return c-1...
Write a Python function with prototype “def anagramdictionary(wordlist):” that will return an “anagram dictionary” of the...
Write a Python function with prototype “def anagramdictionary(wordlist):” that will return an “anagram dictionary” of the given wordlist  An anagram dictionary has each word with the letters sorted alphabetically creating a “key”.
Write a Python 3 code that takes an irrational number 'x' and return 'm' fraction approximations....
Write a Python 3 code that takes an irrational number 'x' and return 'm' fraction approximations. For example let x=pi and m=4, then the program should return 4 examples of pi written as a fraction approximation.  
PYTHON PROBLEM: TASKED TO FIND THE FLAW WITH THE FOLLOWING CODE: from itertools import count def...
PYTHON PROBLEM: TASKED TO FIND THE FLAW WITH THE FOLLOWING CODE: from itertools import count def take_e(n, gen):     return [elem for (i, elem) in enumerate(gen) if i < n] def take_zc(n, gen):     return [elem for (i, elem) in zip(count(), gen) if i < n] FIBONACCI UNBOUNDED: def fibonacci_unbounded():     """     Unbounded Fibonacci numbers generator     """     (a, b) = (0, 1)     while True:         # return a         yield a         (a, b) = (b, a + b) SUPPOSED TO RUN THIS TO ASSIST WITH...
In Python write a function with prototype “def dictsort(d):” which will return a list of key-value...
In Python write a function with prototype “def dictsort(d):” which will return a list of key-value pairs of the dictionary as tuples (key, value), reverse sorted by value (highest first) and where multiple keys with the same value appear alphabetically (lowest first).
Python ONLY ONE STATEMENT ALLOWED PER FUNCTION (ONE RETURN STATEMENT ALLOWED) def plsfollowrule(num): return num like...
Python ONLY ONE STATEMENT ALLOWED PER FUNCTION (ONE RETURN STATEMENT ALLOWED) def plsfollowrule(num): return num like this. 1) create a function popular. The dictionary called database contains each people's hobby and their excitement level. This function searches the dictionary and returns a list of that most popular hobby to least popular hobby. If multiple hobbies have the same number of popularity, follow alphabetical order. #What is popular means? The dictionary contains each people's hobby. The programmer should search the dictionary...
In python Write the code to ask a user to enter a number in the range...
In python Write the code to ask a user to enter a number in the range of 1-100. Have the code checked to make sure that it is in this range. If it is not, let the user re-enter the number. The user should be able to re-enter numbers until the number is within the correct range.
matlab code that performs overlap add method.
matlab code that performs overlap add method.
Python. Write a code that asks the user to enter a string. Count the number of...
Python. Write a code that asks the user to enter a string. Count the number of different vowels ( a, e, i, o, u) that are in the string and print out the total. You may need to write 5 different if statements, one for each vowel. Enter a string: mouse mouse has 3 different vowels
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT