Тема 5: Проектирование мультимедиа проектов и модели их разработки


Bu safar biz NumPy va sklearn.cluster.KMeans dan foydalanamiz


Download 1.83 Mb.
bet6/6
Sana23.02.2023
Hajmi1.83 Mb.
#1223381
1   2   3   4   5   6
Bog'liq
3-mavzu-sirtqi

Bu safar biz NumPy va sklearn.cluster.KMeans dan foydalanamiz:

  • >>> import numpy as np >>> from sklearn.cluster import KMeans >>> x = np.array([(0.0, 0.0), ... (9.9, 8.1), ... (-1.0, 1.0), ... (7.1, 5.6), ... (-5.0, -5.5), ... (8.0, 9.8), ... (0.5, 0.5)]) >>> x array([[ 0. , 0. ], [ 9.9, 8.1], [-1. , 1. ], [ 7.1, 5.6], [-5. , -5.5], [ 8. , 9.8], [ 0.5, 0.5]])

Keyingi qadam ma'lumotlarni o'lchashdir, lekin bu har doim ham zarur emas. Ma'lumotlarni oldindan qayta ishlash tugallangach, biz KMeans nusxasini yaratamiz va uni ma'lumotlarimizga moslashtiramiz:

  • >>> cluster_analyzer = KMeans(n_clusters=3, init='k-means++') >>> cluster_analyzer.fit() >>> cluster_analyzer.fit(x) KMeans(algorithm='auto', copy_x=True, init='k-means++', max_iter=300, n_clusters=3, n_init=10, n_jobs=None, precompute_distances='auto', random_state=None, tol=0.0001, verbose=0)

Shunday qilib, biz klasterlar markazlarining koordinatalari va har bir kuzatuv tegishli bo'lgan klasterlarning yorliqlari kabi natijalarni olishga tayyormiz:

  • >>> cluster_analyzer.cluster_centers_ array([[ 8.33333333, 7.83333333], [-0.16666667, 0.5], [-5. , -5.5 ]]) >>> cluster_analyzer.labels_ array([1, 0, 1, 0, 2, 0, 1], dtype=int32)

E’TIBORINGIZ UCHUN RAHMAT!


Download 1.83 Mb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6




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