예제 #1
0
def save_graphclust_h5(f, labels):
    clustering_key = cr_clustering.format_clustering_key(
        cr_clustering.CLUSTER_TYPE_GRAPHCLUST, 0)

    clustering = cr_clustering.create_clustering(
        clusters=labels,
        num_clusters=max(labels),
        cluster_score=0,
        clustering_type=cr_clustering.CLUSTER_TYPE_GRAPHCLUST,
        global_sort_key=float('-inf'),  # always first
        description=cr_clustering.humanify_clustering_key(clustering_key))

    group = f.create_group(f.root, cr_constants.ANALYSIS_H5_CLUSTERING_GROUP)
    cr_io.save_h5(f, group, clustering_key, clustering)
예제 #2
0
def run_kmedoids(transformed_matrix, n_clusters, random_state=None, metric='euclidean'):
    if random_state is None:
        random_state=analysis_constants.RANDOM_STATE

    kmedoids = KMedoids(n_clusters=n_clusters, random_state=random_state, metric=metric)
    clusters = kmedoids.fit_predict(transformed_matrix) + 1

    cluster_score = compute_silhouette_index(transformed_matrix, kmedoids, metric)

    clusters = cr_clustering.relabel_by_size(clusters)

    clustering_key = cr_clustering.format_clustering_key(cr_clustering.CLUSTER_TYPE_KMEDOIDS, n_clusters)

    return cr_clustering.create_clustering(clusters=clusters,
                                           num_clusters=n_clusters,
                                           cluster_score=cluster_score,
                                           clustering_type=cr_clustering.CLUSTER_TYPE_KMEDOIDS,
                                           global_sort_key=n_clusters,
                                           description=cr_clustering.humanify_clustering_key(clustering_key))
예제 #3
0
def run_kmeans(transformed_pca_matrix, n_clusters, random_state=None):
    if random_state is None:
        random_state=cr_constants.RANDOM_STATE

    kmeans = sk_cluster.KMeans(n_clusters=n_clusters, random_state=random_state)
    clusters = kmeans.fit_predict(transformed_pca_matrix) + 1

    cluster_score = compute_db_index(transformed_pca_matrix, kmeans)

    clusters = cr_clustering.relabel_by_size(clusters)

    clustering_key = cr_clustering.format_clustering_key(cr_clustering.CLUSTER_TYPE_KMEANS, n_clusters)

    return cr_clustering.create_clustering(clusters=clusters,
                                           num_clusters=n_clusters,
                                           cluster_score=cluster_score,
                                           clustering_type=cr_clustering.CLUSTER_TYPE_KMEANS,
                                           global_sort_key=n_clusters,
                                           description=cr_clustering.humanify_clustering_key(clustering_key))