Esempio n. 1
0
def plot_cluster(data, mu, colors, ax):
    """
    plot the cluster.

    Note that the dimension of the column vector `colors`
    should be the same as the number of clusters.
    """
    # build distance matrix.
    distance_matrix = build_distance_matrix(data, mu)
    # get the assignments for each point.
    assignments = np.argmin(distance_matrix, axis=1)
    #
    for k_th in range(mu.shape[0]):
        #rows, cols = np.where(assignments == k_th)
        rows = np.where(assignments == k_th)[0]
        data_of_kth_cluster = data[rows, :]
        ax.scatter(
            data_of_kth_cluster[:, 0],
            data_of_kth_cluster[:, 1],
            # works for clusters more than 3
            s=40,
            c=colors[k_th % len(colors)])
    ax.grid()
    ax.set_xlabel("x")
    ax.set_ylabel("y")
Esempio n. 2
0
def plot_cluster(data, mu, colors, ax):
    """plot the cluster.

    Note that the dimension of the column vector `colors`
    should be the same as the number of clusters.
    """
    # check if the dimension matches.
    assert(len(colors) >= mu.shape[0])
    # build distance matrix.
    distance_matrix = build_distance_matrix(data, mu)
    # get the assignments for each point.
    assignments = np.argmin(distance_matrix, axis=1)
    #
    for k_th in range(mu.shape[0]):
        rows, cols = np.where(assignments == k_th)
        data_of_kth_cluster = data[rows, :]
        ax.scatter(
            data_of_kth_cluster[:, 0],
            data_of_kth_cluster[:, 1],
            s=40, c=colors[k_th])
    ax.grid()
    ax.set_xlabel("x")
    ax.set_ylabel("y")
Esempio n. 3
0
File: plots.py Progetto: floepfl/ML
def plot_cluster(data, mu, colors, ax):
    """plot the cluster.

    Note that the dimension of the column vector `colors`
    should be the same as the number of clusters.
    """
    # check if the dimension matches.
    #assert(len(colors) >= mu.shape[0])
    # build distance matrix.
    distance_matrix = build_distance_matrix(data, mu)
    # get the assignments for each point.
    assignments = np.argmin(distance_matrix, axis=1)
    #
    for k_th in range(mu.shape[0]):
        rows = np.where(assignments == k_th)
        data_of_kth_cluster = data[rows, :]
        ax.scatter(
            np.squeeze(data_of_kth_cluster)[:, 0],
            np.squeeze(data_of_kth_cluster)[:, 1],
            s=40, c=colors[k_th % len(colors)])

    ax.grid()
    ax.set_xlabel("x")
    ax.set_ylabel("y")