| import streamlit as st |
| import pandas as pd |
|
|
|
|
| st.title("Movie Recommendation System") |
|
|
| st.write("This app recommends similar movies based on user ratings.") |
|
|
|
|
| |
| ratings = pd.read_csv("src/ratings.csv") |
| movies = pd.read_csv("src/movies.csv") |
|
|
|
|
| |
| df = pd.merge(ratings, movies, on="movieId") |
|
|
|
|
| |
| movie_stats = df.groupby("title")["rating"].agg(["mean", "count"]) |
|
|
|
|
| |
| movie_matrix = df.pivot_table( |
| index="userId", |
| columns="title", |
| values="rating" |
| ) |
|
|
|
|
| def recommend_movies(movie_name): |
|
|
| movie_user_ratings = movie_matrix[movie_name] |
|
|
| similar_movies = movie_matrix.corrwith( |
| movie_user_ratings |
| ) |
|
|
| corr_df = pd.DataFrame( |
| similar_movies, |
| columns=["Correlation"] |
| ) |
|
|
| corr_df.dropna(inplace=True) |
|
|
| corr_df = corr_df.join( |
| movie_stats["count"] |
| ) |
|
|
| recommendations = corr_df[ |
| corr_df["count"] > 100 |
| ] |
|
|
| recommendations = recommendations.sort_values( |
| "Correlation", |
| ascending=False |
| ) |
|
|
| recommendations = recommendations[ |
| recommendations.index != movie_name |
| ] |
|
|
| return recommendations.head(10) |
|
|
|
|
|
|
| movie_list = sorted( |
| movie_stats[movie_stats["count"] > 100].index |
| ) |
|
|
| selected_movie = st.selectbox( |
| "Select a movie", |
| movie_list |
| ) |
|
|
|
|
| if st.button("Recommend"): |
|
|
| result = recommend_movies(selected_movie) |
|
|
| st.subheader("Recommended Movies") |
|
|
| if result.empty: |
| st.warning("Bu film için yeterli öneri bulunamadı.") |
| else: |
| for movie in result.index: |
| st.write(movie) |