Spaces:
Runtime error
Runtime error
tobiasaurer
commited on
Commit
•
eee895c
1
Parent(s):
94b9600
add pages
Browse files
pages/1 - Popularity based recommender.py
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
st.title("Test Page")
|
2 |
+
|
3 |
+
st.write("""
|
4 |
+
### Instructions
|
5 |
+
Check the Sidebar and choose a recommender that suits your purpose.
|
6 |
+
""")
|
7 |
+
|
8 |
+
if st.button("TEST"):
|
9 |
+
|
10 |
+
st.write(movies.head(10))
|
pages/2 - User based recommender.py
ADDED
File without changes
|
pages/3 - Old recommender.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
|
4 |
+
|
5 |
+
st.title("Movie Recommender")
|
6 |
+
|
7 |
+
st.write("""
|
8 |
+
### Instructions
|
9 |
+
Type in a movie title with the release year in brackets (e.g. "The Matrix (1999)"), choose the number of recommendations you wish, and the app will recommend movies based on your chosen movie.\n\n
|
10 |
+
The recommendation process will take ca. 15 seconds.
|
11 |
+
""")
|
12 |
+
|
13 |
+
chosen_movie = st.text_input("Movie title and release year")
|
14 |
+
number_of_recommendations = st.slider("Number of recommendations", 1, 10, 5)
|
15 |
+
|
16 |
+
movies = pd.read_csv('https://raw.githubusercontent.com/tobiasaurer/recommender-systems/main/movie_data/movies.csv')
|
17 |
+
ratings = pd.read_csv('https://raw.githubusercontent.com/tobiasaurer/recommender-systems/main/movie_data/ratings.csv')
|
18 |
+
|
19 |
+
all_ratings = ratings.merge(movies, on='movieId')[['title', 'rating', 'userId']]
|
20 |
+
all_ratings_pivoted = all_ratings.pivot_table(index='userId', columns='title', values='rating')
|
21 |
+
|
22 |
+
def get_recommendations_for_movie(movie_name, n):
|
23 |
+
|
24 |
+
eligible_movies = []
|
25 |
+
|
26 |
+
for movie in all_ratings_pivoted.columns:
|
27 |
+
nr_shared_ratings = all_ratings_pivoted.loc[all_ratings_pivoted[movie_name].notnull() & all_ratings_pivoted[movie].notnull(), [movie_name, movie]].count()[0]
|
28 |
+
if nr_shared_ratings >= 10:
|
29 |
+
eligible_movies.append(movie)
|
30 |
+
|
31 |
+
return (
|
32 |
+
all_ratings_pivoted
|
33 |
+
[eligible_movies]
|
34 |
+
.corrwith(all_ratings_pivoted[movie_name]).sort_values(ascending=False)[1:n+1]
|
35 |
+
.index
|
36 |
+
)
|
37 |
+
|
38 |
+
if st.button("Recommend"):
|
39 |
+
|
40 |
+
recommendations = get_recommendations_for_movie(chosen_movie, number_of_recommendations)
|
41 |
+
|
42 |
+
st.write("Recommendations for", chosen_movie)
|
43 |
+
st.write(recommendations)
|