<jupyter_start><jupyter_text>Exersice A<jupyter_code>data = pd.read_csv('nba2013_data.csv')
data = data.select_dtypes(['number'])
imp_mean = IterativeImputer(random_state=0)
data.replace('?.0','NaN', inplace = True)
imputed_DF = pd.DataFrame(imp_mean.fit_transform(data))
imputed_DF.columns = data.columns
imputed_DF.index = data.index
imputed_DF.head()
distortions = []
K = range(1,10)
for k in K:
    kmeanModel = KMeans(n_clusters=k)
    kmeanModel.fit(imputed_DF)
    distortions.append(kmeanModel.inertia_)
plt.figure(figsize=(16,8))
plt.plot(K, distortions, 'bx-')
plt.xlabel('k')
plt.ylabel('Distortion')
plt.title('The Elbow Method showing the optimal k')
plt.show()
distortions = []
K = range(2,10)
for k in K:
    kmeanModel = KMeans(n_clusters=k).fit(imputed_DF)
    #print(np.unique(kmeanModel.labels_))
    labels = kmeanModel.labels_
    distortions.append(metrics.calinski_harabasz_score(imputed_DF, labels))
plt.figure(figsize=(16,8))
plt.plot(K, distortions, 'bx-')
plt.xlabel('k')
plt.ylabel('Distortion')
plt.title('Calinski harabasz showing the optimal k')
plt.show()
distortions = []
K = range(2,10)
for k in K:
    kmeanModel = KMeans(n_clusters=k).fit(imputed_DF)
    #print(np.unique(kmeanModel.labels_))
    labels = kmeanModel.labels_
    distortions.append(metrics.davies_bouldin_score(imputed_DF, labels))
plt.figure(figsize=(16,8))
plt.plot(K, distortions, 'bx-')
plt.xlabel('k')
plt.ylabel('Distortion')
plt.title('Davis Bouldin Score showing the optimal k')
plt.show()<jupyter_output><empty_output><jupyter_text>Exersice B<jupyter_code>Sum_of_squared_distances = []
K = range(1,15)
for k in K:
    df = KMeans(n_clusters=k)
    df = df.fit(imputed_DF)
    Sum_of_squared_distances.append(df.inertia_)
plt.figure(figsize=(16,8))
plt.plot(K, Sum_of_squared_distances, 'bx-')
plt.xlabel('k')
plt.ylabel('Sum_of_squared_distances')
plt.title('Sum of squared Method For Optimal k')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15297741273100615, 'fraction_numerical': 0.015400410677618069, 'mean_word_length': 6.4106463878327, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '254665', 'license': 'MIT', 'n_tokens_mistral': 840, 'n_tokens_neox': 775, 'n_words': 123, 'path': 'Assignment1/Assignment1.1.ipynb', 'repo_name': 'Nybbbbe/data-mining', 'size': '1948'}