start_cross_validation.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  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.k_fold import KFold
  18. from federatedml.util import LOGGER
  19. def _get_cv_param(model):
  20. model.model_param.cv_param.role = model.role
  21. model.model_param.cv_param.mode = model.mode
  22. return model.model_param.cv_param
  23. def run(model, data_instances, host_do_evaluate=False):
  24. if not model.need_run:
  25. return data_instances
  26. kflod_obj = KFold()
  27. cv_param = _get_cv_param(model)
  28. output_data = kflod_obj.run(cv_param, data_instances, model, host_do_evaluate)
  29. LOGGER.info("Finish KFold run")
  30. return output_data