|
import streamlit as st |
|
from surprise import SVD |
|
import pandas as pd |
|
import pickle |
|
|
|
|
|
with open('svd_model.pkl', 'rb') as file: |
|
svd_model, merged_data, movies = pickle.load(file) |
|
|
|
|
|
st.title("Movie Recommendations") |
|
|
|
|
|
user_id = st.number_input("Enter User ID", min_value=1, step=1) |
|
|
|
|
|
rated_user_movies = merged_data[merged_data['userId'] == user_id]['title'].values |
|
unrated_movies = movies[~movies['title'].isin(rated_user_movies)]['title'] |
|
|
|
|
|
pred_ratings = [svd_model.predict(user_id, movie_id) for movie_id in unrated_movies] |
|
|
|
|
|
sorted_predictions = sorted(pred_ratings, key=lambda x: x.est, reverse=True) |
|
|
|
|
|
top_recommendations = sorted_predictions[:10] |
|
|
|
|
|
st.write(f"\nTop 10 movie recommendations for User {user_id}:") |
|
for recommendation in top_recommendations: |
|
movie_title = movies[movies['title'] == recommendation.iid]['title'].values[0] |
|
st.write(f"{movie_title} (Estimated Rating: {recommendation.est})") |
|
|