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

Fix evaluation doc typing #1682

Merged
merged 4 commits into from
Feb 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions doc/source/evaluation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ All built-in strategies support centralized evaluation by providing an evaluatio
An evaluation function is any function that can take the current global model parameters as input and return evaluation results:

.. code-block:: python

from flwr.common import NDArrays, Scalar

from typing import Dict, Optional, Tuple

def get_evaluate_fn(model):
"""Return an evaluation function for server-side evaluation."""
Expand All @@ -24,8 +28,10 @@ An evaluation function is any function that can take the current global model pa
x_val, y_val = x_train[45000:50000], y_train[45000:50000]

# The `evaluate` function will be called after every round
def evaluate(weights: fl.common.Weights) -> Optional[Tuple[float, Dict]]:
model.set_weights(weights) # Update model with the latest parameters
def evaluate(
server_round: int, parameters: NDArrays, config: Dict[str, Scalar]
) -> Optional[Tuple[float, Dict[str, Scalar]]]:
model.set_weights(parameters) # Update model with the latest parameters
loss, accuracy = model.evaluate(x_val, y_val)
return loss, {"accuracy": accuracy}

Expand Down