<jupyter_start><jupyter_text>Importing the necessary dependencies<jupyter_code>import pandas as pd
import numpy as np
import difflib
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import cosine_similarity<jupyter_output><empty_output><jupyter_text>Data collection and processing<jupyter_code>df = pd.read_csv('C:/Users/Hemant/jupyter_codes/ML Project 1/Movie recommendation system/movies.csv')
# print first 5 rows of the dataset
df.head()
# shape of the dataset
df.shape
# info about the dataset
df.info()
# selecting the relevant feature for recomeendation
selected_features = ['genres', 'keywords', 'title', 'runtime', 'tagline', 'cast', 'director']
selected_features
# replacing the null values with null strings
for i in selected_features:
    df[i] = df[i].fillna('')
# combining all the selected features
combined_features = df['genres'] +' '+ df['keywords'] +' '+ df['tagline'] +' '+ df['cast'] +' '+ df['director'] 
combined_features
# convert the text data to feature vectors
vectorizer = TfidfVectorizer()
feature_vectors = vectorizer.fit_transform(combined_features)
print(feature_vectors)<jupyter_output>(0, 2432)	0.17272411194153
  (0, 7755)	0.1128035714854756
  (0, 13024)	0.1942362060108871
  (0, 10229)	0.16058685400095302
  (0, 8756)	0.22709015857011816
  (0, 14608)	0.15150672398763912
  (0, 16668)	0.19843263965100372
  (0, 14064)	0.20596090415084142
  (0, 13319)	0.2177470539412484
  (0, 17290)	0.20197912553916567
  (0, 17007)	0.23643326319898797
  (0, 13349)	0.15021264094167086
  (0, 11503)	0.27211310056983656
  (0, 11192)	0.09049319826481456
  (0, 16998)	0.1282126322850579
  (0, 15261)	0.07095833561276566
  (0, 4945)	0.24025852494110758
  (0, 14271)	0.21392179219912877
  (0, 3225)	0.24960162956997736
  (0, 16587)	0.12549432354918996
  (0, 14378)	0.33962752210959823
  (0, 5836)	0.1646750903586285
  (0, 3065)	0.22208377802661425
  (0, 3678)	0.21392179219912877
  (0, 5437)	0.1036413987316636
  :	:
  (4801, 17266)	0.2886098184932947
  (4801, 4835)	0.24713765026963996
  (4801, 403)	0.17727585190343226
  (4801, 6935)	0.2886098184932947
  (4801, 11663)	0.21557500762727902
  (4801, 1672[...]<jupyter_text>Cosine Singularity<jupyter_code># getting the similarity score/ similarity confidence value
similarity = cosine_similarity(feature_vectors)
similarity
similarity.shape
# getting the movie name from the user
movie_name = input('ENTER THE MOVIE NAME : ')
# creating a list with all the movie names
movie_title_list = df['title'].tolist()
movie_title_list
# finding the close match to the movie name given by user
close_match_list = difflib.get_close_matches(movie_name, movie_title_list)
print(close_match_list)
close_match = close_match_list[0]
# finding the index of the movie
movie_index = df[df['title'] == close_match]['index'].values[0]
movie_index
# getting a list of similar values
similarity_score = list(enumerate(similarity[movie_index]))
similarity_score
len(similarity_score)
#sorting the movies based on their similarity score
sorted_movies = sorted(similarity_score, key = lambda x : x[1], reverse = True)
sorted_movies
# print the name of similar movies based on the index
print('RECOMMENDED MOVIES : ')

i = 1
for movies in sorted_movies:
    index = movies[0]
    title_name = df[df.index == index]['title'].values[0]
    if i < 21:
        print(i, ')', title_name)
        i += 1<jupyter_output>RECOMMENDED MOVIES : 
1 ) Iron Man
2 ) Iron Man 2
3 ) Iron Man 3
4 ) Avengers: Age of Ultron
5 ) The Avengers
6 ) Captain America: Civil War
7 ) Captain America: The Winter Soldier
8 ) Ant-Man
9 ) X-Men
10 ) Made
11 ) X-Men: Apocalypse
12 ) X2
13 ) The Incredible Hulk
14 ) The Helix... Loaded
15 ) X-Men: First Class
16 ) X-Men: Days of Future Past
17 ) Captain America: The First Avenger
18 ) Kick-Ass 2
19 ) Guardians of the Galaxy<jupyter_text>Movie recommendation system<jupyter_code># getting the movie name from the user
movie_name = input('ENTER THE MOVIE NAME : ')

# creating a list with all the movie names
movie_title_list = df['title'].tolist()

# finding the close match to the movie name given by user
close_match_list = difflib.get_close_matches(movie_name, movie_title_list)
close_match = close_match_list[0]

# finding the index of the movie
movie_index = df[df['title'] == close_match]['index'].values[0]

# getting a list of similar values
similarity_score = list(enumerate(similarity[movie_index]))

#sorting the movies based on their similarity score
sorted_movies = sorted(similarity_score, key = lambda x : x[1], reverse = True)

# print the name of similar movies based on the index
print('RECOMMENDED MOVIES : ')
i = 1
for movies in sorted_movies:
    index = movies[0]
    title_name = df[df.index == index]['title'].values[0]
    if i < 21:
        print(i, ')', title_name)
        i += 1<jupyter_output>ENTER THE MOVIE NAME : x-men
RECOMMENDED MOVIES : 
1 ) X-Men
2 ) X2
3 ) X-Men: The Last Stand
4 ) X-Men: Days of Future Past
5 ) X-Men: Apocalypse
6 ) The Wolverine
7 ) Avengers: Age of Ultron
8 ) Ant-Man
9 ) The Avengers
10 ) X-Men Origins: Wolverine
11 ) Iron Man 2
12 ) The Incredible Hulk
13 ) The Image Revolution
14 ) Man of Steel
15 ) Deadpool
16 ) Thor: The Dark World
17 ) The Amazing Spider-Man 2
18 ) X-Men: First Class
19 ) Captain America: The Winter Soldier
20 ) Superman II
{'fraction_non_alphanumeric': 0.10280549802297119, 'fraction_numerical': 0.1517604970815289, 'mean_word_length': 4.8956714761376245, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 14, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '594359', 'license': 'MIT', 'n_tokens_mistral': 2448, 'n_tokens_neox': 1934, 'n_words': 568, 'path': 'Recommendation model.ipynb', 'repo_name': 'Hemant2801/Movie-recommendation-system', 'size': '5311'}