svd movielens data train and test

Solutions on MaxInterview for svd movielens data train and test by the best coders in the world

showing results for - "svd movielens data train and test"
Margo
16 May 2016
1from surprise import Dataset, Reader, SVD, accuracy
2from surprise.model_selection import train_test_split
3 
4# instantiate a reader and read in our rating data
5reader = Reader(rating_scale=(1, 5))
6data = Dataset.load_from_df(ratings_f[['userId','movieId','rating']], reader)
7 
8# train SVD on 75% of known rates
9trainset, testset = train_test_split(data, test_size=.25)
10algorithm = SVD()
11algorithm.fit(trainset)
12predictions = algorithm.test(testset)
13 
14# check the accuracy using Root Mean Square Error
15accuracy.rmse(predictions)
16RMSE: 0.7724
17 
18# check the preferences of a particular user
19user_id = 7010
20predicted_ratings = pred_user_rating(user_id)
21pdf = pd.DataFrame(predicted_ratings, columns = ['movies','ratings'])
22pdf.sort_values('ratings', ascending=False, inplace=True)  
23pdf.set_index('movies', inplace=True)
24pdf.head(10)