Upload 3 files
Browse files- app.py +33 -0
- requirements.txt +5 -0
- svd_model.pkl +3 -0
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from surprise import SVD
|
3 |
+
import pandas as pd
|
4 |
+
import pickle
|
5 |
+
|
6 |
+
# Load data back from the file
|
7 |
+
with open('svd_model.pkl', 'rb') as file:
|
8 |
+
svd_model, merged_data, movies = pickle.load(file)
|
9 |
+
|
10 |
+
# Title for the app
|
11 |
+
st.title("Movie Recommendations")
|
12 |
+
|
13 |
+
# User input for user ID
|
14 |
+
user_id = st.number_input("Enter User ID", min_value=1, step=1)
|
15 |
+
|
16 |
+
# Get rated and unrated movies for the given user
|
17 |
+
rated_user_movies = merged_data[merged_data['userId'] == user_id]['title'].values
|
18 |
+
unrated_movies = movies[~movies['title'].isin(rated_user_movies)]['title']
|
19 |
+
|
20 |
+
# Make predictions on unrated movies
|
21 |
+
pred_ratings = [svd_model.predict(user_id, movie_id) for movie_id in unrated_movies]
|
22 |
+
|
23 |
+
# Sort predictions by estimated rating in descending order
|
24 |
+
sorted_predictions = sorted(pred_ratings, key=lambda x: x.est, reverse=True)
|
25 |
+
|
26 |
+
# Get top 10 movie recommendations
|
27 |
+
top_recommendations = sorted_predictions[:10]
|
28 |
+
|
29 |
+
# Display recommendations
|
30 |
+
st.write(f"\nTop 10 movie recommendations for User {user_id}:")
|
31 |
+
for recommendation in top_recommendations:
|
32 |
+
movie_title = movies[movies['title'] == recommendation.iid]['title'].values[0]
|
33 |
+
st.write(f"{movie_title} (Estimated Rating: {recommendation.est})")
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
pandas
|
2 |
+
scikit-learn
|
3 |
+
pickle
|
4 |
+
streamlit
|
5 |
+
surprise
|
svd_model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6632a316ac38946f937a76160c523dee16af7b740debd9716d830ed96849f3b4
|
3 |
+
size 14463353
|