<jupyter_start><jupyter_text>Activity 01<jupyter_code>import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
data = pd.read_csv("wholesale_customers_data.csv")
data.isnull().sum()
outliers = {}
for i in range(data.shape[1]):
    min_t = data[data.columns[i]].mean() - (3 * data[data.columns[i]].std())
    max_t = data[data.columns[i]].mean() + (3 * data[data.columns[i]].std())
    count = 0
    for j in data[data.columns[i]]:
        if j < min_t or j > max_t:
            count += 1
    outliers[data.columns[i]] = [count,data.shape[0]-count]
print(outliers)
plt.hist(data["Fresh"])
plt.show()
plt.figure(figsize=(8,8))
plt.pie(outliers["Detergents_Paper"],autopct="%.2f")
plt.show()
data_standardized = (data - data.mean())/data.std()
data_standardized.head()<jupyter_output><empty_output><jupyter_text>Activity 02<jupyter_code>from sklearn.cluster import KMeans
ideal_k = []
for i in range(1,21):
    est_kmeans = KMeans(n_clusters=i, random_state = 0)
    est_kmeans.fit(data_standardized)
    
    ideal_k.append([i,est_kmeans.inertia_])
ideal_k = np.array(ideal_k)
plt.plot(ideal_k[:,0],ideal_k[:,1])
plt.show()<jupyter_output><empty_output><jupyter_text>A number of 6 cluster was selected<jupyter_code>est_kmeans = KMeans(n_clusters=6, random_state = 0)
est_kmeans.fit(data_standardized)
pred_kmeans = est_kmeans.predict(data_standardized)
plt.subplots(1, 2, sharex='col', sharey='row', figsize=(16,8))
plt.scatter(data.iloc[:,5], data.iloc[:,3], c=pred_kmeans, s=20)
plt.xlim([0, 20000])
plt.ylim([0,20000])
plt.xlabel('Frozen')
plt.subplot(1, 2, 1)
plt.scatter(data.iloc[:,4], data.iloc[:,3], c=pred_kmeans, s=20)
plt.xlim([0, 20000])
plt.ylim([0,20000])
plt.xlabel('Grocery')
plt.ylabel('Milk')
plt.show()<jupyter_output><empty_output><jupyter_text>Activity 03<jupyter_code>from sklearn.cluster import MeanShift
est_meanshift = MeanShift(0.4)
est_meanshift.fit(data_standardized)
pred_meanshift = est_meanshift.predict(data_standardized)
plt.subplots(1, 2, sharex='col', sharey='row', figsize=(16,8))
plt.scatter(data.iloc[:,5], data.iloc[:,3], c=pred_meanshift, s=20)
plt.xlim([0, 20000])
plt.ylim([0,20000])
plt.xlabel('Frozen')
plt.subplot(1, 2, 1)
plt.scatter(data.iloc[:,4], data.iloc[:,3], c=pred_meanshift, s=20)
plt.xlim([0, 20000])
plt.ylim([0,20000])
plt.xlabel('Grocery')
plt.ylabel('Milk')
plt.show()<jupyter_output><empty_output><jupyter_text>Activity 04<jupyter_code>from sklearn.cluster import DBSCAN
est_dbscan = DBSCAN(eps=0.8)
pred_dbscan = est_dbscan.fit_predict(data_standardized)
plt.subplots(1, 2, sharex='col', sharey='row', figsize=(16,8))
plt.scatter(data.iloc[:,5], data.iloc[:,3], c=pred_dbscan, s=20)
plt.xlim([0, 20000])
plt.ylim([0,20000])
plt.xlabel('Frozen')
plt.subplot(1, 2, 1)
plt.scatter(data.iloc[:,4], data.iloc[:,3], c=pred_dbscan, s=20)
plt.xlim([0, 20000])
plt.ylim([0,20000])
plt.xlabel('Grocery')
plt.ylabel('Milk')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1909153005464481, 'fraction_numerical': 0.05122950819672131, 'mean_word_length': 7.136111111111111, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 22, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '36059', 'license': 'MIT', 'n_tokens_mistral': 1395, 'n_tokens_neox': 1252, 'n_words': 181, 'path': 'Activity04/Activity04.ipynb', 'repo_name': 'Develop-Packt/Clustering', 'size': '2928'}