(cm, class_names)
return figure
Returns a matplotlib figure containing the plotted confusion matrix.

    Parameters:
    cm (array, shape = [n, n]): a confusion matrix of integer classes
    class_names (array, shape = [n]): String names of the integer classes
Returns a matplotlib figure containing the plotted confusion matrix.
Returns a matplotlib figure containing the plotted confusion matrix .
def plot_confusion_matrix(cm, class_names):
    """
    Returns a matplotlib figure containing the plotted confusion matrix.

    Parameters:
    cm (array, shape = [n, n]): a confusion matrix of integer classes
    class_names (array, shape = [n]): String names of the integer classes
    """
    figure = plt.figure(figsize=(8, 8))
    ax = plt.gca()
    im = ax.imshow(cm, interpolation='nearest', cmap=plt.cm.Blues)
    plt.title("Confusion matrix")
    plt.colorbar(im, fraction=0.046, pad=0.04)
    tick_marks = np.arange(len(class_names))
    plt.xticks(tick_marks, class_names, rotation=45)
    plt.yticks(tick_marks, class_names)

    # Normalize the confusion matrix.
    cm = np.around(cm.astype('float') / cm.sum(axis=1)[:, np.newaxis], decimals=2)

    # Use white text if squares are dark; otherwise black.
    threshold = cm.max() / 2.
    for i, j in product(range(cm.shape[0]), range(cm.shape[1])):
        color = "white" if cm[i, j] > threshold else "black"
        plt.text(j, i, cm[i, j], horizontalalignment="center", color=color)

    plt.tight_layout()
    plt.ylabel('True label')
    plt.xlabel('Predicted label')
    return figure
def plot_confusion_matrix ( cm , class_names ) : figure = plt . figure ( figsize = ( 8 , 8 ) ) ax = plt . gca ( ) im = ax . imshow ( cm , interpolation = 'nearest' , cmap = plt . cm . Blues ) plt . title ( "Confusion matrix" ) plt . colorbar ( im , fraction = 0.046 , pad = 0.04 ) tick_marks = np . arange ( len ( class_names ) ) plt . xticks ( tick_marks , class_names , rotation = 45 ) plt . yticks ( tick_marks , class_names ) # Normalize the confusion matrix. cm = np . around ( cm . astype ( 'float' ) / cm . sum ( axis = 1 ) [ : , np . newaxis ] , decimals = 2 ) # Use white text if squares are dark; otherwise black. threshold = cm . max ( ) / 2. for i , j in product ( range ( cm . shape [ 0 ] ) , range ( cm . shape [ 1 ] ) ) : color = "white" if cm [ i , j ] > threshold else "black" plt . text ( j , i , cm [ i , j ] , horizontalalignment = "center" , color = color ) plt . tight_layout ( ) plt . ylabel ( 'True label' ) plt . xlabel ( 'Predicted label' ) return figure