<jupyter_start><jupyter_text>Copyright (C) 2020 <NAME> - All Rights Reserved 12/29/2020 Implementation of Movie Recommender System - (using MovieLenz dataset) Here we wanna make a item-item recommendation which is a kind of Content base recommendation  Question: find the 10 items which have most similarity to an input movie<jupyter_code>import pandas as pd
import numpy as np
from sklearn.metrics.pairwise import pairwise_distances<jupyter_output><empty_output><jupyter_text>Reading datasets<jupyter_code>r_col = 'user_id | item_id | rating | timestamp'.split(' | ')
raiting = pd.read_csv('movies-100k/u.data', sep='\t', names=r_col)
raiting.head()
i_col = 'movie_id | movie_title | release date | video release date | IMDb URL | unknown | Action | Adventure | Animation | Children | Comedy | Crime | Documentary | Drama | Fantasy | Film-Noir | Horror | Musical | Mystery | Romance | Sci-Fi | Thriller | War | Western'.split(' | ')
items = pd.read_csv('movies-100k/u.item', sep='|', names=i_col, encoding='latin-1')
items.head()<jupyter_output><empty_output><jupyter_text>Getting the number of users and items in order to define a similarity matrix<jupyter_code>n_users = raiting.user_id.unique().shape[0]
n_items = raiting.item_id.unique().shape[0]

n_items<jupyter_output><empty_output><jupyter_text>Place rates which users submitted for each item in a matrix<jupyter_code>data_matrix = np.zeros((n_users, n_items))
for line in raiting.itertuples():
    data_matrix[line[1] - 1, line[2] - 1] = line[3]
    
data_matrix<jupyter_output><empty_output><jupyter_text>Now calculate the similarity using 'Cosine' method<jupyter_code>user_similarity = pairwise_distances(data_matrix, metric='cosine')
item_similarity = pairwise_distances(data_matrix, metric='cosine')

user_similarity<jupyter_output><empty_output><jupyter_text>And finaly define a function for searching item in the similarity matrix<jupyter_code>def movie_recommender(movie_name, similarity_matrix):
    
    movie_id = int(items[items.movie_title == movie_name]['movie_id'])
    
    score = similarity_matrix[movie_id - 1]
    
    sorted_score = sorted(score, key=lambda x : x, reverse=True)
    
    movie_indexes = [list(score).index(x) for x in sorted_score]
    
    return items['movie_title'].iloc[movie_indexes]<jupyter_output><empty_output><jupyter_text>Yooha :) Did it. The 10 items which have the most rate similarity to 'Mad Love (1995)' movie<jupyter_code>movie_recommender('Mad Love (1995)', item_similarity).unique().tolist()[1:11]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1109362706530291, 'fraction_numerical': 0.016522423288749016, 'mean_word_length': 6.224431818181818, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 30, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '188475', 'license': 'MIT', 'n_tokens_mistral': 894, 'n_tokens_neox': 827, 'n_words': 204, 'path': 'Recommender_System.ipynb', 'repo_name': 'nahbos/Recommendation-System', 'size': '2560'}