Skip to content

Commit

Permalink
Update plotData input again
Browse files Browse the repository at this point in the history
  • Loading branch information
jtlowery committed Mar 10, 2017
1 parent 60615de commit 629f727
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 4 additions & 6 deletions ex1/ex1.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,19 @@
# ======================= Part 2: Plotting =======================
data = np.loadtxt('ex1data1.txt', delimiter=',')
m = data.shape[0]
X = np.vstack(zip(np.ones(m), data[:, 0]))
y = data[:, 1]
X = data[:, 0]

# Plot Data
# Note: You have to complete the code in plotData.py
print('Plotting Data ...')
plotData(X, y)
plotData(x=data[:, 0], y=data[:, 1])
show()

input('Program paused. Press Enter to continue...')

# =================== Part 3: Gradient descent ===================
print('Running Gradient Descent ...')
# Add a column of ones to x
X = np.vstack(zip(np.ones(m), X))
theta = np.zeros(2)

# compute and display initial cost
Expand All @@ -80,7 +78,7 @@

# Plot the linear fit
plt.figure()
plotData(data)
plotData(x=data[:, 0], y=data[:, 1])
plt.plot(X[:, 1], X.dot(theta), '-', label='Linear regression')
plt.legend(loc='upper right', shadow=True, fontsize='x-large', numpoints=1)
show()
Expand Down Expand Up @@ -153,7 +151,7 @@
print('For population = 70,000, we predict a profit of {:.4f}'.format(predict2 * 10000))

plt.figure()
plotData(data)
plotData(x=data[:, 0], y=data[:, 1])
plt.plot(X[:, 1], X.dot(regr.coef_), '-', color='black', label='Linear regression wit scikit')
plt.legend(loc='upper right', shadow=True, fontsize='x-large', numpoints=1)
show()
Expand Down
2 changes: 1 addition & 1 deletion ex1/plotData.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import numpy as np


def plotData(X, y):
def plotData(x, y):
"""
plots the data points and gives the figure axes labels of
population and profit.
Expand Down

0 comments on commit 629f727

Please sign in to comment.