(
        stat_metrics, sys_metrics, max_num_clients, figsize=(15, 12), title_fontsize=16, max_name_len=10, **kwargs)
Plots the clients' test accuracy vs. the round number.

    Args:
        stat_metrics: pd.DataFrame as written by writer.py.
        sys_metrics: pd.DataFrame as written by writer.py. Allows us to know which client actually performed training
            in each round. If None, then no indication is given of when was each client trained.
        max_num_clients: Maximum number of clients to plot.
        figsize: Size of the plot as specified by plt.figure().
        title_fontsize: Font size for the plot's title.
        max_name_len: Maximum length for a client's id.
        kwargs: Arguments to be passed to _set_plot_properties.
Plots the clients' test accuracy vs. the round number.
Plots the clients test accuracy vs . the round number .
def plot_accuracy_vs_round_number_per_client(
        stat_metrics, sys_metrics, max_num_clients, figsize=(15, 12), title_fontsize=16, max_name_len=10, **kwargs):
    """Plots the clients' test accuracy vs. the round number.

    Args:
        stat_metrics: pd.DataFrame as written by writer.py.
        sys_metrics: pd.DataFrame as written by writer.py. Allows us to know which client actually performed training
            in each round. If None, then no indication is given of when was each client trained.
        max_num_clients: Maximum number of clients to plot.
        figsize: Size of the plot as specified by plt.figure().
        title_fontsize: Font size for the plot's title.
        max_name_len: Maximum length for a client's id.
        kwargs: Arguments to be passed to _set_plot_properties."""
    # Plot accuracies per client.
    clients = stat_metrics[CLIENT_ID_KEY].unique()[:max_num_clients]
    cmap = plt.get_cmap('jet_r')
    plt.figure(figsize=figsize)

    for i, c in enumerate(clients):
        color = cmap(float(i) / len(clients))
        c_accuracies = stat_metrics.loc[stat_metrics[CLIENT_ID_KEY] == c]
        plt.plot(c_accuracies[NUM_ROUND_KEY], c_accuracies[ACCURACY_KEY], color=color)

    plt.suptitle('Accuracy vs Round Number (Per Client)', fontsize=title_fontsize)
    plt.title('(Dots indicate that client was trained at that round)')
    plt.xlabel('Round Number')
    plt.ylabel('Accuracy')

    labels = stat_metrics[[CLIENT_ID_KEY, NUM_SAMPLES_KEY]].drop_duplicates()
    labels = labels.loc[labels[CLIENT_ID_KEY].isin(clients)]
    labels = ['%s, %d' % (row[CLIENT_ID_KEY][:max_name_len], row[NUM_SAMPLES_KEY])
              for _, row in labels.iterrows()]
    plt.legend(labels, title='client id, num_samples', loc='upper left')

    # Plot moments in which the clients were actually used for training.
    # To do this, we need the system metrics (to know which client actually performed training in each round).
    if sys_metrics is not None:
        for i, c in enumerate(clients[:max_num_clients]):
            color = cmap(float(i) / len(clients))
            c_accuracies = stat_metrics.loc[stat_metrics[CLIENT_ID_KEY] == c]
            c_computation = sys_metrics.loc[sys_metrics[CLIENT_ID_KEY] == c]
            c_join = pd.merge(c_accuracies, c_computation, on=NUM_ROUND_KEY, how='inner')
            if not c_join.empty:
                plt.plot(
                    c_join[NUM_ROUND_KEY],
                    c_join[ACCURACY_KEY],
                    linestyle='None',
                    marker='.',
                    color=color,
                    markersize=18)

    _set_plot_properties(kwargs)
    plt.show()
def plot_accuracy_vs_round_number_per_client ( stat_metrics , sys_metrics , max_num_clients , figsize = ( 15 , 12 ) , title_fontsize = 16 , max_name_len = 10 , * * kwargs ) : # Plot accuracies per client. clients = stat_metrics [ CLIENT_ID_KEY ] . unique ( ) [ : max_num_clients ] cmap = plt . get_cmap ( 'jet_r' ) plt . figure ( figsize = figsize ) for i , c in enumerate ( clients ) : color = cmap ( float ( i ) / len ( clients ) ) c_accuracies = stat_metrics . loc [ stat_metrics [ CLIENT_ID_KEY ] == c ] plt . plot ( c_accuracies [ NUM_ROUND_KEY ] , c_accuracies [ ACCURACY_KEY ] , color = color ) plt . suptitle ( 'Accuracy vs Round Number (Per Client)' , fontsize = title_fontsize ) plt . title ( '(Dots indicate that client was trained at that round)' ) plt . xlabel ( 'Round Number' ) plt . ylabel ( 'Accuracy' ) labels = stat_metrics [ [ CLIENT_ID_KEY , NUM_SAMPLES_KEY ] ] . drop_duplicates ( ) labels = labels . loc [ labels [ CLIENT_ID_KEY ] . isin ( clients ) ] labels = [ '%s, %d' % ( row [ CLIENT_ID_KEY ] [ : max_name_len ] , row [ NUM_SAMPLES_KEY ] ) for _ , row in labels . iterrows ( ) ] plt . legend ( labels , title = 'client id, num_samples' , loc = 'upper left' ) # Plot moments in which the clients were actually used for training. # To do this, we need the system metrics (to know which client actually performed training in each round). if sys_metrics is not None : for i , c in enumerate ( clients [ : max_num_clients ] ) : color = cmap ( float ( i ) / len ( clients ) ) c_accuracies = stat_metrics . loc [ stat_metrics [ CLIENT_ID_KEY ] == c ] c_computation = sys_metrics . loc [ sys_metrics [ CLIENT_ID_KEY ] == c ] c_join = pd . merge ( c_accuracies , c_computation , on = NUM_ROUND_KEY , how = 'inner' ) if not c_join . empty : plt . plot ( c_join [ NUM_ROUND_KEY ] , c_join [ ACCURACY_KEY ] , linestyle = 'None' , marker = '.' , color = color , markersize = 18 ) _set_plot_properties ( kwargs ) plt . show ( )