algorithms/k-means/utilities.py
def display_points_cluster(clusters, centers, dimension):
    """
    Display the cluster using a different color for each cluster. Only 2D and 3D representation are supported.
    :param clusters: List of clusters.
    :param centers: List of centers.
    :param dimension: dimension of the points (2 or 3)
    :return: None
    """
    if dimension == 2:
        for cluster in clusters:
            if cluster != []:
                points = list(zip(*cluster))
                plt.scatter(points[0], points[1], s=10)

        for center in centers:
            plt.scatter(*center, marker='*', s=200, color='black')
        plt.show()

    elif dimension == 3:
        fig = plt.figure()
        ax = Axes3D(fig)

        for cluster in clusters:
            if cluster != []:
                points = list(zip(*cluster))
                ax.scatter(points[0], points[1], points[2], s=10)
        plt.show()

    else:
        raise Exception("Wrong dimension")

    Display the cluster using a different color for each cluster. Only 2D and 3D representation are supported.
    :param clusters: List of clusters.
    :param centers: List of centers.
    :param dimension: dimension of the points (2 or 3)
    :return: None
    
Display the cluster using a different color for each cluster. Only 2D and 3D representation are supported.
Display the cluster using a different color for each cluster . Only 2D and 3D representation are supported .
def display_points_cluster(clusters, centers, dimension):
    if dimension == 2:
        for cluster in clusters:
            if cluster != []:
                points = list(zip(*cluster))
                plt.scatter(points[0], points[1], s=10)
        for center in centers:
            plt.scatter(*center, marker='*', s=200, color='black')
        plt.show()
    elif dimension == 3:
        fig = plt.figure()
        ax = Axes3D(fig)
        for cluster in clusters:
            if cluster != []:
                points = list(zip(*cluster))
                ax.scatter(points[0], points[1], points[2], s=10)
        plt.show()
    else:
        raise Exception("Wrong dimension")
def display_points_cluster ( clusters , centers , dimension ) : if dimension == 2 : for cluster in clusters : if cluster != [ ] : points = list ( zip ( * cluster ) ) plt . scatter ( points [ 0 ] , points [ 1 ] , s = 10 ) for center in centers : plt . scatter ( * center , marker = '*' , s = 200 , color = 'black' ) plt . show ( ) elif dimension == 3 : fig = plt . figure ( ) ax = Axes3D ( fig ) for cluster in clusters : if cluster != [ ] : points = list ( zip ( * cluster ) ) ax . scatter ( points [ 0 ] , points [ 1 ] , points [ 2 ] , s = 10 ) plt . show ( ) else : raise Exception ( "Wrong dimension" )
Display the cluster using a different color for each cluster.
Display the cluster using a different color for each cluster .
"""
    Display the cluster using a different color for each cluster. Only 2D and 3D representation are supported.
    :param clusters: List of clusters.
    :param centers: List of centers.
    :param dimension: dimension of the points (2 or 3)
    :return: None
    """
None
clusters
List of clusters.
List of clusters .
centers
List of centers.
List of centers .
dimension
dimension of the points (2 or 3)
dimension of the points ( 2 or 3 )