# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Importing libraries

import pandas as pd
import numpy as np
from sklearn.metrics.pairwise import cosine_similarity
from sklearn.feature_extraction.text import CountVectorizer

# # Importing data

data=pd.read_csv("D:\\Workshops\\Machine Learning for Data Science & Artifcial Intelligence With Python\\data\\movie_data.CSV")

data.head()

# # Data wrangling

data.isnull().sum()

data.dropna(inplace=True)

data=data[~data["movie_title"].duplicated()]

data.reset_index(inplace=True)

data.head()

data.drop("index",axis=1,inplace=True)

data.head()

data.isnull().sum()

data.duplicated().sum()

# # Needful columns

df=data[["movie_title","director_name","actor_1_name","actor_2_name","genres","country","language"]]

df.head()

# # Combined features

" ".join(list(df.iloc[0].values))

# +
features=[]

for i in range(df.shape[0]):
    features.append(" ".join(list(df.iloc[i].values)))
# -

df["features"]=features

# # Fetaure count matrix

cvec=CountVectorizer()

cv_df=cvec.fit_transform(df["features"])

cv_df.toarray()

cv_df.shape

df.shape

# # Cosine similarity

cs=cosine_similarity(cv_df)

cs

cs.shape

# # Recommendations

title="Avatar"
movie_index=df[[title in name for name in df["movie_title"]]].index[0]

movie_index

scores=list(enumerate(cs[movie_index]))

scores

sorted_scores=sorted(scores,key=lambda x:x[1],reverse=True)

sorted_scores

top_10=[h[0] for h in sorted_scores[1:11]]

top_10

df.iloc[top_10]["movie_title"]



StarcoderdataJupyterScriptsDedupFiltered