Ejemplo n.º 1
0
one = np.ones((m, 1))
datax = np.append(one, datax, axis=1)
print(datax)
print(datax.shape)
# initialize fitting parameters

theta = np.zeros((2, 1))

# Some gradient descent settings
alpha = 0.01
num_iters = 1500
print('Testing the cost function ...')

# compute and display initial cost

J = LR.computecost(datax, datay, theta)
print('With theta = [0 ; 0]Cost computed =', J)
print('Expected cost value (approx) 32.07')

# further testing of the cost function

thetatest = np.array([[-1], [2]])
J = LR.computecost(datax, datay, thetatest)
print('With theta = [-1 ; 2]Cost computed = ', J)
print('Expected cost value (approx) 54.24')

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

# run gradient descent

print('Running Gradient Descent ...')