# ---
# 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
# ---

from copy import deepcopy
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# %matplotlib inline

sns.set() # for plot styling
plt.rcParams['figure.figsize'] = (16,9)
plt.style.use('ggplot')

# importing dataset
data = pd.read_csv('movie_metadata.csv')
data.shape
data.head()

newdata = data.iloc[:,4:6]
newdata

newdata = newdata.dropna()
newdata

# ## Build model

from sklearn.cluster import KMeans

model = KMeans(n_clusters=5)

model.fit(newdata)

model.cluster_centers_

print(model.labels_)
print(len(model.labels_))

print(type(model.labels_))
unique, counts = np.unique(model.labels_, return_counts=True)
print(dict(zip(unique,counts)))

# Plot the data
newdata['cluster'] = model.labels_
sns.set_style('whitegrid')
sns.lmplot('director_facebook_likes', 'actor_3_facebook_likes', data=newdata, hue='cluster',
          palette='coolwarm', size=6, aspect=1, fit_reg=False)



StarcoderdataJupyterScriptsDedupFiltered