Skip to content

Instantly share code, notes, and snippets.

@aateg
Last active October 27, 2019 06:07
Show Gist options
  • Save aateg/9d72f92e0eaaa65068cf594272f43f9c to your computer and use it in GitHub Desktop.
Save aateg/9d72f92e0eaaa65068cf594272f43f9c to your computer and use it in GitHub Desktop.
Treinamento da Rede Neural
def nnTrain(epsilon, alpha, max_iter):
input_layer_size = x_train.shape[1]
hidden_layer_size = 800
num_labels = 10
theta_1, theta_2 = randomInit(input_layer_size, hidden_layer_size, num_labels)
for i in range(max_iter):
J_theta, Theta1_grad, Theta2_grad = nnRegCostFunction(
theta_1, theta_2, x_train, y_train,
input_layer_size, hidden_layer_size, num_labels)
theta_1 = theta_1 - alpha * Theta1_grad
theta_2 = theta_2 - alpha * Theta2_grad
acc = accuracy(theta_1, theta_2, x_train, y_train, y_train_classif)
print(f'Iteração {i+1:2d}: custo={J_theta:5.2f} acurácia={100*acc:4.1f}%')
if 1-acc < epsilon:
break
return theta_1, theta_2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment