Пример #1
0
        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)
        results['realization'].append(realization)
        for type in ['ACCURACY', 'precision', 'recall', 'f1_score']:
            results[type].append(metric_results[type])
Пример #2
0
        y_train_val = train_val[:, 2:]

        x_test = test[:, :2]
        y_test = test[:, 2:]

        validation_alphas = [0.15]
        hidden = 2 * np.arange(1, 4)
        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.predict(x_test, bias=True)

        y_test = simple_net.predicao(y_test)

        metrics_calculator = metric(
            y_test,
            y_out,
            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(y_test, y_out, labels=[0,
                                                                        1])))
        results['alphas'].append(simple_net.learning_rate)