<jupyter_start><jupyter_text>CODE TO IMPLEMENT A RECOMMENDER SYSTEMBy: <NAME>  Problem Statement* This notebook implements a movie recommender system.* Recommender systems are used to suggest movies or songs to users based on their interest or usage history.* For example, Netflix recommends movies to watch based on the previous movies you've watched.* In this example, we will  use Item-Based Collaborative Filter* Dataset  MovieLens: https://grouplens.org/datasets/movielens/100k/  Step 0: LIBRARIES IMPORT<jupyter_code>import pandas as pd
import numpy as np 
import seaborn as sns
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>Step 1: IMPORT DATASET<jupyter_code>movies_titles_df = pd.read_csv("D:/Code/Projects/DL and ML Practical Tutorials - Package/Project 8/Movie_Id_Titles")
movies_titles_df
movies_rating_df = pd.read_csv("D:/Code/Projects/DL and ML Practical Tutorials - Package/Project 8/u.data", sep="\t", names=['user_id', 'item_id', "rating", "timestamp"])
movies_rating_df.drop(['timestamp'], axis="columns", inplace=True)
movies_rating_df
movies_rating_df.describe()
movies_rating_df.info()
movies_rating_df = pd.merge(movies_rating_df, movies_titles_df, on="item_id")
movies_rating_df
movies_rating_df.shape<jupyter_output><empty_output><jupyter_text>Step 2: VISUALIZE DATASET<jupyter_code>movies_rating_df.groupby('title')['rating'].describe()
rating_df_mean = movies_rating_df.groupby('title')['rating'].describe()['mean']
rating_df_mean
rating_df_count = movies_rating_df.groupby('title')['rating'].describe()['count']
rating_df_count
rating_mean_count_df = pd.concat([rating_df_count, rating_df_mean], axis="columns")
rating_mean_count_df.reset_index()
rating_mean_count_df['mean'].plot(bins=100, kind='hist', color='r')
rating_mean_count_df['count'].plot(bins=100, kind='hist', color='r')
rating_mean_count_df[rating_mean_count_df['mean']==5]
rating_mean_count_df.sort_values('count', ascending=False).head(100)
rating_mean_count_df.sort_values('count', ascending=True).head(200)<jupyter_output><empty_output><jupyter_text>Step 3: PERFORM ITEM-BASED COLLABORATIVE FILTERING ON ONE MOVIE SAMPLE<jupyter_code>userid_movietitle_matrix = movies_rating_df.pivot_table(index='user_id', columns='title', values='rating')
userid_movietitle_matrix
titanic = userid_movietitle_matrix['Titanic (1997)']
titanic
star_wars = userid_movietitle_matrix['Star Wars (1977)']
star_wars_correlations = pd.DataFrame(userid_movietitle_matrix.corrwith(star_wars), columns=['Correlation'])
star_wars_correlations = star_wars_correlations.join(rating_mean_count_df['count'])
star_wars_correlations.dropna(inplace=True)
star_wars_correlations[star_wars_correlations['count']>100].sort_values('Correlation', ascending=False)
titanic_correlations = pd.DataFrame(userid_movietitle_matrix.corrwith(titanic), columns=['Correlation'])
titanic_correlations = titanic_correlations.join(rating_mean_count_df['count'])
titanic_correlations.dropna(inplace=True)
titanic_correlations
titanic_correlations[titanic_correlations['count']>80].sort_values('Correlation', ascending=False)<jupyter_output><empty_output><jupyter_text>Step 4: CREATE AN ITEM-BASED COLLABORATIVE FILTER ON THE ENTIRE DATASET<jupyter_code>userid_movietitle_matrix
movie_correlations =userid_movietitle_matrix.corr(method='pearson', min_periods=80)
movie_correlations
myRatings = pd.read_csv("D:/Code/Projects/DL and ML Practical Tutorials - Package/Project 8/My_Ratings.csv")
myRatings
myRatings['Movie Name'][0]
similar_movies_list = pd.Series()

for i in range(2):
    similar_movie = movie_correlations[myRatings['Movie Name'][i]].dropna()
    similar_movie = similar_movie.map(lambda x: x*myRatings['Ratings'][i])
    similar_movies_list = similar_movies_list.append(similar_movie)
similar_movies_list.sort_values(inplace=True, ascending=False)
print(similar_movies_list.head(10))<jupyter_output><NAME> (1997)                             5.000000
Con Air (1997)                               2.349141
Pretty Woman (1990)                          2.348951
Michael (1996)                               2.210110
<NAME> and the Last Crusade (1989)    2.072136
Top Gun (1986)                               2.028602
<NAME> (1997)                             1.989656
Multiplicity (1996)                          1.984302
Grumpier Old Men (1995)                      1.953494
Ghost and the Darkness, The (1996)           1.895376
dtype: float64
{'fraction_non_alphanumeric': 0.11023266320307205, 'fraction_numerical': 0.035012423763270836, 'mean_word_length': 6.153473344103393, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 26, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '443894', 'license': 'MIT', 'n_tokens_mistral': 1655, 'n_tokens_neox': 1491, 'n_words': 265, 'path': 'Movie Recommender System-Filming.ipynb', 'repo_name': 'rsanimesh/Udemy-Complete-Data-Science-Bootcamp', 'size': '4451'}