Hands-On Machine Learning with Scikit-Learn and TensorFlow


| Chapter 9: Unsupervised Learning Techniques



Download 26,57 Mb.
Pdf ko'rish
bet192/225
Sana16.03.2022
Hajmi26,57 Mb.
#497859
1   ...   188   189   190   191   192   193   194   195   ...   225
Bog'liq
Hands on Machine Learning with Scikit Learn Keras and TensorFlow

242 | Chapter 9: Unsupervised Learning Techniques


Figure 9-2. An unlabeled dataset composed of five blobs of instances
Let’s train a K-Means clusterer on this dataset. It will try to find each blob’s center and
assign each instance to the closest blob:
from
sklearn.cluster
import
KMeans
k
=
5
kmeans
=
KMeans
(
n_clusters
=
k
)
y_pred
=
kmeans
.
fit_predict
(
X
)
Note that you have to specify the number of clusters 
k
that the algorithm must find.
In this example, it is pretty obvious from looking at the data that 
k
should be set to 5,
but in general it is not that easy. We will discuss this shortly.
Each instance was assigned to one of the 5 clusters. In the context of clustering, an
instance’s 
label
is the index of the cluster that this instance gets assigned to by the
algorithm: this is not to be confused with the class labels in classification (remember
that clustering is an unsupervised learning task). The 
KMeans
instance preserves a
copy of the labels of the instances it was trained on, available via the 
labels_
instance
variable:
>>> 
y_pred
array([4, 0, 1, ..., 2, 1, 0], dtype=int32)
>>> 
y_pred
is 
kmeans
.
labels_
True
We can also take a look at the 5 centroids that the algorithm found:
>>> 
kmeans
.
cluster_centers_
array([[-2.80389616, 1.80117999],
[ 0.20876306, 2.25551336],
[-2.79290307, 2.79641063],
[-1.46679593, 2.28585348],
[-2.80037642, 1.30082566]])
Of course, you can easily assign new instances to the cluster whose centroid is closest:

Download 26,57 Mb.

Do'stlaringiz bilan baham:
1   ...   188   189   190   191   192   193   194   195   ...   225




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish