Spaces:
Runtime error
Runtime error
tobiasaurer
commited on
Commit
•
b30ab55
1
Parent(s):
eee895c
change app.py
Browse files
app.py
CHANGED
@@ -2,42 +2,15 @@ import streamlit as st
|
|
2 |
import pandas as pd
|
3 |
|
4 |
|
5 |
-
st.title("Movie
|
6 |
|
7 |
st.write("""
|
8 |
### Instructions
|
9 |
-
|
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)
|
|
|
2 |
import pandas as pd
|
3 |
|
4 |
|
5 |
+
st.title("Movie Recommenders")
|
6 |
|
7 |
st.write("""
|
8 |
### Instructions
|
9 |
+
Check the Sidebar and choose a recommender that suits your purpose.
|
|
|
10 |
""")
|
11 |
|
|
|
|
|
|
|
12 |
movies = pd.read_csv('https://raw.githubusercontent.com/tobiasaurer/recommender-systems/main/movie_data/movies.csv')
|
13 |
ratings = pd.read_csv('https://raw.githubusercontent.com/tobiasaurer/recommender-systems/main/movie_data/ratings.csv')
|
14 |
|
15 |
all_ratings = ratings.merge(movies, on='movieId')[['title', 'rating', 'userId']]
|
16 |
all_ratings_pivoted = all_ratings.pivot_table(index='userId', columns='title', values='rating')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|