<jupyter_start><jupyter_text>Simple popularity-based recommender based on Number of Views<jupyter_code>movie_df1=pd.DataFrame(df.groupby(['movie_id','movie title'])['user_id'].count())
movie_df1.head()
movie_df1['Number_Of_Views']=movie_df1['user_id']
movie_df1=movie_df1.drop('user_id',axis=1)
movie_df1.head()<jupyter_output><empty_output><jupyter_text>Showing Popular Movies on the basis of Number of Views<jupyter_code>popular_movie1=movie_df1.sort_values(by='Number_Of_Views',ascending=False)
popular_movie1['Rank']=range(1,len(popular_movie1)+1)
popular_movie1.head(10)
pd.merge(movie_df,popular_movie1,on="movie_id").sort_values(by='Number_Of_Views',ascending=False).head(15)<jupyter_output><empty_output><jupyter_text>Simple popularity-based recommender based on Ratings<jupyter_code>movie_df2=pd.DataFrame(df.groupby(['movie_id','movie title'])['rating'].mean())
movie_df2.head()
movie_df2['Number_Of_Rating']=df.groupby(['movie_id','movie title'])['rating'].count()
movie_df2.head()
popular_movies2=movie_df2.sort_values(by='rating',ascending=False)
popular_movies2.head(10)<jupyter_output><empty_output><jupyter_text>Showing Popular Movies on the basis of Ratings There is possibility that there is only one rating for a movie and its value is 5 in that case suggesting that movie is not correct so we have to decide a threshold value for number of rating<jupyter_code># suppose threshold = 100

popular_movies2_final=popular_movies2[popular_movies2['Number_Of_Rating']>=100]
popular_movies2_final['Rank']=range(1,len(popular_movies2_final)+1)
popular_movies2_final.head(10)
pd.merge(movie_df,popular_movies2_final,on="movie_id").sort_values(by='rating',ascending=False).head(10)<jupyter_output><empty_output><jupyter_text>Build a Movie recommender with personalization  Item Based<jupyter_code>movie_matrix2 = df.pivot_table(index='user_id', columns='movie_id', values='rating')
movie_matrix2.head(10)
# we are finding movies similar to a particular movie

movie=20

movie_ratings=movie_matrix2[movie]
movie_ratings.head(10)
similar_to_the_movie=movie_matrix2.corrwith(movie_ratings)
print(similar_to_the_movie.shape)
similar_to_the_movie.head(10)
movie_record=pd.DataFrame(similar_to_the_movie,columns=['Correlation'])
movie_record.head(15)
movie_record=movie_record.join(popular_movies2['Number_Of_Rating'])
movie_record.head(15)
movie_record.dropna(inplace=True)
movie_record.head(10)
suggested_movies=movie_record.sort_values(by='Correlation',ascending=False)
suggested_movies.head(15)
# suppose threshold=100

suggested_movies_final=suggested_movies[suggested_movies['Number_Of_Rating']>100]
suggested_movies_final['Rank']=range(1,len(suggested_movies_final)+1)
suggested_movies_final.head(20)
pd.merge(movie_df,suggested_movies_final,on="movie_id").sort_values(by='Correlation',ascending=False).head(10)<jupyter_output><empty_output><jupyter_text>User Based<jupyter_code>movie_matrix3 = df.pivot_table(index='movie_id', columns='user_id', values='rating')
movie_matrix3.head(10)
# we are finding user similar to a particular user

user=20

user_ratings=movie_matrix3[user]
user_ratings.head(10)
similar_to_the_user=movie_matrix3.corrwith(user_ratings)
print(similar_to_the_user.shape)
similar_to_the_user.head(10)
user_record=pd.DataFrame(similar_to_the_user,columns=['Correlation'])
user_record.head(10)
user_record.dropna(inplace=True)
suggested_users=user_record.sort_values(by='Correlation',ascending=False)
suggested_users.head(20)
suggested_users=pd.merge(user_df,suggested_users,on="user_id").sort_values(by='Correlation',ascending=False)
suggested_users.head(20)
# List of users which are similar to the that particular user

suggested_users['Rank']=range(1,len(suggested_users)+1)
suggested_users.head(20)<jupyter_output><empty_output><jupyter_text>Now suppose if we want to recommend movies for that particular user then go to the movie list to the user with rank 1 and recommend the movies which are not seen by the particular user and then go for rank 2 and so on.......<jupyter_code># particular user

user
# the userid of the user which is similar to the particular user

suggested_users.iloc[0][0]<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup