Last active
October 27, 2019 06:07
-
-
Save guilhermefgs/9d72f92e0eaaa65068cf594272f43f9c to your computer and use it in GitHub Desktop.
Treinamento da Rede Neural
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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