<jupyter_start><jupyter_text>Collaborative Filtering<jupyter_code>import pandas as pd
from scipy import sparse
from sklearn.metrics.pairwise import cosine_similarity
ratings = pd.read_csv("toy_dataset.csv")
ratings
ratings = pd.read_csv("toy_dataset.csv",index_col=0)
ratings = ratings.fillna(0)
ratings
##creating a standardize method
def standardize(row):
    new_row = (row - row.mean())/(row.max() - row.min())
    return new_row

ratings_std = ratings.apply(standardize)


##we are taking a transpose since we want similarity between items which need to be in rows
item_similarity = cosine_similarity(ratings_std.T)
print(item_similarity)
item_similarity_df = pd.DataFrame(item_similarity,index=ratings.columns,columns=ratings.columns)
item_similarity_df
##Making Recommendations
def get_similar_movies(movie_name,user_rating):
    similar_score = item_similarity_df[movie_name]*(user_rating-2.5) 
    similar_score = similar_score.sort_values(ascending=False)
    
    return similar_score
print(get_similar_movies("action1",1))
##created a user as action_pritam
action_pritam = [("action1",4),("romantic2",1),("romantic3",5)]

similar_movies = pd.DataFrame()

for movie,rating in action_pritam:
    similar_movies = similar_movies.append(get_similar_movies(movie,rating),ignore_index=True)
similar_movies.head()
similar_movies.sum().sort_values(ascending=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10658082975679542, 'fraction_numerical': 0.008583690987124463, 'mean_word_length': 7.6894409937888195, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '178917', 'license': 'Apache-2.0', 'n_tokens_mistral': 501, 'n_tokens_neox': 477, 'n_words': 86, 'path': 'Collaborative Filtering.ipynb', 'repo_name': 'pritam0123/Movie-Recommendation-System', 'size': '1398'}