Ajay-user's picture
movie recommedation
f12e569
import streamlit as st
from utils import Collaborative_filtering, Content_based_filtering
st.title("MovieLens Recommender System")
st.caption(
"MovieLens is a recommender system that was developed by GroupLens, a computer science research lab at the University of Minnesota. It recommends movies to its users based on their movie ratings. It is also a dataset that is widely used in research and teaching contexts. [link](https://grouplens.org/datasets/movielens/)")
rec_1 = Collaborative_filtering()
rec_2 = Content_based_filtering()
movie_title = st.selectbox("Select a movie you like πŸ’–",
options=rec_1.movies.title.to_list())
tab_1, tab_2, tab_3, tab_4 = st.tabs(
["Collaborative Filtering", "Content-based Filtering", "Matrix Factorization", "Content-based Filtering from Feedback"])
with tab_1:
st.caption("""I'm going to use a technique called colaborative filtering to generate recommendations for you. This technique is based on the premise that similar people like similar things. The beauty of collaborative filtering is that it doesn't require any information about the users or the movies to generate recommendations.""")
st.caption(
f"🎬 You selected `{movie_title}` so I would recommed the following")
for movie in rec_1.find_similar_movies(movie_title):
st.code("🍿 "+movie)
with tab_2:
st.caption("""The **cold start problem** is when there are new users and movies in our matrix that do not have any ratings. How do we handle the cold-start problem.
Collaborative filtering relies solely on user-item interactions within the utility matrix. The issue with this approach is that brand new users or items with no iteractions get excluded from the recommendation system. This is called the **cold start problem**. Content-based filtering is a way to handle this problem by generating recommendations based on user and item features.""")
st.caption(
f"🎬 You selected `{movie_title}` so I would recommed the following")
for movie in rec_2.find_similar_movies(movie_title):
st.code("🍿 "+movie)
with tab_3:
st.caption("""Matrix factorization (MF) is a linear algebra technique that can help us discover latent features underlying the interactions between users and movies. These latent features give a more compact representation of user tastes and item descriptions. MF is particularly useful for very sparse data and can enhance the quality of recommendations. The algorithm works by factorizing the original user-item matrix into two factor matrices:
- user-factor matrix (n_users, k)
- item-factor matrix (k, n_items)""")
st.caption(
f"🎬 You selected `{movie_title}` so I would recommed the following")
for movie in rec_1.find_similar_movies(movie_title, use_matrix_factorization=True):
st.code("🍿 "+movie)
with tab_4:
st.caption("The **cold start problem** is when there are new users and movies in our matrix that do not have any ratings. Content-based filtering uses user-item features to recommend other items similar to what the user likes, based on their previous actions or explicit feedback.")
col_1, col_2 = st.columns(spec=[25, 75])
with col_1:
movie_id = rec_2.movie_id_title_invmap[movie_title]
movie_index = rec_2.movie_id_index_map[movie_id]
row = rec_2.user_feature_matrix.iloc[movie_index]
options = []
st.caption("**Feedback**")
for k, v in row.items():
options.append(st.checkbox(label=k, value=bool(v)))
with col_2:
vector = []
for item in options:
vector.append(item)
st.caption("**Movie Recommendation based on feedback**")
for movie in rec_2.find_similar_movies_based_on_feedback(vector):
st.code("🍿 "+movie)