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

    # Labels and Legend
    plt.xlabel('Microchip Test 1')
    plt.ylabel('Microchip Test 2')
Beispiel #2
0
def plotBoundary(theta, X, y):
    plotDecisionBoundary(theta, X.values, y.values)
    plt.title(r'$\lambda$ = ' + str(Lambda))
    # Labels and Legend
    plt.xlabel('Microchip Test 1')
    plt.ylabel('Microchip Test 2')
    plt.show()
               args=(X, y),
               options={
                   'gtol': 1e-3,
                   'disp': True,
                   'maxiter': 1000
               })
#Nelder-Mead method works similar to the Octave code
theta = res.x
cost = res.fun

# Print theta to screen
print('Cost at theta found by scipy: %f' % cost)
print('theta:', ["%0.4f" % i for i in theta])

# Plot Boundary
plotDecisionBoundary(theta, X, y)

# Labels and Legend
plt.legend(['Admitted', 'Not admitted'],
           loc='upper right',
           shadow=True,
           fontsize='x-large',
           numpoints=1)
plt.xlabel('Exam 1 score')
plt.ylabel('Exam 2 score')
plt.show()

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

#  ============== Part 4: Predict and Accuracies ==============
print 'Gradient at initial theta (zeros): ' + str(grad)


# ============= Part 3: Optimizing using scipy  =============
res = minimize(costFunction, initial_theta, method='TNC',
               jac=False, args=(X, y), options={'gtol': 1e-3, 'disp': True, 'maxiter': 1000})

theta = res.x
cost = res.fun

# Print theta to screen
print 'Cost at theta found by scipy: %f' % cost
print 'theta:', ["%0.4f" % i for i in theta]

# Plot Boundary
plotDecisionBoundary(theta, X, y)

# Labels and Legend
plt.legend(['Admitted', 'Not admitted'], loc='upper right', shadow=True, fontsize='x-large', numpoints=1)
plt.xlabel('Exam 1 score')
plt.ylabel('Exam 2 score')


#  ============== Part 4: Predict and Accuracies ==============

#  Predict probability for a student with score 45 on exam 1
#  and score 85 on exam 2

prob = sigmoid(np.array([1, 45, 85]).dot(theta))
print 'For a student with scores 45 and 85, we predict an admission probability of %f' % prob