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: sklearn example model initialisation #289

Merged
merged 4 commits into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Update Iris example to init model parameter in the new initialisation task ([#289](https://github.com/Substra/substra-documentation/pull/289))
- Clarify how to login in the remote mode (#281)
- Improve permission page (#279)
- Improve installation paragraph in landing page (#276)
Expand All @@ -20,7 +21,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Rename examples from `plot_*.py` to `run_*.py` (#268)
- Add note on supported OS (#270)


## [0.24.0]

- Update intro scheme and index generator scheme (#245)
Expand Down
22 changes: 11 additions & 11 deletions substrafl_examples/go_further/run_iris_sklearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@ def __init__(self, model, seed=None):

self._model = model

# We need all different instances of the algorithm to have the same
# initialization.
self._model.coef_ = np.ones((OUTPUT_SIZE, INPUT_SIZE))
self._model.intercept_ = np.zeros(3)
self._model.classes_ = np.array([-1])

if seed is not None:
np.random.seed(seed)

Expand All @@ -272,7 +278,7 @@ def train(
to allow this function to be sent and executed on the right organization.

Args:
datasamples (_type_): datasamples extracted from the organizations data using
datasamples: datasamples extracted from the organizations data using
the given opener.
shared_state (Optional[fl_schemas.FedAvgAveragedState], optional):
shared_state provided by the aggregator. Defaults to None.
Expand All @@ -281,13 +287,7 @@ def train(
fl_schemas.FedAvgSharedState: State to be sent to the aggregator.
"""

if shared_state is None:
# If shared state is None, we are at the init state of the algorithm.
# We need all different instances of the algorithm to have the same
# initialization.
self._model.coef_ = np.ones((OUTPUT_SIZE, INPUT_SIZE))
self._model.intercept_ = np.zeros(3)
else:
if shared_state is not None:
# If we have a shared state, we update the model parameters with
# the average parameters updates.
self._model.coef_ += np.reshape(
Expand Down Expand Up @@ -331,10 +331,10 @@ def predict(self, datasamples, shared_state, predictions_path):
to allow this function to be sent and executed on the right organization.

Args:
datasamples (_type_): datasamples extracted from the organizations data using
datasamples: datasamples extracted from the organizations data using
the given opener.
shared_state (_type_): shared_state provided by the aggregator.
predictions_path (_type_, optional): Path where to save the predictions.
shared_state: shared_state provided by the aggregator.
predictions_path: Path where to save the predictions.
This path is provided by Substra and the metric will automatically
get access to this path to load the predictions.
"""
Expand Down