Skip to content

Commit

Permalink
Altered X, y format to be consistent with prev part
Browse files Browse the repository at this point in the history
  • Loading branch information
jtlowery committed Mar 14, 2017
1 parent 44aa371 commit d455d55
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions ex2/ex2_reg.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
def optimize(Lambda):

result = minimize(costFunctionReg, initial_theta, method='L-BFGS-B',
jac=gradientFunctionReg, args=(X.as_matrix(), y, Lambda),
jac=gradientFunctionReg, args=(X, y, Lambda),
options={'gtol': 1e-4, 'disp': False, 'maxiter': 1000})

return result


# Plot Boundary
def plotBoundary(theta, X, y):
plotDecisionBoundary(theta, X.values, y.values)
plotDecisionBoundary(theta, X, y)
plt.title(r'$\lambda$ = ' + str(Lambda))

# Labels and Legend
Expand All @@ -41,11 +41,12 @@ def plotBoundary(theta, X, y):
# The first two columns contains the X values and the third column
# contains the label (y).

data = pd.read_csv('ex2data2.txt', header=None, names=[1, 2, 3])
X = data[[1, 2]]
y = data[[3]]
# data = pd.read_csv('ex2data2.txt', header=None, names=[1, 2, 3])
data = np.loadtxt('ex2data2.txt', delimiter=',')
X = data[:, 0:2]
y = data[:, 2]

plotData(X.values, y.values)
plotData(X, y)

# Labels and Legend
plt.xlabel('Microchip Test 1')
Expand All @@ -60,7 +61,10 @@ def plotBoundary(theta, X, y):

# Note that mapFeature also adds a column of ones for us, so the intercept
# term is handled
X = pd.DataFrame(X)
X = X.apply(mapFeature, axis=1)
# convert back to numpy ndarray
X = X.values

# Initialize fitting parameters
initial_theta = np.zeros(X.shape[1])
Expand Down

0 comments on commit d455d55

Please sign in to comment.