<jupyter_start><jupyter_text>Practical Machine Learning with Python from  the youtube channel sentdex "The goal is to break it down so much that it is panfully simple " Episode:* [Clustering Introduction - Practical Machine Learning Tutorial with Python p.34:](https://www.youtube.com/watch?v=ZueoXMgCd1c&list=PLQVvvaa0QuDfKTOs3Keq_kaG2P55YRn5v&index=34)  Objective: Learn about Practical Machine Learning with Python from Scratch with Python .  Introduction: Up until this point, every thing that we've covered is known as supervised ML, which means we decide what the classes of the feature sets are. With unsupervised ML the our role begins to be removed.We are gonna be covering clustering, which comes in two major forms:* Flat Clustering: You define the nº of clusters * Hierarchical  Clustering:The machine choose  the nº of clustersWith both forms of clustering, the machine is simply given a data set(feature sets), and then the machine itself is going to search fo groups or clusters.The fist one  that we are going to be covering is k-means algorithm  k-means algorithm<jupyter_code>%matplotlib inline 
import matplotlib.pyplot as plt
from matplotlib import style
import numpy as np
from sklearn.cluster import KMeans
style.use('ggplot')

X = np.array([[1, 2]
            ,[1.5, 1.8]
            ,[5, 8]
            ,[8, 8]
            ,[1, 0.6]
            ,[9, 11]])


#plt.scatter(X[:, 0],X[:, 1], s=150, linewidths = 5, zorder = 10)
#plt.show()

clf = KMeans(n_clusters=2)
clf.fit(X)

centroids = clf.cluster_centers_
labels = clf.labels_
print(labels)


colors = ["g.","r.","c.","y."]
for i in range(len(X)):
    plt.plot(X[i][0], X[i][1], colors[labels[i]], markersize = 10)
plt.scatter(centroids[:, 0],centroids[:, 1], marker = "x", s=150, linewidths = 5)
plt.show()<jupyter_output>[0 0 1 1 0 1]
{'fraction_non_alphanumeric': 0.1075565361279647, 'fraction_numerical': 0.028681742967457253, 'mean_word_length': 4.212643678160919, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '405798', 'license': 'MIT', 'n_tokens_mistral': 643, 'n_tokens_neox': 585, 'n_words': 224, 'path': 'Practical-Machine-Learning-with-Python/Clustering/k-means algorithm/Machine_Learning_ P_34_Clustering_Introduction.ipynb', 'repo_name': 'glauco-endrigo/Practical-Machine-Learning-with-Python', 'size': '1813'}