# How do I plot the metrics from the strategy

**URL:** <https://discuss.flower.ai/t/how-do-i-plot-the-metrics-from-the-strategy/72>\
**Category:** Flower Help - Beginners\
**Tags:** faq, metrics\
**Created:** [February 22, 2024, 1:56pm UTC](https://discuss.flower.ai/t/how-do-i-plot-the-metrics-from-the-strategy/72 "2024-02-22T13:56:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![flower](https://dub1.discourse-cdn.com/flex013/user_avatar/discuss.flower.ai/flower/32/17_2.png) [@flower](https://discuss.flower.ai/u/flower)\
**Post date:** [February 22, 2024, 1:56pm UTC](https://discuss.flower.ai/t/how-do-i-plot-the-metrics-from-the-strategy/72/1 "2024-02-22T13:56:10Z")

</div>

**A frequently asked question we get is:**

How do I plot the metrics from the strategy (e.g., the loss/accuracy over rounds)? 🤔

---

<div class="post-metadata">

**Author:** ![javier](https://dub1.discourse-cdn.com/flex013/user_avatar/discuss.flower.ai/javier/32/116_2.png) [@javier](https://discuss.flower.ai/u/javier)\
**Post date:** [March 1, 2024, 9:02am UTC](https://discuss.flower.ai/t/how-do-i-plot-the-metrics-from-the-strategy/72/2 "2024-03-01T09:02:46Z")

</div>

Let’s assume your strategy does centralized evaluation of the _global model_ (i.e. if you set the [`evaluate_fn`](https://flower.ai/docs/framework/ref-api/flwr.server.strategy.FedAvg.html#fedavg) argument) and also specifies a method to aggregate the metrics received by clients in an `evaluate` round. For example:

```python
strategy = fl.server.strategy.FedAvg(
    ...,
    evaluate_metrics_aggregation_fn=weighted_average, # aggregates federated metrics
    evaluate_fn=get_evaluate_fn(centralized_testset), # global evaluation function
)

```

You’d then pass such strategy to either `start_server` or `start_simulation`. They both return a [History](https://flower.ai/docs/framework/ref-api/flwr.server.History.html#flwr.server.History) object.

## Printing Centralised evaluation results

These are the results of just 10 rounds on MNIST. I’m plotting the centralized accuracy reported by the function passed to `evaluate_fn` in my strategy.

```auto
import matplotlib.pyplot as plt

print(f"{history.metrics_centralized = }")

global_accuracy_centralised = history.metrics_centralized["accuracy"]
round = [data[0] for data in global_accuracy_centralised]
acc = [100.0 * data[1] for data in global_accuracy_centralised]
plt.plot(round, acc)
plt.grid()
plt.ylabel("Accuracy (%)")
plt.xlabel("Round")
plt.title("MNIST - IID - 100 clients with 10 clients per round")

```

 ![Screenshot 2024-03-01 at 09.00.04](https://europe1.discourse-cdn.com/flex013/uploads/flower/original/1X/4136c72d624f783b153691849a0594127bfd6041.png)

You can follow a similar logic for the aggregated _distributed_ evaluate metrics. The result of your `evaluate_metrics_aggregation_fn` can be accessed by:

```python
history.metrics_distributed # as opposed to .metrics_centralized
# then you can plot it 

```

If interacting with the [History](https://flower.ai/docs/framework/ref-api/flwr.server.History.html#flwr.server.History) object is limiting for your use case, you can write a custom strategy that stores in a different way the result of the strategy’s `evaluate()`, `aggregate_evaluate()` methods (and potentially `aggregate_fit()`.

---

<div class="post-metadata">

**Author:** ![flower](https://dub1.discourse-cdn.com/flex013/user_avatar/discuss.flower.ai/flower/32/17_2.png) [@flower](https://discuss.flower.ai/u/flower)\
**Post date:** [March 1, 2024, 11:29am UTC](https://discuss.flower.ai/t/how-do-i-plot-the-metrics-from-the-strategy/72/3 "2024-03-01T11:29:53Z")

</div>


