示例#1
0
def predict(movie_id):
    target_movie = Movies.get(movie_id)
    #target_movie = get_movie(movie_id)
    target_ratings = make_target_ratings(movie_id)
    # target_movie_rating = rating
    my_movie_ids = movie_ids(0)

    movies_to_compare = []
    for id in my_movie_ids:
        ratings = make_target_ratings(id)
        movies_to_compare.append(ratings)

    similarities = []

    for ratings in movies_to_compare:
        our_rating = ratings[0] # ratings is not a list, it is a dictionary
        similarity = pearson(target_ratings, ratings)
        tup = (similarity, our_rating)
        similarities.append(tup)

    # (similarity, ranking)

    top_five = sorted(similarities)
    top_five.reverse()
    top_five = top_five[: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)
        den += sim

    rating = num/den
    print "Best guess for movie %d: %s is %.2f stars"%\
            (movie_id, target_movie['title'], rating)
示例#2
0
def movie_details():
	movie_id = int(request.form["movie_id"])
	average_rating = movies.average_rating(movie_id)
	md = Movies.get(movie_id)
	return render_template("details.html", md=md, avg = average_rating)