def plot_confusion_matrix()

in builtin_algorithm_hpo_tabular/util/classification_report.py [0:0]


def plot_confusion_matrix(confusion_matrix, 
                          class_names_list=['Class1', 'Class2'],
                          axis=None,
                          title='Confusion matrix',
                          plot_style='ggplot',
                          colormap=plt.cm.Blues):

    if axis is None:  # for standalone plot
        plt.figure()
        ax = plt.gca()
    else:  # for plots inside a subplot
        ax = axis
 
    plt.style.use(plot_style)
    
    # normalizing matrix to [0,100%]
    confusion_matrix_norm = (confusion_matrix.astype('float') / 
                             confusion_matrix.sum(axis=1)[:, np.newaxis])
    confusion_matrix_norm = np.round(100 * confusion_matrix_norm, 2)

    ax.imshow(confusion_matrix_norm,
              interpolation='nearest',
              cmap=colormap,
              vmin=0,  # to make sure colors are scaled between [0,100%]
              vmax=100)
 
    ax.set_title(title)
    tick_marks = np.arange(len(class_names_list))
    ax.set_xticks(tick_marks)
    ax.set_xticklabels(class_names_list, rotation=0)
    ax.set_yticks(tick_marks)
    ax.set_yticklabels(class_names_list)
    
    for i, j in itertools.product(range(confusion_matrix.shape[0]), 
                                  range(confusion_matrix.shape[1])):
        ax.text(j, i, 
                 str(confusion_matrix[i, j])+'\n('+str(confusion_matrix_norm[i,j])+'%)',
                 horizontalalignment="center",
                 color="white" if confusion_matrix_norm[i, j] > 50 else "black")

    ax.set_ylabel('True label')
    ax.set_xlabel('Predicted label')
    ax.grid(False)
    
    if axis is None:  # for standalone plots
        plt.tight_layout()
        plt.show()