def main(cluster_num):
    print "Basic global clustering"
    print "Iterations: " + str(iterations)
    print "Clusters: " + str(cluster_num)
    start = time.time()
    # Performing Global Histogram-Based Color Image Clustering
    globalHistogramKMeans = GlobalHistogramKMeans(cluster_num, 'k-means++', 10, 300, 1e-4, 0)
    predicted_labels = globalHistogramKMeans.fit_predict(histograms)
    end = time.time()
    print "Time: " + str(end - start)

    # Adequate to sklearn's inertia_
    print "Sum distances: %s" % globalHistogramKMeans.sum_distances_

    true_labels = dataset.get_true_labels()

    # Evaluation
    purity = Evaluator.calculate_purity(true_labels, predicted_labels)
    precision, recall = Evaluator.calculate_precision_recall(true_labels, predicted_labels)
    ri = Evaluator.calculate_ri(true_labels, predicted_labels)

    # Show results
    print "Purity: %s" % purity
    print "Precision: %s" % precision
    print "Recall: %s" % recall
    print "Random index value: %s" % ri

    dataset.write_results(os.path.join("results_global/", str(cluster_num), "no-pca"), predicted_labels)

    print "PCA global clustering"
    print "Dimensions left " + str(dimensions_left)
    print "Iterations: " + str(iterations)
    print "Clusters: " + str(cluster_num)


    start = time.time()
    # Changing dimensions from 768 to selected value.
    pca = Pca(dimensions_left)
    reduced_histograms = pca.fit_transform(histograms)

    # Clustering and predicting
    predicted_labels = globalHistogramKMeans.fit_predict(reduced_histograms)
    end = time.time()
    print "Time: " + str(end - start)

    # Adequate to sklearn's inertia_
    print "Sum distances: %s" % globalHistogramKMeans.sum_distances_

    # Evaluation
    purity = Evaluator.calculate_purity(true_labels, predicted_labels)
    precision, recall = Evaluator.calculate_precision_recall(true_labels, predicted_labels)
    ri = Evaluator.calculate_ri(true_labels, predicted_labels)

    # Show results
    print "Purity: %s" % purity
    print "Precision: %s" % precision
    print "Recall: %s" % recall
    print "Random index value: %s" % ri
    dataset.write_results(os.path.join("results_global/", str(cluster_num), "pca"), predicted_labels)
Example #2
0
def main(cluster_num):
    print "Local clustering"
    print "Iterations: " + str(iterations)
    print "Clusters: " + str(cluster_num)
    start = time.time()
    # Performing Local Histogram-Based Color Image Clustering
    localHistogramKMeans = LocalHistogramKMeans(cluster_num, 'k-means++', 10, 300, 1e-4, 0)
    predicted_labels = localHistogramKMeans.fit_predict(part_images)
    end = time.time()
    print "Time: " + str(end - start)

    # Adequate to sklearn's inertia_
    print "Sum similarities: %s" % localHistogramKMeans.sum_similarities_

    true_labels = dataset.get_true_labels()

    # Evaluation
    purity = Evaluator.calculate_purity(true_labels, predicted_labels)
    precision, recall = Evaluator.calculate_precision_recall(true_labels, predicted_labels)
    ri = Evaluator.calculate_ri(true_labels, predicted_labels)

    # Show results
    print "Purity: %s" % purity
    print "Precision: %s" % precision
    print "Recall: %s" % recall
    print "Random index value: %s" % ri

    dataset.write_results(os.path.join("results_local/", str(cluster_num)), predicted_labels)