local_baseline_param.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. #
  18. import copy
  19. from federatedml.param.base_param import BaseParam
  20. from federatedml.param.predict_param import PredictParam
  21. class LocalBaselineParam(BaseParam):
  22. """
  23. Define the local baseline model param
  24. Parameters
  25. ----------
  26. model_name : str
  27. sklearn model used to train on baseline model
  28. model_opts : dict or none, default None
  29. Param to be used as input into baseline model
  30. predict_param : PredictParam object, default: default PredictParam object
  31. predict param
  32. need_run: bool, default True
  33. Indicate if this module needed to be run
  34. """
  35. def __init__(self, model_name="LogisticRegression", model_opts=None, predict_param=PredictParam(), need_run=True):
  36. super(LocalBaselineParam, self).__init__()
  37. self.model_name = model_name
  38. self.model_opts = model_opts
  39. self.predict_param = copy.deepcopy(predict_param)
  40. self.need_run = need_run
  41. def check(self):
  42. descr = "local baseline param"
  43. self.model_name = self.check_and_change_lower(self.model_name,
  44. ["logisticregression"],
  45. descr)
  46. self.check_boolean(self.need_run, descr)
  47. if self.model_opts is not None:
  48. if not isinstance(self.model_opts, dict):
  49. raise ValueError(descr + " model_opts must be None or dict.")
  50. if self.model_opts is None:
  51. self.model_opts = {}
  52. self.predict_param.check()
  53. return True