Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example for Custom Metrics calculation during Federated Learning #1958

Merged
merged 34 commits into from
Jan 23, 2024

Conversation

gubertoli
Copy link
Contributor

Issue

A common question on the flower's questions channel from Slack is related with retrieving other metrics in addition to those available on the ML frameworks.

Description

This PR aims to provide a clear example on how to retrieve custom and additional metrics, to serve as baseline for other people using the Flower for Federated Learning.

Related issues/PRs

N/A

Proposal

A new example on how to calculate custom metrics during Federated Learning.

Explanation

This simple example demonstrate how to calculate custom metrics over multiple clients beyond the traditional ones available in the ML frameworks. In this case, it demonstrate the use of ready-available scikit-learn metrics: accuracy, recall, precision, and f1-score.

Once both the test values (y_test) and the predictions (y_pred) are available on the client side (client.py), other metrics or custom ones are possible to be calculated.

The main takeaways of this implementation are:

  • the use of the output_dict on the client side - inside evaluate method on client.py
  • the use of the evaluate_metrics_aggregation_fn - to aggregate the metrics on the server side, part of the strategy on server.py

This example is based on the quickstart_tensorflow with CIFAR-10, source here.

Checklist

  • Implement proposed change
  • Write tests
  • Update documentation
  • Update changelog
  • Make CI checks pass
  • Ping maintainers on Slack (channel #contributions)

Any other comments?

N/A

gubertoli and others added 11 commits March 6, 2022 00:42
Correcting validation dataset references on FlowerClient class and min_eval_clients to be in accordance with the comments.
To be compatible with sanity check for the return of fit method from clients (Tuple of list,int,dict) introduced on the last version of flower.
@gubertoli
Copy link
Contributor Author

@danieljanes
Just a heads up regarding this example, as I missed the history in the Slack channel (+90 days).

@gubertoli gubertoli requested a review from jafermarq as a code owner January 16, 2024 15:05
examples/custom-metrics/requirements.txt Outdated Show resolved Hide resolved
examples/custom-metrics/pyproject.toml Outdated Show resolved Hide resolved
examples/custom-metrics/client.py Outdated Show resolved Hide resolved
examples/custom-metrics/client.py Outdated Show resolved Hide resolved
@jafermarq jafermarq self-assigned this Jan 17, 2024
@jafermarq jafermarq added the part: examples Add or update a Flower example label Jan 17, 2024
@yan-gao-GY yan-gao-GY self-requested a review January 18, 2024 10:13
examples/custom-metrics/README.md Outdated Show resolved Hide resolved
examples/custom-metrics/README.md Outdated Show resolved Hide resolved
examples/custom-metrics/README.md Show resolved Hide resolved
examples/custom-metrics/README.md Show resolved Hide resolved
examples/custom-metrics/client.py Show resolved Hide resolved
examples/custom-metrics/client.py Outdated Show resolved Hide resolved
examples/custom-metrics/client.py Outdated Show resolved Hide resolved
examples/custom-metrics/server.py Show resolved Hide resolved
examples/custom-metrics/server.py Show resolved Hide resolved
examples/custom-metrics/server.py Show resolved Hide resolved
@yan-gao-GY
Copy link
Contributor

Hi @gubertoli, thanks for your contribution for this example! I left a few suggested changes and comments.

@gubertoli
Copy link
Contributor Author

Hi @gubertoli, thanks for your contribution for this example! I left a few suggested changes and comments.

Thank you so much, @yan-gao-GY, for the support!

@danieljanes danieljanes merged commit dfa30a3 into adap:main Jan 23, 2024
28 checks passed
@danieljanes
Copy link
Member

Thanks for the contribution @gubertoli!

@gubertoli gubertoli deleted the extra_metrics branch January 23, 2024 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
part: examples Add or update a Flower example
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants