import numpy as np import dataset as ds from neural_networks import NeuralNetwork from layers import InputLayer, OutputLayer, DenseLayer from functions._init_functions import init_functions from functions._activation_functions import activation_functions, activation_functions_derivatives from functions._loss_functions import loss_functions import plot as plt data = ds.MLCupDataset() data = ds.MLCupDataset() model = NeuralNetwork() model.add(InputLayer(10)) model.add(DenseLayer(50, fanin=10, activation="sigmoid")) model.add(DenseLayer(30, fanin=50, activation="sigmoid")) model.add(OutputLayer(2, fanin=30)) # configuration 322, line 324 model.compile(1143, 600, 0.03, None, 0.000008, 0.3, "mean_squared_error") loss = model.fit(data.train_data_patterns, data.train_data_targets) print(loss[-1]) plt.plot_loss(loss)
fp = open(filepath, "w") config = 0 for epoch in epochs: for lr in learning_rates: for reg in regularizations: for alpha in momentums: mean_loss = 0 mean_validation = 0 for i in range(k): model = NeuralNetwork() model.add(InputLayer(10)) model.add(DenseLayer(50, fanin=10)) model.add(DenseLayer(30, fanin=50)) model.add(OutputLayer(2, fanin=30)) model.compile(size, epoch, lr / size, None, reg, alpha, "mean_squared_error") (train, val) = data.kfolds(index=i, k=k) mean_loss = mean_loss + model.fit(train[0], train[1])[-1] mean_validation = mean_validation + model.evaluate( val[0], val[1]) fp.write("{}, {}, {}, {}, {}, {}, {}\n".format( config, epoch, lr, reg, alpha, mean_loss / k, mean_validation / k)) config = config + 1 fp.close()
import numpy as np import dataset as ds from neural_networks import NeuralNetwork from layers import InputLayer, OutputLayer, DenseLayer import matplotlib.pyplot as plt data = ds.MonksDataset() my_model = NeuralNetwork() my_model.add(InputLayer(17)) my_model.add(DenseLayer(10, fanin=17, activation="sigmoid")) my_model.add(OutputLayer(1, fanin=10, activation="sigmoid")) my_model.compile(122, 600, 0.075, None, 0.0001, 0, "mean_squared_error") (loss, test_loss, accuracy, test_accuracy) = my_model.fit_monks( data.train_data_patterns, data.train_data_targets, data.test_data_patterns, data.test_data_targets) print("Loss: {}".format(loss[-1])) print("Test Loss: {}".format(test_loss[-1])) print("Accuracy: {}".format(accuracy[-1])) print("Test accuracy: {}".format(test_accuracy[-1])) plot1 = plt.figure(1) plt.plot(loss) plt.plot(test_loss, "--") plot2 = plt.figure(2)