<jupyter_start><jupyter_text>Clustering Setting import<jupyter_code>%matplotlib inline
from collections import Counter
import random

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
from sklearn.cluster import KMeans, DBSCAN
from scipy.stats import multivariate_normal

# Make plots larger
plt.rcParams['figure.figsize'] = (16, 10)<jupyter_output><empty_output><jupyter_text>Reading data from csv file<jupyter_code>original = pd.read_csv('clean_data_new.csv')
original.head()<jupyter_output><empty_output><jupyter_text>Drop columns that won't be used.<jupyter_code>movies = original.drop(['id','runtime','vote_count'],axis=1)
movies.head()<jupyter_output><empty_output><jupyter_text>Setting color function<jupyter_code># setting color function
def set_colors(labels, colors='rgbykcmw'):
    colored_labels = []
    for label in labels:
        if (label < 0) or (label > 6):
          colored_labels.append(colors[7]) 
        else:
          colored_labels.append(colors[label])
    return colored_labels<jupyter_output><empty_output><jupyter_text>Fit a k-means estimator Give the clusters in the labels_attribute.<jupyter_code>#### Fit a k-means estimator
X = np.array(movies)
estimator = KMeans(n_clusters = 4)
estimator.fit(X)

# Clusters are given in the labels_ attribute
labels = estimator.labels_
print (labels)<jupyter_output>[2 2 2 ... 0 0 0]<jupyter_text>K-means clustering for vote_average and revenue.<jupyter_code>colors = set_colors(labels)
plt.scatter(movies['revenue'],movies['vote_average'], c=colors)
plt.title("KMeans k=4")
plt.xlabel("revenue")
plt.ylabel("vote_average")
plt.show()<jupyter_output><empty_output><jupyter_text>K-means clustering for vote_average and budget.<jupyter_code>colors = set_colors(labels)
plt.scatter(movies['budget'],movies['vote_average'], c=colors)
plt.title("KMeans k=4")
plt.xlabel("budget")
plt.ylabel("vote_average")
plt.show()<jupyter_output><empty_output><jupyter_text>K-means clustering for vote_average and popularity.<jupyter_code>colors = set_colors(labels)
plt.scatter(movies['popularity'],movies['vote_average'], c=colors)
plt.title("KMeans k=4")
plt.xlabel("popularity")
plt.ylabel("vote_average")
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12600178094390027, 'fraction_numerical': 0.008014247551202136, 'mean_word_length': 7.511363636363637, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, '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': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '607366', 'license': 'MIT', 'n_tokens_mistral': 841, 'n_tokens_neox': 775, 'n_words': 152, 'path': 'Clustering/Clustering.ipynb', 'repo_name': 'BoyangWei/INFO_7390', 'size': '2246'}