Пример #1
0
def compute_confusion_matrix_rand_index_clustering(clustering_algorithm, ys_labels_true, ys_labels_predicted, num_clusters, final_clustering = False):
    
    num_examples = len(ys_labels_true)
    
    confusion_matrix_rand_index_clustering = matrix_array_zeros((2, 2))
    
    num_true_positives = 0
    num_false_positives = 0
    
    num_false_negatives = 0
    num_true_negatives = 0
    
    
    examples_pairs = list( iteration_combinations( range( 0, num_examples ), r = 2 ) )
    
    num_examples_pairs = len(examples_pairs)
    
    
    for example_pair in examples_pairs:
        
        example_pair_first_index = example_pair[0]
        example_pair_second_index = example_pair[1]
        
        # The Example Pair are in the same Group (same True Label)
        if(ys_labels_true[example_pair_first_index] == ys_labels_true[example_pair_second_index]):

            # The Example Pair are in the same Cluster (same Predicted Label)
            if(ys_labels_predicted[example_pair_first_index] == ys_labels_predicted[example_pair_second_index]):    
                num_true_positives = ( num_true_positives + 1 )
            
            # The Example Pair are in different Clusters (different Predicted Labels)
            else:    
                num_false_negatives = ( num_false_negatives + 1 )
        
        # The Example Pair are in different Groups (different True Labels)
        else:
            
            # The Example Pair are in the same Cluster (same Predicted Label)
            if(ys_labels_predicted[example_pair_first_index] == ys_labels_predicted[example_pair_second_index]):    
                num_false_positives = ( num_false_positives + 1 )
            
            # The Example Pair are in different Clusters (different Predicted Labels)
            else:    
                num_true_negatives = ( num_true_negatives + 1 )        
    
    
    confusion_matrix_rand_index_clustering[0][0] = int(num_true_positives)
    confusion_matrix_rand_index_clustering[0][1] = int(num_false_positives)
    
    confusion_matrix_rand_index_clustering[1][0] = int(num_false_negatives)
    confusion_matrix_rand_index_clustering[1][1] = int(num_true_negatives)
        
    
    return confusion_matrix_rand_index_clustering, num_examples_pairs
Пример #2
0
transformed_xs_images_matrix_isomap = isomap.fit_transform(xs_images_matrix)


# Create Data Frames for the 3 Features Extractions (PCA, TSNE and Isomap)
data_frame_transformed_extraction_pca, data_frame_columns_pca, data_frame_transformed_extraction_tsne, data_frame_columns_tsne, data_frame_transformed_extraction_isomap, data_frame_columns_isomap = create_data_frames_extraction(transformed_xs_images_matrix_pca, transformed_xs_images_matrix_tsne, transformed_xs_images_matrix_isomap, ys_labels_true, num_total_images_examples = 563, num_features_components = NUM_FEATURES_COMPONENTS)

# Initialize the Visualization/Plotting Style
intialize_plotting_style('seaborn-dark')

# Generate Analysis' Plots, for several Visualization Plots
generate_data_analysis_plots(data_frame_transformed_extraction_pca, data_frame_columns_pca, data_frame_transformed_extraction_tsne, data_frame_columns_tsne, data_frame_transformed_extraction_isomap, data_frame_columns_isomap, num_components = NUM_FEATURES_COMPONENTS)


# The final Features Extracted, to be used, in the Clustering methods,
# filled initially with zeros (0s)
xs_features = matrix_array_zeros( (num_total_images_examples, ( 3 * NUM_FEATURES_COMPONENTS ) ) )
xs_features = matrix_array_zeros( (num_total_images_examples, ( ( 3 * NUM_FEATURES_COMPONENTS ) + 1 ) ) )

# The final Features Extracted, to be used, in the Clustering methods,
# filled with the fitted and transformed data,
# from the PCA (Principal Component Analysis) Decomposition
xs_features[:, 0 : NUM_FEATURES_COMPONENTS] = transformed_xs_images_matrix_pca

# The final Features Extracted, to be used, in the Clustering methods,
# filled with the fitted and transformed data,
# from the TSNE (T-Distributed Stochastic Neighbor Embedding)
xs_features[:, NUM_FEATURES_COMPONENTS : ( 2 * NUM_FEATURES_COMPONENTS ) ] = transformed_xs_images_matrix_tsne

# The final Features Extracted, to be used, in the Clustering methods,
# filled with the fitted and transformed data,
# from the Isomap (Isometric Mapping)
Пример #3
0
def create_data_frames_extraction(transformed_xs_images_matrix_pca, transformed_xs_images_matrix_tsne, transformed_xs_images_matrix_isomap, ys_labels_true, num_total_images_examples = 563, num_features_components = 6):

    # The Matrix for the Features and Labels, to be used to create the Data Frame,
    # for the PCA (Principal Component Analysis) Features' Extraction method
    transformed_data_images_matrix_pca = matrix_array_zeros( (num_total_images_examples, ( num_features_components + 1 ) ) )

    # Fill the Matrix for the Features and Labels, to be used to create the Data Frame,
    # for the PCA (Principal Component Analysis) Features' Extraction method, with the Features extracted
    transformed_data_images_matrix_pca[:, 0 : -1] = transformed_xs_images_matrix_pca

    # Fill the Matrix for the Features and Labels, to be used to create the Data Frame,
    # for the PCA (Principal Component Analysis) Features' Extraction method, with the associated Labels
    transformed_data_images_matrix_pca[:, -1] = ys_labels_true

    # The Columns, with respect to the Identifiers of the Features and Labels,
    # to be used in the Data Frame, for the PCA (Principal Component Analysis) method
    data_frame_columns_pca = ['PCA - Feature 1', 'PCA - Feature 2', 'PCA - Feature 3',
                              'PCA - Feature 4', 'PCA - Feature 5', 'PCA - Feature 6',
                              'Celular Phase']

    # The Data Frame of the Features Extracted, for the PCA (Principal Component Analysis) method 
    data_frame_extraction_pca = pandas_data_frame(transformed_data_images_matrix_pca, columns = data_frame_columns_pca)   




    # The Matrix for the Features and Labels, to be used to create the Data Frame,
    # for the TSNE (T-Distributed Stochastic Neighbor Embedding) Features' Extraction method
    transformed_data_images_matrix_tsne = matrix_array_zeros( (num_total_images_examples, ( num_features_components + 1 ) ) )

    # Fill the Matrix for the Features and Labels, to be used to create the Data Frame,
    # for the TSNE (T-Distributed Stochastic Neighbor Embedding) Features' Extraction method, with the Features extracted
    transformed_data_images_matrix_tsne[:, 0 : -1] = transformed_xs_images_matrix_tsne

    # Fill the Matrix for the Features and Labels, to be used to create the Data Frame,
    # for the TSNE (T-Distributed Stochastic Neighbor Embedding) Features' Extraction method, with the associated Labels
    transformed_data_images_matrix_tsne[:, -1] = ys_labels_true

    # The Columns, with respect to the Identifiers of the Features and Labels,
    # to be used in the Data Frame, for the TSNE (T-Distributed Stochastic Neighbor Embedding) method
    data_frame_columns_tsne = ['TSNE - Feature 7', 'TSNE - Feature 8', 'TSNE - Feature 9',
                               'TSNE - Feature 10', 'TSNE - Feature 11', 'TSNE - Feature 12',
                               'Celular Phase']    

    # The Data Frame of the Features Extracted, for the TSNE (T-Distributed Stochastic Neighbor Embedding) method 
    data_frame_extraction_tsne = pandas_data_frame(transformed_data_images_matrix_tsne, columns = data_frame_columns_tsne)   




    # The Matrix for the Features and Labels, to be used to create the Data Frame,
    # for the Isomap (Isometric Mapping) Features' Extraction method
    transformed_data_images_matrix_isomap = matrix_array_zeros( (num_total_images_examples, ( num_features_components + 1 ) ) )

    # Fill the Matrix for the Features and Labels, to be used to create the Data Frame,
    # for the Isomap (Isometric Mapping) Features' Extraction method, with the Features extracted
    transformed_data_images_matrix_isomap[:, 0 : -1] = transformed_xs_images_matrix_isomap

    # Fill the Matrix for the Features and Labels, to be used to create the Data Frame,
    # for the Isomap (Isometric Mapping) Features' Extraction method, with the associated Labels
    transformed_data_images_matrix_isomap[:, -1] = ys_labels_true

    # The Columns, with respect to the Identifiers of the Features and Labels,
    # to be used in the Data Frame, for the Isomap (Isometric Mapping) method
    data_frame_columns_isomap = ['Isomap - Feature 13', 'Isomap - Feature 14', 'Isomap - Feature 15',
                                 'Isomap - Feature 16', 'Isomap - Feature 17', 'Isomap - Feature 18',
                                 'Celular Phase']    

    # The Data Frame of the Features Extracted, for the Isomap (Isometric Mapping) method 
    data_frame_extraction_isomap = pandas_data_frame(transformed_data_images_matrix_isomap, columns = data_frame_columns_isomap)   



    return data_frame_extraction_pca, data_frame_columns_pca, data_frame_extraction_tsne, data_frame_columns_tsne, data_frame_extraction_isomap, data_frame_columns_isomap
Пример #4
0
def bisecting_k_means_clustering(xs_features_data,
                                 examples_ids,
                                 ys_labels_true,
                                 final_max_num_clusters_and_iterations=2):

    clusters_ids = [0]

    clusters_data = [xs_features_data]
    clusters_examples_ids = [examples_ids]

    clusters_centroids_points = [0]

    num_clusters = 1

    tree_predictions_lists_with_offset = array_empty(
        (len(xs_features_data), 0)).tolist()
    tree_predictions_lists_without_offset = array_empty(
        (len(xs_features_data), 0)).tolist()

    ys_labels_predicted_with_offset = None
    ys_labels_predicted_without_offset = None

    current_iteration = 0

    while (num_clusters < final_max_num_clusters_and_iterations):

        cluster_index_with_more_examples = -1
        num_max_examples_in_cluster = -1

        for index_cluster in range(num_clusters):

            num_examples_in_cluster = len(clusters_data[index_cluster])

            if (num_examples_in_cluster > num_max_examples_in_cluster):

                cluster_index_with_more_examples = index_cluster
                num_max_examples_in_cluster = num_examples_in_cluster

        cluster_id_to_be_divided = clusters_ids[
            cluster_index_with_more_examples]

        cluster_data_to_be_divided = clusters_data[
            cluster_index_with_more_examples]
        cluster_examples_ids_to_be_divided = clusters_examples_ids[
            cluster_index_with_more_examples]

        cluster_centroid_point_to_be_divided = clusters_centroids_points[
            cluster_index_with_more_examples]

        clusters_data.remove(cluster_data_to_be_divided)
        clusters_examples_ids.remove(cluster_examples_ids_to_be_divided)

        if (num_clusters == 1):

            clusters_ids.pop(cluster_id_to_be_divided)
            clusters_centroids_points.pop(0)

        else:

            cluster_centroid_point_index = 0

            cluster_centroid_point_index_triggered = 0

            for cluster_centroid_point in clusters_centroids_points:

                if ((cluster_centroid_point_to_be_divided ==
                     cluster_centroid_point).all()):

                    cluster_centroid_point_index_triggered = cluster_centroid_point_index

                cluster_centroid_point_index = (cluster_centroid_point_index +
                                                1)

            clusters_centroids_points.pop(
                cluster_centroid_point_index_triggered)

        if (num_clusters == 1):

            two_sub_clusters_ids, two_sub_clusters_examples_ids, two_sub_clusters_data, two_sub_clusters_centroids, ys_labels_predicted_without_offset, ys_labels_predicted_with_offset, cluster_squared_error_sum_intertia = bissect_k_means_into_two_sub_clusters(
                cluster_data_to_be_divided,
                cluster_examples_ids_to_be_divided,
                left_leaf_cluster_id_offset=0,
                right_leaf_cluster_id_offset=0)

        else:

            two_sub_clusters_ids, two_sub_clusters_examples_ids, two_sub_clusters_data, two_sub_clusters_centroids, ys_labels_predicted_without_offset, ys_labels_predicted_with_offset, cluster_squared_error_sum_intertia = bissect_k_means_into_two_sub_clusters(
                cluster_data_to_be_divided,
                cluster_examples_ids_to_be_divided,
                left_leaf_cluster_id_offset=cluster_id_to_be_divided,
                right_leaf_cluster_id_offset=(num_clusters - 1))

        ys_labels_predicted_with_offset_unique = array_sort(
            array_unique_values(ys_labels_predicted_with_offset))

        for sub_cluster_id in range(2):

            clusters_ids.append(two_sub_clusters_ids[sub_cluster_id])

            clusters_data.append(two_sub_clusters_data[sub_cluster_id])
            clusters_examples_ids.append(
                two_sub_clusters_examples_ids[sub_cluster_id])

            clusters_centroids_points.append(
                two_sub_clusters_centroids[sub_cluster_id])

            for example_index in range(len(xs_features_data)):

                if (example_index
                        in two_sub_clusters_examples_ids[sub_cluster_id]):

                    if (sub_cluster_id <
                            len(ys_labels_predicted_with_offset_unique)):

                        tree_predictions_lists_with_offset[
                            example_index].append(
                                ys_labels_predicted_with_offset_unique[
                                    sub_cluster_id])

                    tree_predictions_lists_without_offset[
                        example_index].append(sub_cluster_id)

        num_clusters = (num_clusters + 1)

        current_iteration = (current_iteration + 1)

    ys_final_labels_predicted = matrix_array_zeros(len(xs_features_data))

    for example_index in range(len(xs_features_data)):

        last_index = (len(tree_predictions_lists_with_offset[example_index]) -
                      1)

        ys_final_labels_predicted[
            example_index] = tree_predictions_lists_with_offset[example_index][
                last_index]

    clusters_centroids_points = array_matrix(clusters_centroids_points)

    effective_num_clusters = len(
        array_unique_values(ys_final_labels_predicted))

    if (effective_num_clusters >= 2):

        if (effective_num_clusters <= 26):

            plot_clusters_centroids_and_radii("Bisecting-K-Means",
                                              xs_features_data,
                                              ys_final_labels_predicted,
                                              clusters_centroids_points,
                                              effective_num_clusters,
                                              epsilon=None,
                                              damping=None,
                                              final_clustering=True)

            plot_silhouette_analysis("Bisecting-K-Means",
                                     xs_features_data,
                                     ys_final_labels_predicted,
                                     clusters_centroids_points,
                                     effective_num_clusters,
                                     epsilon=None,
                                     damping=None,
                                     final_clustering=True)

        bisecting_k_means_final_clustering_silhouette_score, bisecting_k_means_final_clustering_precision_score, bisecting_k_means_final_clustering_recall_score, bisecting_k_means_final_clustering_rand_index_score, bisecting_k_means_final_clustering_f1_score, bisecting_k_means_final_clustering_adjusted_rand_score, bisecting_k_means_final_clustering_confusion_matrix_rand_index = compute_clustering_performance_metrics(
            "Bisecting-K-Means",
            xs_features_data,
            ys_labels_true,
            ys_final_labels_predicted,
            effective_num_clusters,
            final_clustering=True)

        plot_confusion_matrix_rand_index_clustering_heatmap(
            "Bisecting-K-Means",
            bisecting_k_means_final_clustering_confusion_matrix_rand_index,
            effective_num_clusters,
            epsilon=None,
            damping=None,
            final_clustering=True)

    xs_ids_examples = list(range(0, len(examples_ids)))

    html_report_cluster_labels_hierarchical(
        xs_ids_examples, tree_predictions_lists_without_offset,
        "bisecting-k-means-hierarchical.html")

    return clusters_ids, clusters_data, ys_final_labels_predicted, tree_predictions_lists_without_offset, num_clusters, effective_num_clusters
Пример #5
0
def k_means_pre_clustering(xs_features_data, ys_labels_true,
                           num_total_clusters):

    clusters_squared_errors_sums_intertias = matrix_array_zeros(
        num_total_clusters)

    clusters_silhouette_scores = matrix_array_zeros((num_total_clusters - 1))
    clusters_precision_scores = matrix_array_zeros((num_total_clusters - 1))
    clusters_recall_scores = matrix_array_zeros((num_total_clusters - 1))
    clusters_rand_index_scores = matrix_array_zeros((num_total_clusters - 1))
    clusters_f1_scores = matrix_array_zeros((num_total_clusters - 1))
    clusters_adjusted_rand_scores = matrix_array_zeros(
        (num_total_clusters - 1))

    for current_num_clusters in range(1, (num_total_clusters + 1)):

        ys_labels_predicted, clusters_centroids, error_k_means_pre_clustering = k_means_clustering_method(
            xs_features_data,
            num_clusters=current_num_clusters,
            max_iterations=300)

        clusters_squared_errors_sums_intertias[(
            current_num_clusters - 1)] = error_k_means_pre_clustering

        plot_clusters_centroids_and_radii("K-Means",
                                          xs_features_data,
                                          ys_labels_predicted,
                                          clusters_centroids,
                                          num_clusters=current_num_clusters,
                                          epsilon=None,
                                          damping=None,
                                          final_clustering=False)

        if (current_num_clusters >= 2):

            if (current_num_clusters <= 26):

                plot_silhouette_analysis("K-Means",
                                         xs_features_data,
                                         ys_labels_predicted,
                                         clusters_centroids,
                                         current_num_clusters,
                                         epsilon=None,
                                         damping=None,
                                         final_clustering=False)

            silhouette_score, precision_score, recall_score, rand_index_score, f1_score, adjusted_rand_score, confusion_matrix_rand_index_clustering = compute_clustering_performance_metrics(
                "K-Means",
                xs_features_data,
                ys_labels_true,
                ys_labels_predicted,
                current_num_clusters,
                final_clustering=False)

            plot_confusion_matrix_rand_index_clustering_heatmap(
                "K-Means",
                confusion_matrix_rand_index_clustering,
                current_num_clusters,
                epsilon=None,
                damping=None,
                final_clustering=False)

            clusters_silhouette_scores[(current_num_clusters -
                                        2)] = silhouette_score
            clusters_precision_scores[(current_num_clusters -
                                       2)] = precision_score
            clusters_recall_scores[(current_num_clusters - 2)] = recall_score
            clusters_rand_index_scores[(current_num_clusters -
                                        2)] = rand_index_score
            clusters_f1_scores[(current_num_clusters - 2)] = f1_score
            clusters_adjusted_rand_scores[(current_num_clusters -
                                           2)] = adjusted_rand_score

    print_k_means_clustering_performance_metrics(
        "K-Means", num_total_clusters, clusters_squared_errors_sums_intertias,
        clusters_silhouette_scores, clusters_precision_scores,
        clusters_recall_scores, clusters_rand_index_scores, clusters_f1_scores,
        clusters_adjusted_rand_scores)

    plot_clustering_scores("K-Means", num_total_clusters, None, None, None,
                           None, None, None, None, None,
                           clusters_silhouette_scores,
                           clusters_precision_scores, clusters_recall_scores,
                           clusters_rand_index_scores, clusters_f1_scores,
                           clusters_adjusted_rand_scores)

    return clusters_squared_errors_sums_intertias, clusters_silhouette_scores, clusters_precision_scores, clusters_recall_scores, clusters_rand_index_scores, clusters_f1_scores, clusters_adjusted_rand_scores
Пример #6
0
def dbscan_pre_clustering(xs_features_data, ys_labels_true, num_closest_k_neighbors = 5, start_epsilon = 0.01, end_epsilon = 0.28, step_epsilon = 0.01):
    
    current_epsilon_step = 0
    
    num_epsilons_steps = int( ( end_epsilon - start_epsilon ) / step_epsilon )
    
    clusters_epsilon_values = matrix_array_zeros( num_epsilons_steps )
    clusters_num_centroids = matrix_array_zeros( num_epsilons_steps )
    
    clusters_num_inliers = matrix_array_zeros( num_epsilons_steps )
    clusters_num_outliers = matrix_array_zeros( num_epsilons_steps )
    
    clusters_silhouette_scores = matrix_array_zeros( num_epsilons_steps )
    clusters_precision_scores = matrix_array_zeros( num_epsilons_steps )
    clusters_recall_scores = matrix_array_zeros( num_epsilons_steps )
    clusters_rand_index_scores = matrix_array_zeros( num_epsilons_steps )
    clusters_f1_scores = matrix_array_zeros( num_epsilons_steps )
    clusters_adjusted_rand_scores = matrix_array_zeros( num_epsilons_steps )
    
    
    for current_epsilon in a_range(start_epsilon, end_epsilon, step_epsilon):
       
        ys_labels_predicted, clusters_centroids_indices, clusters_centroids_points, clusters_border_points, xs_features_data_inliers, xs_features_data_outliers = dbscan_clustering_method(xs_features_data, current_epsilon, num_closest_k_neighbors = num_closest_k_neighbors)

        num_clusters_centroids = ( nan_max(ys_labels_predicted) + 1 )
        
        plot_clusters_centroids_and_radii("DBSCAN", xs_features_data, ys_labels_predicted, clusters_centroids_points, num_clusters = num_clusters_centroids, epsilon = current_epsilon, damping = None, final_clustering = False)
        
        clusters_epsilon_values[current_epsilon_step] = current_epsilon        
        clusters_num_centroids[current_epsilon_step] = num_clusters_centroids
        
        clusters_num_inliers[current_epsilon_step] = len(xs_features_data_inliers)
        clusters_num_outliers[current_epsilon_step] = len(xs_features_data_outliers)
        
        
        if( num_clusters_centroids >= 2 ):
            
            if( num_clusters_centroids <= 26 ):
            
                plot_silhouette_analysis("DBSCAN", xs_features_data, ys_labels_predicted, clusters_centroids_points, num_clusters_centroids, epsilon = current_epsilon, damping = None, final_clustering = False)
        
            
            silhouette_score, precision_score, recall_score, rand_index_score, f1_score, adjusted_rand_score, confusion_matrix_rand_index_clustering = compute_clustering_performance_metrics("K-Means", xs_features_data, ys_labels_true, ys_labels_predicted, num_clusters_centroids, final_clustering = False)
            
            plot_confusion_matrix_rand_index_clustering_heatmap("DBSCAN", confusion_matrix_rand_index_clustering, num_clusters_centroids, epsilon = current_epsilon, damping = None, final_clustering = False)
            
            clusters_silhouette_scores[current_epsilon_step] = silhouette_score
            clusters_precision_scores[current_epsilon_step] = precision_score
            clusters_recall_scores[current_epsilon_step] = recall_score
            clusters_rand_index_scores[current_epsilon_step] = rand_index_score
            clusters_f1_scores[current_epsilon_step] = f1_score
            clusters_adjusted_rand_scores[current_epsilon_step] = adjusted_rand_score
            
            
        current_epsilon_step = ( current_epsilon_step + 1 )
    
    
    print_dbscan_clustering_performance_metrics("DBSCAN", start_epsilon, end_epsilon, step_epsilon, clusters_num_centroids, clusters_num_inliers, clusters_num_outliers, clusters_silhouette_scores, clusters_precision_scores, clusters_recall_scores, clusters_rand_index_scores, clusters_f1_scores, clusters_adjusted_rand_scores)
        
    plot_clustering_scores("DBSCAN", num_clusters_centroids, start_epsilon, end_epsilon, step_epsilon, clusters_epsilon_values, None, None, None, None, clusters_silhouette_scores, clusters_precision_scores, clusters_recall_scores, clusters_rand_index_scores, clusters_f1_scores, clusters_adjusted_rand_scores)
    
    
    return clusters_num_centroids, clusters_num_inliers, clusters_num_outliers, clusters_silhouette_scores, clusters_precision_scores, clusters_recall_scores, clusters_rand_index_scores, clusters_f1_scores, clusters_adjusted_rand_scores
Пример #7
0
def affinity_propagation_pre_clustering(xs_features_data, ys_labels_true, start_damping = 0.5, end_damping = 1.0, step_damping = 0.01):
    
    current_damping_step = 0
    
    some_damping = 0
    some_damping_flag = False
    
    num_damping_steps = int( ( end_damping - start_damping ) / step_damping )
    
    clusters_damping_values = matrix_array_zeros( num_damping_steps )
    clusters_num_centroids = matrix_array_zeros( num_damping_steps )
    
    clusters_silhouette_scores = matrix_array_zeros( num_damping_steps )
    clusters_precision_scores = matrix_array_zeros( num_damping_steps )
    clusters_recall_scores = matrix_array_zeros( num_damping_steps )
    clusters_rand_index_scores = matrix_array_zeros( num_damping_steps )
    clusters_f1_scores = matrix_array_zeros( num_damping_steps )
    clusters_adjusted_rand_scores = matrix_array_zeros( num_damping_steps )
    
    
    for current_damping in a_range(start_damping, end_damping, step_damping):
        
        ys_labels_predicted, clusters_centroids_indices, clusters_centroids_points = affinity_propagation_clustering_method(xs_features_data, damping_value = current_damping, max_iterations = 300)
        
        num_clusters_centroids = ( nan_max(ys_labels_predicted) + 1 )

        
        clusters_damping_values[current_damping_step] = current_damping        
        clusters_num_centroids[current_damping_step] = num_clusters_centroids        
        
        
        if( num_clusters_centroids >= 2 ):
            
            if( num_clusters_centroids <= 26 ):
                
                plot_clusters_centroids_and_radii("Affinity-Propagation", xs_features_data, ys_labels_predicted, clusters_centroids_points, num_clusters = num_clusters_centroids, epsilon = None, damping = current_damping, final_clustering = False)

                plot_silhouette_analysis("Affinity-Propagation", xs_features_data, ys_labels_predicted, clusters_centroids_points, num_clusters_centroids, epsilon = None, damping = current_damping, final_clustering = False)
            
            
                if(not some_damping_flag):
                    
                    some_damping = current_damping
                    some_damping_flag = True
            
            
            silhouette_score, precision_score, recall_score, rand_index_score, f1_score, adjusted_rand_score, confusion_matrix_rand_index_clustering = compute_clustering_performance_metrics("Affinity-Propagation", xs_features_data, ys_labels_true, ys_labels_predicted, num_clusters_centroids, final_clustering = False)
            
            plot_confusion_matrix_rand_index_clustering_heatmap("Affinity-Propagation", confusion_matrix_rand_index_clustering, num_clusters_centroids, epsilon = None, damping = current_damping, final_clustering = False)
                          
            clusters_silhouette_scores[current_damping_step] = silhouette_score
            clusters_precision_scores[current_damping_step] = precision_score
            clusters_recall_scores[current_damping_step] = recall_score
            clusters_rand_index_scores[current_damping_step] = rand_index_score
            clusters_f1_scores[current_damping_step] = f1_score
            clusters_adjusted_rand_scores[current_damping_step] = adjusted_rand_score
            
            
        current_damping_step = ( current_damping_step + 1 )
    
    print_affinity_propagation_clustering_performance_metrics("Affinity-Propagation", start_damping, end_damping, step_damping, clusters_num_centroids, clusters_silhouette_scores, clusters_precision_scores, clusters_recall_scores, clusters_rand_index_scores, clusters_f1_scores, clusters_adjusted_rand_scores)
    
    plot_clustering_scores("Affinity-Propagation", num_clusters_centroids, None, None, None, None, start_damping, end_damping, step_damping, clusters_damping_values, clusters_silhouette_scores, clusters_precision_scores, clusters_recall_scores, clusters_rand_index_scores, clusters_f1_scores, clusters_adjusted_rand_scores)
    
    
    return clusters_num_centroids, clusters_silhouette_scores, clusters_precision_scores, clusters_recall_scores, clusters_rand_index_scores, clusters_f1_scores, clusters_adjusted_rand_scores, some_damping