python_data_scien/algorithmic_thinking2/project3/alg_project3_viz.py
def run_example():
    """
    Load a data table, compute a list of clusters and 
    plot a list of clusters

    Set DESKTOP = True/False to use either matplotlib or simplegui
    """
    #data_table = load_data_table(DATA_3108_URL)
    data_table = load_data_table(DATA_111_URL)
    #data_table = load_data_table(DATA_290_URL)
    
    singleton_list = []
    for line in data_table:
        singleton_list.append(alg_cluster.Cluster(set([line[0]]), line[1], line[2], line[3], line[4]))
        
    #cluster_list = sequential_clustering(singleton_list, 15)   
    #print "Displaying", len(cluster_list), "sequential clusters"

    # cluster_list = alg_project3_solution.hierarchical_clustering(singleton_list, 9)
    # print "Displaying", len(cluster_list), "hierarchical clusters"
    # print "distortion:", compute_distortion(cluster_list, data_table)
    # start = time.clock()
    # cluster_list = alg_project3_solution.hierarchical_clustering(singleton_list, 15)
    # elapsed = (time.clock() - start)
    # print "elapsed:",elapsed
    # print "Displaying", len(cluster_list), "hierarchical clusters"
    # cluster_list = alg_project3_solution.hierarchical_clustering(singleton_list, 16)
    # print "Displaying", len(cluster_list), "hierarchical clusters"
    # print "distortion:", compute_distortion(cluster_list, data_table)

    cluster_list = alg_project3_solution.kmeans_clustering(singleton_list, 9, 5)
    print "Displaying", len(cluster_list), "k-means clusters"
    print "distortion:", compute_distortion(cluster_list, data_table)
    # start = time.clock()
    # cluster_list = alg_project3_solution.kmeans_clustering(singleton_list, 15, 5)  
    # elapsed = (time.clock() - start)
    # print "elapsed:",elapsed
    # print "Displaying", len(cluster_list), "k-means clusters"
    # cluster_list = alg_project3_solution.kmeans_clustering(singleton_list, 16, 5)
    # print "Displaying", len(cluster_list), "k-means clusters"
    # print "distortion:", compute_distortion(cluster_list, data_table)

            
    # draw the clusters using matplotlib or simplegui
    # if DESKTOP:
    #     #alg_clusters_matplotlib.plot_clusters(data_table, cluster_list, False)
    #     alg_clusters_matplotlib.plot_clusters(data_table, cluster_list, True)  #add cluster centers
    # else:
    #     alg_clusters_simplegui.PlotClusters(data_table, cluster_list)   # use toggle in GUI to add cluster centers


    Load a data table, compute a list of clusters and 
    plot a list of clusters

    Set DESKTOP = True/False to use either matplotlib or simplegui
    
Load a data table, compute a list of clusters and
plot a list of clusters

Set DESKTOP = True/False to use either matplotlib or simplegui
Load a data table compute a list of clusters and plot a list of clusters Set DESKTOP = True / False to use either matplotlib or simplegui
def run_example():
    data_table = load_data_table(DATA_111_URL)
    singleton_list = []
    for line in data_table:
        singleton_list.append(alg_cluster.Cluster(set([line[0]]), line[1], line[2], line[3], line[4]))
    cluster_list = alg_project3_solution.kmeans_clustering(singleton_list, 9, 5)
    print "Displaying", len(cluster_list), "k-means clusters"
    print "distortion:", compute_distortion(cluster_list, data_table)
def run_example ( ) : data_table = load_data_table ( DATA_111_URL ) singleton_list = [ ] for line in data_table : singleton_list . append ( alg_cluster . Cluster ( set ( [ line [ 0 ] ] ) , line [ 1 ] , line [ 2 ] , line [ 3 ] , line [ 4 ] ) ) cluster_list = alg_project3_solution . kmeans_clustering ( singleton_list , 9 , 5 ) print "Displaying" , len ( cluster_list ) , "k-means clusters" print "distortion:" , compute_distortion ( cluster_list , data_table )
Load a data table, compute a list of clusters and
plot a list of clusters
Load a data table compute a list of clusters and plot a list of clusters
"""
    Load a data table, compute a list of clusters and 
    plot a list of clusters

    Set DESKTOP = True/False to use either matplotlib or simplegui
    """ #data_table = load_data_table(DATA_3108_URL)
 #data_table = load_data_table(DATA_290_URL)
 #cluster_list = sequential_clustering(singleton_list, 15)   
 #print "Displaying", len(cluster_list), "sequential clusters"
 # cluster_list = alg_project3_solution.hierarchical_clustering(singleton_list, 9)
 # print "Displaying", len(cluster_list), "hierarchical clusters"
 # print "distortion:", compute_distortion(cluster_list, data_table)
 # start = time.clock()
 # cluster_list = alg_project3_solution.hierarchical_clustering(singleton_list, 15)
 # elapsed = (time.clock() - start)
 # print "elapsed:",elapsed
 # print "Displaying", len(cluster_list), "hierarchical clusters"
 # cluster_list = alg_project3_solution.hierarchical_clustering(singleton_list, 16)
 # print "Displaying", len(cluster_list), "hierarchical clusters"
 # print "distortion:", compute_distortion(cluster_list, data_table)
 # start = time.clock()
 # cluster_list = alg_project3_solution.kmeans_clustering(singleton_list, 15, 5)  
 # elapsed = (time.clock() - start)
 # print "elapsed:",elapsed
 # print "Displaying", len(cluster_list), "k-means clusters"
 # cluster_list = alg_project3_solution.kmeans_clustering(singleton_list, 16, 5)
 # print "Displaying", len(cluster_list), "k-means clusters"
 # print "distortion:", compute_distortion(cluster_list, data_table)
 # draw the clusters using matplotlib or simplegui
 # if DESKTOP:
 #     #alg_clusters_matplotlib.plot_clusters(data_table, cluster_list, False)
 #     alg_clusters_matplotlib.plot_clusters(data_table, cluster_list, True)  #add cluster centers
 # else:
 #     alg_clusters_simplegui.PlotClusters(data_table, cluster_list)   # use toggle in GUI to add cluster centers
