def test_monk1(self): nn = NN(seed=4, epochs_limit=400, learning_algorithm=batch, error_calculator=ErrorCalculator.MSE, architecture=MultilayerPerceptron( 4, activation=sigmoid, activation_hidden=relu, eta=0.5, alambd=0, alpha=0.8, )) train_data, test_data = read_monk(1) nn.fit(train_data) train_errs = nn.compute_learning_curve(train_data, ErrorCalculator.MIS) test_errs = nn.compute_learning_curve(test_data, ErrorCalculator.MIS) error_train = 0 for x, d in train_data: error_train += (round(nn(x)[0][-1]) - d[0])**2 error_test = 0 for x, d in test_data: error_test += (round(nn(x)[0][-1]) - d[0])**2 print( 'train:', str(((len(train_data) - error_train) / len(train_data)) * 100) + '%') print( 'test: ', str(((len(test_data) - error_test) / len(test_data)) * 100) + '%') self.assertEqual(error_train, 0) self.assertEqual(error_test, 0) nn.error_calculator = ErrorCalculator.MIS self.assertEqual(nn.compute_error(train_data), 0) self.assertEqual(nn.compute_error(test_data), 0)
from typing import Mapping, Sequence, Any, Dict from nn import ErrorCalculator from nn import sigmoid, batch from nn.utilities import read_monk from nn.activation_functions import relu, tanh, tanh_classification from nn.validation import grid_search, write_on_file import multiprocessing as mp train_data, test_data = read_monk(1) params_nn: Dict[str, Sequence[Any]] = dict( error_calculator=[ErrorCalculator.MSE], learning_algorithm=[batch], epochs_limit=[1000], n_init=[10], epsilon=[1e-05], patience=[10], ) params_architecture: Mapping[str, Sequence[Any]] = dict( size_hidden_layers=[(2, )], activation=[tanh_classification], activation_hidden=[relu], eta=[0.1, 0.01, 0.001], alpha=[0, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9], alambd=[0, 0.0001, 0.001, 0.01], eta_decay=[0], ) cv_params: Mapping[str, Any] = dict(