filled=True,
                                   rounded=True,
                                   special_characters=True,
                                   feature_names=labels_features,
                                   class_names=['0', '1'])
        # Convert to png
        call([
            'dot', '-Tpng', (subDir + 'HFCR - ' + key + ' - dtree.dot'), '-o',
            (subDir + 'HFCR Decision Trees - ' + key +
             ' - tree representation.png'), '-Gdpi=600'
        ])

        prd_trn_lst = best_model[0]
        prd_tst_lst = best_model[1]

        ds.plot_evaluation_results_kfold([0, 1], trn_y_lst, prd_trn_lst,
                                         tst_y_lst, prd_tst_lst)
        plt.suptitle('HFCR Decision Trees - ' + key +
                     ' - Performance & Confusion matrix')
        plt.savefig(subDir + 'HFCR Decision Trees - ' + key +
                    ' - Performance & Confusion matrix')

        if (offset == 1):
            break
        if (last_accuracy > best_accuracy and best_accuracy != -1):
            best_accuracy = last_accuracy
            last_accuracy = -1
            count += offset
            offset -= 1
        elif (best_accuracy == -1):
            best_accuracy = last_accuracy
            count += 1
Exemplo n.º 2
0
                ds.multiple_line_chart(
                    n_estimators,
                    overfit_values[d][f],
                    ax=axs[k, i],
                    title=
                    'Overfitting for max_depth = %d with max_features = %f' %
                    (d, f),
                    xlabel='n_estimators',
                    ylabel='accuracy',
                    percentage=True)
        plt.suptitle('HFCR Overfitting - Random Forests')
        plt.savefig(subDir + 'HFCR Overfitting - Random Forests')

        print('HFCR Random Forests - Performance & Confusion Matrix')
        prd_trn_lst = best_model[0]
        prd_tst_lst = best_model[1]

        ds.plot_evaluation_results_kfold(pd.unique(y), trn_y_lst, prd_trn_lst,
                                         tst_y_lst, prd_tst_lst)
        plt.suptitle('HFCR Random Forests - ' + key +
                     '- Performance & Confusion Matrix')
        plt.savefig(subDir + 'HFCR Random Forests - ' + key +
                    '- Performance & Confusion Matrix')
        print()

        plt.close("all")

plt.figure(figsize=(7, 7))
ds.multiple_bar_chart(['Train', 'Test'], best_accuracies, ylabel='Accuracy')
plt.suptitle('HFCR Sampling & Feature Selection')
plt.savefig(graphsDir + 'HFCR Sampling & Feature Selection')