Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def train(X, Y, n_batch, eta, n_epochs, W, b, l):
- vX, vY, vy = unpackData(vFileName)
- costs = []
- vCosts = []
- i = 0
- while i < n_epochs:
- j = 0
- while j < np.shape(X)[1]/n_batch:
- j_start = j * n_batch
- j_end = (j+1) * n_batch
- Xbatch = X[:, j_start:j_end]
- Ybatch = Y[:, j_start:j_end]
- P = evaluateClassifier(Xbatch, W, b);
- grad_W, grad_b = computeGradients(Xbatch, Ybatch, P, W, l)
- W = W - eta * grad_W;
- b = b - eta * grad_b;
- j += 1
- c = computeCost(X, Y, W, b, l);
- vC = computeCost(vX, vY, W, b, l);
- print(i, ". Cost: ", c)
- costs.append(c)
- vCosts.append(vC)
- i += 1
- return costs, vCosts, W, b
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement