DavidHosp commited on
Commit
07586d5
·
1 Parent(s): c78c548

update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -3
app.py CHANGED
@@ -6,19 +6,26 @@ import pandas as pd
6
  from pandas.io.formats.style import Styler
7
  import gradio as gr
8
 
 
9
  def generar_recomendacion(svd_model, user_id, df, genres, top=5):
10
  # Crear un mapeo de id de película a título de película para una búsqueda más eficiente
11
  id_to_title = df.set_index('id')['title'].to_dict()
12
 
13
- # Obtener las recomendaciones utilizando la función `predict` del modelo SVD
 
 
 
 
 
14
  recommended_movies = []
15
- for movie_id in df['id'].unique():
16
  predicted_rating = svd_model.predict(user_id, movie_id).est
17
  recommended_movies.append((movie_id, predicted_rating))
18
 
19
- # Ordenar las películas según su predicción de rating
20
  recommended_movies.sort(key=lambda x: x[1], reverse=True)
21
 
 
22
  # Obtener los títulos de las películas recomendadas y géneros
23
  recommended_titles = [id_to_title[movie_id] for movie_id, _ in recommended_movies[:top]]
24
  recommended_genres = []
 
6
  from pandas.io.formats.style import Styler
7
  import gradio as gr
8
 
9
+
10
  def generar_recomendacion(svd_model, user_id, df, genres, top=5):
11
  # Crear un mapeo de id de película a título de película para una búsqueda más eficiente
12
  id_to_title = df.set_index('id')['title'].to_dict()
13
 
14
+
15
+ # Obtener las películas que el usuario aún no ha calificado
16
+ user_ratings = df[df['userId'] == user_id]
17
+ unwatched_movie_ids = set(df['id'].unique()) - set(user_ratings['movieId'].unique())
18
+
19
+ # Obtener las recomendaciones utilizando la función `predict` del modelo SVD
20
  recommended_movies = []
21
+ for movie_id in unwatched_movie_ids:
22
  predicted_rating = svd_model.predict(user_id, movie_id).est
23
  recommended_movies.append((movie_id, predicted_rating))
24
 
25
+ # Ordenar las películas según su predicción de rating
26
  recommended_movies.sort(key=lambda x: x[1], reverse=True)
27
 
28
+
29
  # Obtener los títulos de las películas recomendadas y géneros
30
  recommended_titles = [id_to_title[movie_id] for movie_id, _ in recommended_movies[:top]]
31
  recommended_genres = []