Hướng dẫn how do you implement agglomerative clustering in python? - làm thế nào để bạn triển khai phân cụm kết tụ trong python?

Cải thiện bài viết

Show

    Lưu bài viết

    Điều kiện tiên quyết: Phân cụm kết tụ kết tụ là một trong những kỹ thuật phân cụm phân cấp phổ biến nhất. Bộ dữ liệu - Bộ dữ liệu thẻ tín dụng. Giả định: Kỹ thuật phân cụm giả định rằng mỗi điểm dữ liệu đủ tương tự với các điểm dữ liệu khác mà dữ liệu khi bắt đầu có thể được giả định là được phân cụm trong 1 cụm. Bước 1: Nhập các thư viện bắt buộc & NBSP; Agglomerative Clustering Agglomerative Clustering is one of the most common hierarchical clustering techniques. Dataset – Credit Card Dataset. Assumption: The clustering technique assumes that each data point is similar enough to the other data points that the data at the starting can be assumed to be clustered in 1 cluster. Step 1: Importing the required libraries 

    Python3

    import pandas as pd

    import numpy as np

    import matplotlib.pyplot as plt

    from sklearn.decomposition import PCA

    from pandas as pd1import pandas as pd3

    from pandas as pd5import pandas as pd7

    from pandas as pd9import import1

    import import3

    Bước 2: Tải và làm sạch dữ liệu & NBSP; 

    Python3

    import4

    import5import6 import7import8import9

    import5import6 numpy as np2numpy as np3numpy as np4import6 numpy as np6import9

    numpy as np8import6import0import1import6 import3import9

    Bước 3: Tiền xử lý dữ liệu & NBSP; 

    Python3

    import5import6 import7

    import8import6 matplotlib.pyplot as plt0

    matplotlib.pyplot as plt1import6 matplotlib.pyplot as plt3

    matplotlib.pyplot as plt1import6 matplotlib.pyplot as plt6

    Bước 4: Giảm kích thước của dữ liệu & NBSP; 

    Python3

    matplotlib.pyplot as plt7import6 matplotlib.pyplot as plt9import6 from1import9

    from3import6 from5

    from3import6 from8

    from9import6 sklearn.decomposition 1sklearn.decomposition 2sklearn.decomposition 3sklearn.decomposition 4sklearn.decomposition 5

    Dendrogram được sử dụng để chia một cụm nhất định thành nhiều cụm khác nhau. Bước 5: Hình dung hoạt động của dendrogram & nbsp; are used to divide a given cluster into many different clusters. Step 5: Visualizing the working of the Dendrograms 

    Python3

    sklearn.decomposition 6import6sklearn.decomposition 8sklearn.decomposition 9sklearn.decomposition 3sklearn.decomposition 9import2

    import3import4import9

    import6import6 import8import6PCA0__

    Hướng dẫn how do you implement agglomerative clustering in python? - làm thế nào để bạn triển khai phân cụm kết tụ trong python?
    Để xác định số lượng cụm tối ưu bằng cách trực quan hóa dữ liệu, hãy tưởng tượng tất cả các đường ngang là hoàn toàn nằm ngang và sau đó sau khi tính khoảng cách tối đa giữa bất kỳ hai đường ngang nào, hãy vẽ một đường ngang theo khoảng cách tối đa được tính toán. Hình ảnh trên cho thấy số lượng cụm tối ưu phải là 2 cho dữ liệu đã cho. Bước 6: Xây dựng và trực quan hóa các mô hình phân cụm khác nhau cho các giá trị khác nhau của k a) k = 2 & nbsp;
    Hướng dẫn how do you implement agglomerative clustering in python? - làm thế nào để bạn triển khai phân cụm kết tụ trong python?
    The above image shows that the optimal number of clusters should be 2 for the given data. Step 6: Building and Visualizing the different clustering models for different values of k a) k = 2 

    Python3

    PCA2import6 PCA4import6 from1import9

    sklearn.decomposition 6import6sklearn.decomposition 8pandas as pd01sklearn.decomposition 3pandas as pd01import2

    pandas as pd05sklearn.decomposition 2pandas as pd07sklearn.decomposition 4pandas as pd09

    pandas as pd10pandas as pd11import6 pandas as pd13import6pandas as pd15import9

    pandas as pd17

    Hướng dẫn how do you implement agglomerative clustering in python? - làm thế nào để bạn triển khai phân cụm kết tụ trong python?
    b) k = 3 & nbsp;k = 3 

    Python3

    pandas as pd18import6 PCA4import6 pandas as pd222____29

    sklearn.decomposition 6import6sklearn.decomposition 8pandas as pd01sklearn.decomposition 3pandas as pd01import2

    pandas as pd05sklearn.decomposition 2pandas as pd07sklearn.decomposition 4pandas as pd09

    pandas as pd10pandas as pd11import6 pandas as pd39import6pandas as pd15import9

    pandas as pd17

    Hướng dẫn how do you implement agglomerative clustering in python? - làm thế nào để bạn triển khai phân cụm kết tụ trong python?
    c) k = 4 & nbsp;k = 4 

    Python3

    pandas as pd44import6 PCA4import6 pandas as pd48import9

    sklearn.decomposition 6import6sklearn.decomposition 8pandas as pd01sklearn.decomposition 3pandas as pd01import2

    pandas as pd05sklearn.decomposition 2pandas as pd07sklearn.decomposition 4pandas as pd09

    pandas as pd62pandas as pd11import6 pandas as pd65import6pandas as pd15import9

    pandas as pd17

    Hướng dẫn how do you implement agglomerative clustering in python? - làm thế nào để bạn triển khai phân cụm kết tụ trong python?
    d) k = 5 & nbsp;k = 5 

    Python3

    pandas as pd70import6 PCA4import6 pandas as pd74import9

    sklearn.decomposition 6import6sklearn.decomposition 8pandas as pd01sklearn.decomposition 3pandas as pd01import2

    pandas as pd05sklearn.decomposition 2pandas as pd07sklearn.decomposition 4pandas as pd09

    pandas as pd62pandas as pd11import6 pandas as pd91import6pandas as pd15import9

    pandas as pd17

    Hướng dẫn how do you implement agglomerative clustering in python? - làm thế nào để bạn triển khai phân cụm kết tụ trong python?
    e) k = 6 & nbsp;k = 6 

    Python3

    pandas as pd96import6 PCA4import6 pandas as pd01import9

    sklearn.decomposition 6import6sklearn.decomposition 8pandas as pd01sklearn.decomposition 3pandas as pd01import2

    pandas as pd05sklearn.decomposition 2pandas as pd07sklearn.decomposition 4pandas as pd09

    pandas as pd62pandas as pd11import6 import17import6pandas as pd15import9

    pandas as pd17

    Hướng dẫn how do you implement agglomerative clustering in python? - làm thế nào để bạn triển khai phân cụm kết tụ trong python?
    Bây giờ chúng tôi xác định số lượng cụm tối ưu bằng kỹ thuật toán học. Ở đây, chúng tôi sẽ sử dụng điểm số bóng cho mục đích này. Bước 7: Đánh giá các mô hình khác nhau và trực quan hóa kết quả. & NBSP;Silhouette Scores for the purpose. Step 7: Evaluating the different models and Visualizing the results. 

    Python3

    import222import6 sklearn.decomposition 1from1sklearn.decomposition 3pandas as pd22222

    import35import6 import37

    import38

    import39import40

    import38

    import39import43

    import38

    import39import46

    import38

    import39import49

    import38

    import39import52

    import53

    import54import55import56import6 import58import9

    import60import61import56import6 import58import9

    pandas as pd17

    Hướng dẫn how do you implement agglomerative clustering in python? - làm thế nào để bạn triển khai phân cụm kết tụ trong python?
    Do đó, với sự trợ giúp của điểm số bóng, người ta đã kết luận rằng số lượng cụm tối ưu cho dữ liệu đã cho và kỹ thuật phân cụm là 2.