Example #1
0
def prediction(movie_id):
	similarities =[]
	keys_list = mc.get("keys")
	for key in keys_list:
		sim = pearson_similarity(RATINGS, key, movie_id)
		similarities.append((sim, key))
	similarities.sort()
	best_guess_tup = similarities[-1]
	bg_sim = best_guess_tup[0]
	bg_movie = best_guess_tup[1]
	rating = mc.get(bg_movie)
	
	return "Our best guess for movie %s: is %s stars" % (movie_id, rating)
Example #2
0
def predict(movie_id):
    movie_name1 = movie_dict[str(movie_id)]["title"]
    pearson = []
    for k, v in USER_RATING.iteritems():
        movie_name2 = movie_dict[k]["title"]
        pearson.append((correlation.pearson_similarity(user_ratings, movie_name1, movie_name2), v))
        # get the max pearson score and assign the associated rating to prediction
    sorted_list = sorted(pearson)
    sorted_list.reverse()
    print sorted_list
    score = sorted_list[0][0]
    most_similar_rating = sorted_list[0][1]
    if score <= 0:
        print "Cannot predict score. Please rate more movies"
        return
    prediction = "%.1f" % round(score * most_similar_rating)
    print "Best Pearson guess for movie %s: %s is %s stars" % (movie_id, movie_name1, prediction)
Example #3
0
def predict(target_movie_id, rating_dictionary, movie_dictionary):
    movie = movie_dictionary.get(target_movie_id)
    title = movie["title"]

    best_key = None
    best_correlation = -9

    # for movie_id, rating in g_crud.items():
    for movie_id in g_crud.get("my_keys"):
        rating = g_crud.get(movie_id)
        similarity = correlation.pearson_similarity(rating_dictionary, target_movie_id, movie_id)
        if similarity > best_correlation:
            best_key = movie_id
            best_correlation = similarity
            predicted_rating = similarity * rating

    print "Best guess for movie %s: %s is %.1f stars" % (movie_id, title, predicted_rating)
Example #4
0
def predict(movie_id):
	"""Returns a prediction of movie rating based on other movies 
	user has rated using given movie id. If YOU_DIC is not populated 
	with movie ratings, an error is returned. """
	movie_ratings = make_movie_ratings()
	movie_title = MOVIE_DIC[movie_id]['title']
	a = 0
	d = []
	for each in YOU_DIC:
		similarity = pearson_similarity(movie_ratings, movie_title, MOVIE_DIC[each]['title'])
		d.append([similarity, each]) # each is {movie_id : rating}
	d.sort(reverse=True)
	best = d[0]
	if d[0][0] < 0.25:
		return "Please rate more movies so we know what you like, then try again"
	best_id = best[1]
	best_rating = YOU_DIC[best_id]
	return "Best guess for movie %s: %s is %s stars" %(movie_id, movie_title, best_rating)
Example #5
0
def predict(movie_id):
    ratings = RATINGS_DB[movie_id] #assigns variable 'ratings' to value of RATINGS_DB[movie_id]
    movie = MOVIE_DB[movie_id] #assigns variable 'movie' to MOVIE_DB[movie_id]
    movies = [ m for k, m in USER_RATINGS.iteritems() ] # THIS LINE IS DUM - christian zeb f
    similarities = [ (correlation.pearson_similarity(RATINGS_DB, movie_id, k), m) for k, m in USER_RATINGS.iteritems() ]
    # comparing your rating to all other ratings for these movies, and compares similarity 
    # tuple for movie id and similarity score
    top_five = sorted(similarities) # all similar movies, sorted
    top_five.reverse() # highest to lowest
    top_five = top_five[:5] # actual top 5
    num = 0.0
    den = 0.0
    # Use a weighted mean rather than a strict top similarity
    for sim, m in top_five:
        num += (float(sim) * m) # sim
        den += sim

    rating = num/den # calculated based on top5 -- the closer to 5, the more likely the movie ratings are similar to your own

    print "Best guess for movie %d: %s is %.2f stars"%\
            (movie_id, movie['title'], rating)