positive_unlabeled_param.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. from pipeline.param import consts
  19. from pipeline.param.base_param import BaseParam
  20. class PositiveUnlabeledParam(BaseParam):
  21. """
  22. Parameters used for positive unlabeled.
  23. ----------
  24. strategy: {"probability", "quantity", "proportion", "distribution"}
  25. The strategy of converting unlabeled value.
  26. threshold: int or float, default: 0.9
  27. The threshold in labeling strategy.
  28. """
  29. def __init__(self, strategy="probability", threshold=0.9):
  30. super(PositiveUnlabeledParam, self).__init__()
  31. self.strategy = strategy
  32. self.threshold = threshold
  33. def check(self):
  34. base_descr = "Positive Unlabeled Param's "
  35. float_descr = "Probability or Proportion Strategy Param's "
  36. int_descr = "Quantity Strategy Param's "
  37. numeric_descr = "Distribution Strategy Param's "
  38. self.check_valid_value(self.strategy, base_descr,
  39. [consts.PROBABILITY, consts.QUANTITY, consts.PROPORTION, consts.DISTRIBUTION])
  40. self.check_defined_type(self.threshold, base_descr, [consts.INT, consts.FLOAT])
  41. if self.strategy == consts.PROBABILITY or self.strategy == consts.PROPORTION:
  42. self.check_decimal_float(self.threshold, float_descr)
  43. if self.strategy == consts.QUANTITY:
  44. self.check_positive_integer(self.threshold, int_descr)
  45. if self.strategy == consts.DISTRIBUTION:
  46. self.check_positive_number(self.threshold, numeric_descr)
  47. return True