def main(argv, input_break, target_break, apply_target, S, max_epoch, lr, B=1): if (len(argv) != 3): print('Error en la entrada') [_, model, data] = argv # lectura y pre procesamiento de datos (input, target) = load_dataset(data, input_break, target_break, apply_target) if (not path.exists(model + '.p')): # entrenamiento errors, W = train(input, target, S, max_epoch, lr, B) plot_error(errors) pickle.dump(errors, open(model + '_errors.p', 'wb')) pickle.dump(W, open(model + '.p', 'wb')) else: # testing # carga de modelo entrenado W = pickle.load(open(model + '.p', 'rb')) # testeo r, Y, Z = test(input, target, S, W) if Z.shape[1] == 1: print('precisión: {} (aciertos/total)'.format(r)) else: print('error cuadratico medio: {}'.format(r))
def exp(self, S, max_epoch, lr, train_break, test_break, B): errors = self.train(S, max_epoch, lr, train_break, B) prec, Y, Z = self.test(test_break) plot_target_1(Y, Z) plot_error(errors) V = [] J = [] Y = np.array(Y) Z = np.array(Z) for i in range(len(Y)): if (Y[i] > -0.95 and Y[i] < 0.95) or not (np.sign(Y[i]) == Z[i]): V.append(Y[i]) J.append(Z[i]) plot_scat_1(Y, Z) plot_scat_1(V, J) print('precision: {}'.format(prec)) return errors
from dataset import load_dataset from hebbiano import Hebbiano from plotter import plot, plot_error data, labels = load_dataset('./dataset/tp2_training_dataset.csv') data_train = data[:700] labels_train = labels[:700] data_test = data[700:] labels_test = labels[700:] modelo = Hebbiano(data_train) errors = modelo.train('oja', 9, 0.00001, 0.001, 1500, 100) plot_error(errors) plot(modelo.test(data_train), labels_train) plot(modelo.test(data_test), labels_test)
def exp_2(self, S, max_epoch, lr, train_break, test_break, B): errors = self.train(S, max_epoch, lr, train_break, B) ecm, Y, Z = self.test(test_break) plot_error(errors) print('error cuadratico medio: {}'.format(ecm)) return errors