<jupyter_start><jupyter_text>Preprocessing<jupyter_code>#removing movie's year from title column and making a new column for it

movies_df['year of release'] = movies_df.title.str.extract("(\(\d\d\d\d\))", expand=False)
movies_df.head(5)
#removing parentheses

movies_df['year of release'] = movies_df.title.str.extract("(\d\d\d\d)", expand=False)
movies_df.head(5)
#removing year from title column

movies_df['title'] = movies_df.title.str.replace("(\(\d\d\d\d\))", '')
movies_df.head(5)
#applying strip function to get rid of extra spaces

movies_df['title'] = movies_df['title'].apply(lambda x: x.strip())
movies_df.head(5)
#applying split function to of Genres column

movies_df['genres'] = movies_df.genres.str.split('|')
movies_df.head()<jupyter_output><empty_output><jupyter_text>Applying One Hot Encoding to Genres<jupyter_code>movies_df
movies_genres = movies_df.copy()

#for every row, iterate through list of genres and put 1 for corresponding column
for i,row in movies_df.iterrows():
    for genre in row['genres']:
        movies_genres.at[i,genre]=1

#filling NaN values with 0 which signifies movie does not have that genre
movies_genres= movies_genres.fillna(0)
movies_genres.head(5)
#dropping timestamp column from ratings column

ratings_df = ratings_df.drop('timestamp',1)
ratings_df.head(5)<jupyter_output>/var/folders/yd/82cyvr0s27b30fytssfmwbnc0000gn/T/ipykernel_43687/3449506270.py:3: FutureWarning: In a future version of pandas all arguments of DataFrame.drop except for the argument 'labels' will be keyword-only
  ratings_df = ratings_df.drop('timestamp',1)<jupyter_text>Content Based recommendation system<jupyter_code>#creating a list of my top movies and my ratings for those movies

my_movies = [
    {'title':"Inglourious Basterds",'rating':9.5},
    {'title':"Django Unchained",'rating':8.5},
    {'title':"Jumanji",'rating':8},
    {'title':"Only Lovers Left Alive",'rating':9},
    {'title':"Swades: We, the People (Our Country)",'rating':8.7}
]
input_movies= pd.DataFrame(my_movies)
input_movies<jupyter_output><empty_output><jupyter_text>Extracting my movies from movies_df<jupyter_code>a=input_movies['title'].tolist()
a
input_id = movies_df[movies_df['title'].isin(a)]
input_id
input_movies = pd.merge(input_id, input_movies)
input_movies
#removing the genres and year of release
input_movies = input_movies.drop('genres',1).drop('year of release',1)
input_movies
input_id<jupyter_output><empty_output><jupyter_text>Learning my preferences<jupyter_code>#filtering out movies 

mansi_Movies = movies_genres[movies_genres['movieId'].isin(input_movies['movieId'].tolist())]
mansi_Movies<jupyter_output><empty_output><jupyter_text>Cleaning the Data<jupyter_code>#resetting the index
mansi_Movies = mansi_Movies.reset_index(drop=True)
mansi_Movies
#dropping movieId title genres and year columns becuase we only need the actual genre table

mansi_Genres = mansi_Movies.drop("movieId",1).drop("title",1).drop("genres",1).drop("year of release",1)
mansi_Genres<jupyter_output><empty_output><jupyter_text>User Profile We will now turn each genre into weight.It will be achieved by mutiplying the mansi_Genres table and my ratings from input_movies table and summing up the resulting table by column.<jupyter_code>userProfile = mansi_Genres.transpose().dot(input_movies['rating'])

userProfile<jupyter_output><empty_output><jupyter_text>Let us now extract the genre table from the original df<jupyter_code>genreTable = movies_genres.set_index(movies_genres['movieId'])

genreTable = genreTable.drop('movieId',1).drop('title',1).drop('genres',1).drop('year of release',1)
genreTable.shape
genreTable.head(5)
#multiplying genres by weights and then taking the weighted average
s=userProfile.sum()

recommendation_table = ((genreTable*userProfile).sum(axis=1)/s)
recommendation_table.head()
#sorting in descending order
recommendation_table = recommendation_table.sort_values(ascending=False)
recommendation_table.head()<jupyter_output><empty_output><jupyter_text>Recommendation Table Here are top 25 movie recommendations for me:<jupyter_code>key_ = recommendation_table.head(25).keys()

movies_df.loc[movies_df['movieId'].isin(key_)]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1216312902456475, 'fraction_numerical': 0.015025041736227046, 'mean_word_length': 7.848101265822785, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 36, 'https://': 0, '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': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '551800', 'license': 'CC0-1.0', 'n_tokens_mistral': 1526, 'n_tokens_neox': 1464, 'n_words': 310, 'path': 'Day2 Content Based Filtering to find top 25 movie recommendations for me.ipynb', 'repo_name': 'MansiSharma98/66daysofData', 'size': '4193'}