def main(): X = get_simple_data() costs = np.empty(10) costs[0] = None for k in range(1, 10): c = plot_k_means(X, k) costs[k] = c plt.plot(costs) plt.title('cost vs K') plt.show()
def main(): X = create_sample_data() plt.scatter(X[:, 0], X[:, 1]) plt.show() costs = np.empty(10) costs[0] = None for k in range(1, 10): M, R = plot_k_means(X, k, show_plots=False) costs[k] = cost(X, R, M) plt.plot(costs) plt.title("Cost vs K") plt.show()
def main(): X = get_simple_data() plt.scatter(X[:,0], X[:,1]) plt.show() costs = np.empty(10) costs[0] = None for k in range(1, 10): M, R = plot_k_means(X, k, show_plots=False) c = cost(X, R, M) costs[k] = c plt.plot(costs) plt.title("Cost vs K") plt.show()
def main(): X, Y = get_data(1000) # simple data # X = get_simple_data() # Y = np.array([0]*300 + [1]*300 + [2]*300) print("Number of data points:", len(Y)) # Note: I modified plot_k_means from the original # lecture to return means and responsibilities # print "performing k-means..." # t0 = datetime.now() M, R = plot_k_means(X, len(set(Y))) # print "k-means elapsed time:", (datetime.now() - t0) # Exercise: Try different values of K and compare the evaluation metrics print("Purity:", purity(Y, R)) print("DBI:", DBI(X, M, R))
def main(): X, Y = get_data(1000) # simple data # X = get_simple_data() # Y = np.array([0]*300 + [1]*300 + [2]*300) print "Number of data points:", len(Y) # Note: I modified plot_k_means from the original # lecture to return means and responsibilities # print "performing k-means..." # t0 = datetime.now() M, R = plot_k_means(X, len(set(Y))) # print "k-means elapsed time:", (datetime.now() - t0) # Exercise: Try different values of K and compare the evaluation metrics print "Purity:", purity(Y, R) print "DBI:", DBI(X, M, R)
def main(): X = donut() plot_k_means(X, 2) X = np.zeros((1000, 2)) X[:500, :] = np.random.multivariate_normal([0, 0], [[1, 0], [0, 20]], 500) X[500:, :] = np.random.multivariate_normal([5, 0], [[1, 0], [0, 20]], 500) plot_k_means(X, 2) X = np.zeros((1000, 2)) X[:950, :] = np.array([0, 0]) + np.random.randn(950, 2) X[950:, :] = np.array([3, 0]) + np.random.randn(50, 2) plot_k_means(X, 2)
def main(): X = donut() plot_k_means(X, 2, beta=0.1, show_plots=True) # elongated clusters X = np.zeros((1000, 2)) X[:500, :] = np.random.multivariate_normal([0, 0], [[1, 0], [0, 20]], 500) X[500:, :] = np.random.multivariate_normal([5, 0], [[1, 0], [0, 20]], 500) plot_k_means(X, 2, beta=0.1, show_plots=True) # different density X = np.zeros((1000, 2)) X[:950, :] = np.array([0, 0]) + np.random.randn(950, 2) X[950:, :] = np.array([3, 0]) + np.random.randn(50, 2) plot_k_means(X, 2, show_plots=True)
def main(): X, Y = get_data(1000) # # sample data # X = create_sample_data() # Y = np.array([0]*300 + [1]*300 + [2]*300) print("Number of data points:", len(Y)) M, R = plot_k_means(X, len(set(Y))) print("Purity:", purity(Y, R)) print("Purity 2 (hard clusters):", purity2(Y, R)) print("DBI:", DBI(X, M, R)) print("DBI 2 (hard clusters):", DBI2(X, R)) # plot the mean images # they should look like digits for k in range(len(M)): im = M[k].reshape(28, 28) plt.imshow(im, cmap='gray') plt.show()
def main(): # donut X = donut() plot_k_means(X, 2) # elongated clusters X = np.zeros((1000, 2)) X[:500,:] = np.random.multivariate_normal([0, 0], [[1, 0], [0, 20]], 500) X[500:,:] = np.random.multivariate_normal([5, 0], [[1, 0], [0, 20]], 500) plot_k_means(X, 2) # different density X = np.zeros((1000, 2)) X[:950,:] = np.array([0,0]) + np.random.randn(950, 2) X[950:,:] = np.array([3,0]) + np.random.randn(50, 2) plot_k_means(X, 2)
def main(): # mnist data X, Y = get_data(10000) # simple data # X = get_simple_data() # Y = np.array([0]*300 + [1]*300 + [2]*300) print("Number of data points:", len(Y)) M, R = plot_k_means(X, len(set(Y))) # Exercise: Try different values of K and compare the evaluation metrics print("Purity:", purity(Y, R)) print("Purity 2 (hard clusters):", purity2(Y, R)) print("DBI:", DBI(X, M, R)) print("DBI 2 (hard clusters):", DBI2(X, R)) # plot the mean images # they should look like digits for k in range(len(M)): im = M[k].reshape(28, 28) plt.imshow(im, cmap='gray') plt.show()
def main(): # mnist data X, Y = get_data(10000) # simple data # X = get_simple_data() # Y = np.array([0]*300 + [1]*300 + [2]*300) print "Number of data points:", len(Y) M, R = plot_k_means(X, len(set(Y))) # Exercise: Try different values of K and compare the evaluation metrics print "Purity:", purity(Y, R) print "Purity 2 (hard clusters):", purity2(Y, R) print "DBI:", DBI(X, M, R) print "DBI 2 (hard clusters):", DBI2(X, R) # plot the mean images # they should look like digits for k in xrange(len(M)): im = M[k].reshape(28, 28) plt.imshow(im, cmap='gray') plt.show()
def main(): ## Donut problem X = donut() plot_k_means(X, 2) ## Two class elongated gaussians X = np.zeros((1000, 2)) X[:500, :] = np.random.multivariate_normal([0, 0], [[1, 0], [0, 20]], 500) X[500:, :] = np.random.multivariate_normal([5, 0], [[1, 0], [0, 20]], 500) plot_k_means(X, 2) ## Denisty wise gaussian X = np.zeros((1000, 2)) X[:950, :] = np.array([0, 0]) + np.random.randn(950, 2) X[950:, :] = np.array([3, 0]) + np.random.randn(50, 2) plot_k_means(X, 2)
def main(): X, Y = get_data(10000) # simple data # X = get_simple_data() # Y = np.array([0]*300 + [1]*300 + [2]*300) print "Number of data points:", len(Y) # Note: I modified plot_k_means from the original # lecture to return means and responsibilities # print "performing k-means..." # t0 = datetime.now() M, R = plot_k_means(X, len(set(Y))) # print "k-means elapsed time:", (datetime.now() - t0) # Exercise: Try different values of K and compare the evaluation metrics print "Purity:", purity(Y, R) print "DBI:", DBI(X, M, R) # plot the mean images # they should look like digits for k in xrange(len(M)): im = M[k].reshape(28, 28) plt.imshow(im, cmap='gray') plt.show()
>>>>>>> upstream/master import numpy as np import matplotlib.pyplot as plt from kmeans import plot_k_means, get_simple_data, cost def main(): X = get_simple_data() plt.scatter(X[:,0], X[:,1]) plt.show() costs = np.empty(10) costs[0] = None <<<<<<< HEAD for k in xrange(1, 10): ======= for k in range(1, 10): >>>>>>> upstream/master M, R = plot_k_means(X, k, show_plots=False) c = cost(X, R, M) costs[k] = c plt.plot(costs) plt.title("Cost vs K") plt.show() if __name__ == '__main__': main()
======= # mnist data >>>>>>> upstream/master X, Y = get_data(10000) # simple data # X = get_simple_data() # Y = np.array([0]*300 + [1]*300 + [2]*300) <<<<<<< HEAD print "Number of data points:", len(Y) # Note: I modified plot_k_means from the original # lecture to return means and responsibilities # print "performing k-means..." # t0 = datetime.now() M, R = plot_k_means(X, len(set(Y))) # print "k-means elapsed time:", (datetime.now() - t0) # Exercise: Try different values of K and compare the evaluation metrics print "Purity:", purity(Y, R) print "DBI:", DBI(X, M, R) # plot the mean images # they should look like digits for k in xrange(len(M)): ======= print("Number of data points:", len(Y)) M, R = plot_k_means(X, len(set(Y))) # Exercise: Try different values of K and compare the evaluation metrics print("Purity:", purity(Y, R)) print("Purity 2 (hard clusters):", purity2(Y, R)) print("DBI:", DBI(X, M, R))