for realization in range(20): train, test = split_random(base, train_percentage=.8) train, train_val = split_random(train, train_percentage=.8) x_train = train[:, :4] y_train = train[:, 4:] x_train_val = train_val[:, :4] y_train_val = train_val[:, 4:] x_test = test[:, :4] y_test = test[:, 4:] validation_alphas = [0.15] hidden = 3 * np.arange(1, 5) simple_net = MultiLayerPerceptron(M, C, epochs=10000) simple_net.fit(x_train, y_train, x_train_val=x_train_val, y_train_val=y_train_val, alphas=validation_alphas, hidden=hidden) y_out_simple_net = simple_net.predict(x_test, bias=True) y_test = simple_net.predicao(y_test) metrics_calculator = metric(y_test, y_out_simple_net, types=['ACCURACY', 'precision', 'recall', 'f1_score']) metric_results = metrics_calculator.calculate(average='macro') print(metric_results) results['cf'].append((metric_results['ACCURACY'], metrics_calculator.confusion_matrix(list(y_test), y_out_simple_net, labels=[0,1,2]))) results['alphas'].append(simple_net.learning_rate)
train, test = split_random(df, train_percentage=.8) train, train_val = split_random(train, train_percentage=.8) x_train = train[features] y_train = train[target].to_numpy().reshape(train[target].shape[0], 1) x_train_val = train_val[features] y_train_val = train_val[target] x_test = test[features] y_test = test[target] y_test.to_numpy().reshape(y_test.shape[0], 1) validation_alphas = [0.008] hidden = [8, 10, 12, 16] simple_net = MultiLayerPerceptron(M, C, epochs=epochs, Regressao=True) simple_net.fit(x_train.to_numpy(), y_train, x_train_val=x_train_val.to_numpy(), y_train_val=y_train_val, alphas=validation_alphas, hidden=hidden, validation=False) y_out = simple_net.predict(x_test, bias=True) metrics_calculator = metric(y_test, y_out, types=['MSE', 'RMSE', 'R2']) metric_results = metrics_calculator.calculate() print(metric_results) results['error_per_epoch'].append(
# ------------------------------ x and y for validation ----------------------------------- # x_train_val = train_val[features] # y_train_val = train_val[different_target] # ------------------------------ x and y for test ------------------------------------------ x_test = test[features] y_test = test[different_target] y_test.to_numpy().reshape(y_test.shape[0], 1) # ---------------------------------- modeling ---------------------------------------------- validation_alphas = [0.15] hidden = 4 * np.arange(1, 5) simple_net = MultiLayerPerceptron(9, C, epochs=1000, Regressao=True, hidden_layer_neurons=12, learning_rate=0.15) simple_net.fit(x_train.to_numpy(), y_train, x_train_val=[], y_train_val=[], alphas=validation_alphas, hidden=hidden, validation=False) y_out = simple_net.predict(x_test, bias=True) metrics_calculator = metric(y_test, y_out, types=['MSE', 'RMSE']) metric_results = metrics_calculator.calculate() print(metric_results) results['alphas'].append(simple_net.lr) results['realization'].append(realization) for type in ['MSE', 'RMSE']:
train, train_val = split_random(train, train_percentage=.8) x_train = train[['x1']] y_train = train[['y']] x_train_val = train_val[['x1']] y_train_val = train_val[['y']] x_test = test[['x1']] y_test = test[['y']] validation_alphas = [0.15] hidden = 3 * np.arange(1, 6) simple_net = MultiLayerPerceptron(M, C, epochs=epochs, Regressao=True, learning_rate=0.05, hidden_layer_neurons=12) simple_net.fit(x_train, y_train.to_numpy(), x_train_val=x_train_val, y_train_val=y_train_val.to_numpy(), alphas=validation_alphas, hidden=hidden) y_out = simple_net.predict(x_test, bias=True) metrics_calculator = metric(y_test, y_out, types=['MSE', 'RMSE', 'R2']) metric_results = metrics_calculator.calculate() print(metric_results)