<jupyter_start><jupyter_text>Unsupervised Learning- train the model on unlabelled data without any guidance- 2types    - Clustering    - Association Clustering- K Means Algorithm    - choose the optimal value of k    - finding out the centroids    - calculation the distances and mean    - repeat step 2 and 3 until you meet the convergence<jupyter_code>from sklearn.datasets import load_iris
iris=load_iris()
iris.keys()
import pandas as pd
df=pd.DataFrame(iris.data,columns=iris.feature_names)
df.head(2)
df.isna().sum()
x=df.iloc[:,:]
range_k=range(1,11)
sse_list=[]
from sklearn.cluster import KMeans
for k in range_k:
    model=KMeans(n_clusters=k)
    model.fit(x)
    sse=model.inertia_
    sse_list.append(sse)
    print("the inertia for k={} is {}".format(k,sse))
import matplotlib.pyplot as plt
x1=range_k
y1=sse_list
plt.plot(x1,y1,marker='o')
plt.show()

from sklearn.cluster import KMeans
model=KMeans(n_clusters=3)
model.fit(x)
y_predict=model.predict(x)
y_predict
df["predicted_values"]=y_predict
df.head()
df["predicted_values"].value_counts()
50
50
50<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11384335154826958, 'fraction_numerical': 0.01639344262295082, 'mean_word_length': 5.316091954022989, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '357135', 'license': 'CC0-1.0', 'n_tokens_mistral': 426, 'n_tokens_neox': 410, 'n_words': 98, 'path': 'Day-8/08_Day8_03Nov2020.ipynb', 'repo_name': 'AP-State-Skill-Development-Corporation/Machine-Learning-Using-Python-MB7', 'size': '1098'}