From ad61e9c6ad042982b30803117bd948cbfb35b54f Mon Sep 17 00:00:00 2001 From: Joel Lowery Date: Sun, 7 May 2017 22:46:24 -0500 Subject: [PATCH] Numerous ex8 fixes - Formatting - More consistent display of plots --- ex8/estimateGaussian.py | 1 - ex8/ex8.py | 6 +++++- ex8/ex8_cofi.py | 3 ++- ex8/visualizeFit.py | 1 - 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/ex8/estimateGaussian.py b/ex8/estimateGaussian.py index 9630620..6b7b31d 100644 --- a/ex8/estimateGaussian.py +++ b/ex8/estimateGaussian.py @@ -17,7 +17,6 @@ def estimateGaussian(X): # In particular, mu(i) should contain the mean of # the data for the i-th feature and sigma2(i) # should contain variance of the i-th feature. - # # ============================================================= return mu, sigma2 diff --git a/ex8/ex8.py b/ex8/ex8.py index f702d2a..62936c3 100644 --- a/ex8/ex8.py +++ b/ex8/ex8.py @@ -52,7 +52,6 @@ show() input('Program paused. Press Enter to continue...') - # ================== Part 2: Estimate the dataset statistics =================== # For this exercise, we assume a Gaussian distribution for the dataset. # @@ -71,6 +70,7 @@ p = multivariateGaussian(X, mu, sigma2) # Visualize the fit +plt.figure() visualizeFit(X, mu, sigma2) plt.xlabel('Latency (ms)') plt.ylabel('Throughput (mb/s)') @@ -93,6 +93,10 @@ outliers = np.where(p < epsilon, True, False) # Draw a red circle around those outliers +plt.figure() +visualizeFit(X, mu, sigma2) +plt.xlabel('Latency (ms)') +plt.ylabel('Throughput (mb/s)') plt.plot(X[outliers, 0], X[outliers, 1], 'ro', lw=2, markersize=10, fillstyle='none', markeredgewidth=1) show() diff --git a/ex8/ex8_cofi.py b/ex8/ex8_cofi.py index 4359fab..53b31f7 100644 --- a/ex8/ex8_cofi.py +++ b/ex8/ex8_cofi.py @@ -49,7 +49,8 @@ # We can "visualize" the ratings matrix by plotting it with imagesc plt.figure() -plt.imshow(Y, aspect='equal', origin='upper', extent=(0, Y.shape[1], 0, Y.shape[0]/2.0)) +plt.imshow(Y, aspect='equal', origin='upper', + extent=(0, Y.shape[1], 0, Y.shape[0]/2.0)) plt.ylabel('Movies') plt.xlabel('Users') show() diff --git a/ex8/visualizeFit.py b/ex8/visualizeFit.py index 3a9bd1f..766a434 100644 --- a/ex8/visualizeFit.py +++ b/ex8/visualizeFit.py @@ -22,4 +22,3 @@ def visualizeFit(X, mu, sigma2): # Do not plot if there are infinities if not isinf(np.sum(Z)): plt.contour(X1[0], X1[1], Z, 10.0 ** np.arange(-20, 0, 3).T) - show()