start_stepwise.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Copyright 2019 The FATE Authors. All Rights Reserved.
  5. #
  6. # Licensed under the Apache License, Version 2.0 (the "License");
  7. # you may not use this file except in compliance with the License.
  8. # You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. from federatedml.model_selection.stepwise.hetero_stepwise import HeteroStepwise
  18. from federatedml.util import LOGGER
  19. from federatedml.util import consts
  20. def _get_stepwise_param(model):
  21. model.model_param.stepwise_param.role = model.role
  22. model.model_param.stepwise_param.mode = model.mode
  23. return model.model_param.stepwise_param
  24. def run(model, train_data, validate_data=None):
  25. if not model.need_run:
  26. return train_data
  27. if model.mode == consts.HETERO:
  28. step_obj = HeteroStepwise()
  29. else:
  30. raise ValueError("stepwise currently only support Hetero mode.")
  31. stepwise_param = _get_stepwise_param(model)
  32. step_obj.run(stepwise_param, train_data, validate_data, model)
  33. pred_result = HeteroStepwise.predict(train_data, model)
  34. LOGGER.info("Finish running Stepwise")
  35. return pred_result