Muxammad al xorazmiy nomidagi toshkent axborot texnologiyalari universiteti


# A list holds the silhouette coefficients for each k



Download 0,87 Mb.
bet10/10
Sana31.12.2021
Hajmi0,87 Mb.
#225527
1   2   3   4   5   6   7   8   9   10
Bog'liq
Machine learning Ergashev Jasur 217 18 MI1

# A list holds the silhouette coefficients for each k

silhouette_coefficients = []


# Notice we start at 2 clusters for silhouette coefficient

for k in range(2, 11):

kmeans = KMeans(n_clusters=k, **kmeans_kwargs)

kmeans.fit(scaled_features)

score = silhouette_score(scaled_features, kmeans.labels_)

silhouette_coefficients.append(score)

In [18]:

plt.style.use("fivethirtyeight")

plt.plot(range(2, 11), silhouette_coefficients)

plt.xticks(range(2, 11))

plt.xlabel("Number of Clusters")

plt.ylabel("Silhouette Coefficient")

plt.show()
Advanced Clustering Evaluation

In [19]:


from sklearn.cluster import DBSCAN

from sklearn.datasets import make_moons

from sklearn.metrics import adjusted_rand_score

In [20]:


features, true_labels = make_moons(

n_samples=250, noise=0.05, random_state=42

)

scaled_features = scaler.fit_transform(features)



In [21]:

# Instantiate k-means and dbscan algorithms

kmeans = KMeans(n_clusters=2)

dbscan = DBSCAN(eps=0.3)
# Fit the algorithms to the features

kmeans.fit(scaled_features)

dbscan.fit(scaled_features)
# Compute the silhouette scores for each algorithm

kmeans_silhouette = silhouette_score(

scaled_features, kmeans.labels_

).round(2)

dbscan_silhouette = silhouette_score(

scaled_features, dbscan.labels_

).round (2)

In [22]:


kmeans_silhouette

Out[22]:


0.5

In [23]:


dbscan_silhouette

Out[23]:


0.38

In [24]:


# Plot the data and cluster silhouette comparison

fig, (ax1, ax2) = plt.subplots(

1, 2, figsize=(8, 6), sharex=True, sharey=True

)

fig.suptitle(f"Clustering Algorithm Comparison: Crescents", fontsize=16)



fte_colors = {

0: "#008fd5",

1: "#fc4f30",

}

# The k-means plot

km_colors = [fte_colors[label] for label in kmeans.labels_]

ax1.scatter(scaled_features[:, 0], scaled_features[:, 1], c=km_colors)

ax1.set_title(

f"k-means\nSilhouette: {kmeans_silhouette}", fontdict={"fontsize": 12}

)
# The dbscan plot

db_colors = [fte_colors[label] for label in dbscan.labels_]

ax2.scatter(scaled_features[:, 0], scaled_features[:, 1], c=db_colors)

ax2.set_title(

f"DBSCAN\nSilhouette: {dbscan_silhouette}", fontdict={"fontsize": 12}

)

plt.show()



In [25]:

ari_kmeans = adjusted_rand_score(true_labels, kmeans.labels_)

ari_dbscan = adjusted_rand_score(true_labels, dbscan.labels_)

In [26]:


round(ari_kmeans, 2)

Out[26]:


0.47

In [27]:


round(ari_dbscan, 2)

Out[27]:


1.0
Download 0,87 Mb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8   9   10




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