Code Monkey home page Code Monkey logo

movie-recommendations's Issues

IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices

Please see the error:


IndexError Traceback (most recent call last)
in ()
10
11 for movie_id in (10,100,1000):
---> 12 print(movie_id,predict_rating(similarities, user_ratings, movie_id))

in predict_rating(model, ratings, movie_id, n)
9
10 rated_movies = ratings.keys()
---> 11 similar_movies = model[movie_id, rated_movies].argsort()[:-1]
12 top_n = [ratings.keys()[i] for i in similar_movies[:n]]
13

IndexError: only integers, slices (:), ellipsis (...), numpy.newaxis (None) and integer or boolean arrays are valid indices

------------------------------------------------------Cosine Similarity
import numpy as np

def predict_rating(model, ratings, movie_id, n=5):

# model = movie similarities matrix
# movie_id = target movie id
# ratings = dict of movie_id: rating


rated_movies = ratings.keys()
similar_movies = model[movie_id, rated_movies].argsort()[:-1]
top_n = [ratings.keys()[i] for i in similar_movies[:n]]

# Average rating weighted by similarity
scores = sum(model[movie_id, m] * ratings[m] for m in top_n)

prediction = float(scores) / sum(model[movie_id, m] for m in top_n)
return prediction

user_id = 10
movies_rated = np.where(R[user_id].todense() > 0)[1].tolist()
movie_ratings = R[user_id, movies_rated].todense().tolist()[0]

user_ratings = dict(zip(movies_rated, movie_ratings))
print('10 2.77208508312')
print('100 1.77135318293')
print('1000 2.35262213947')

for movie_id in (10,100,1000):
print(movie_id,predict_rating(similarities, user_ratings, movie_id))

A problem about the RBM based recommendation

In your implementation of RBM based CF, I see you directly fed the rating data in, ratings ranges from 1-5. I think this should corresponds to Guassian visible layer because the data is not binary, which is different from the original implementation of Ruslan and Hinton. However, your reconstruction, v_2 seems to be binary...

This confused me because I think in RBM, v_2 should try to reconstruct the input data, so I don't know why real input but binary reconstruction works. Can you give some explanation about this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.