def get_train_instances(train, num_negatives): user_input, item_input, labels = [], [], [] num_users = train.shape[0] print(train.keys()[:10]) print(train.values()[:10]) for (u, i) in train.keys(): # positive instance user_input.append(u) item_input.append(i) rating = train[u, i] labels.append(rating) # negative instances for t in xrange(num_negatives): j = np.random.randint(num_items) while train.has_key((u, j)): j = np.random.randint(num_items) user_input.append(u) item_input.append(j) labels.append(0) ratings = utils.load_ratings() user_inputs = [x[0] for x in ratings] item_inputs = [x[1] for x in ratings] labels = [x[2] for x in ratings] # labels = keras.utils.np_utils.to_categorical(labels, nb_classes=6) return user_input, item_input, labels
def setUp(self): #Load data ratings = load_ratings('../data/ml-latest-small/ratings.csv') self.movies = load_movies('../data/ml-latest-small/movies.csv') #Train & Test data train, test = ratings.split_train_test(percent=80) self.train = train self.test = test self.svd = create_svd_model(self.train)
import numpy as np from item2vec import Item2Vector from metrics import n_precision from metrics import n_recall from utils import load_ratings from utils import get_user_movie_dictionary from utils import split_matrix from utils import transform_binary_matrix if __name__ == '__main__': # Load and Preprocess Dataset rating_df = load_ratings('ratings.csv') user2idx, movie2idx = get_user_movie_dictionary(rating_df) print(f'# of user: {len(user2idx)}\t# of movie: {len(movie2idx)}') rating_matrix, stat =\ transform_binary_matrix(rating_df, user2idx, movie2idx) print(f'Positive Feedback: {stat["pos"]}', f'\tNegative Feedback: {stat["neg"]}') rating_matrix_train, rating_matrix_val =\ split_matrix(rating_matrix, user2idx, movie2idx) print(f'Train: {rating_matrix_train.count_nonzero()}\t', f'Validation Size: {rating_matrix_val.count_nonzero()}') # Train Item2Vec Model model = Item2Vector(item_dim=len(movie2idx), embedding_dim=100) model.train(rating_matrix_train)
6. Save & quit """ choice = input("Enter your choice: ") return choice if __name__ == "__main__": #Load data try: ratings = Data() ratings.load('../data/myratings.data') except: ratings = load_ratings('../data/ml-latest-small/ratings.csv') movies = load_movies('../data/ml-latest-small/movies.csv') tags = load_tags('../data/ml-latest-small/tags.csv') os.system('clear') print """ ##################################################### #### COMMAND LINE RECOMMENDER #### ##################################################### A minimalistic command line recommender system using SVD decomposistion. """ # Create a user user_id = str(raw_input("Please enter your username: "))
def main(_): print(FLAGS.__flags) FLAGS.data = load_ratings('%s/ratings.dat' % FLAGS.input_dir, random_state=FLAGS.random_state) model = AutoRec(**FLAGS.__flags) model.train(n_epochs=FLAGS.n_epochs)
if __name__ == "__main__": # Load data from custom path try: data_path = sys.argv[1] except IndexError: data_path = '/data' #Load data ratings = Data() if os.path.isfile(data_path + '/myratings.data'): ratings.load(data_path + '/myratings.data') else: try: ratings = load_ratings(data_path + '/ratings.csv') except IOError: raise Exception('Data not found. Please specify it.' % data_path) movies = load_movies(data_path + '/movies.csv') tags = load_tags(data_path + '/tags.csv') os.system('clear') print """ ##################################################### #### COMMAND LINE RECOMMENDER #### ##################################################### A minimalistic command line recommender system using SVD decomposistion. """