pipeline-data-transform-missing-fill.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #
  2. # Copyright 2019 The FATE Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. import argparse
  17. from pipeline.backend.pipeline import PipeLine
  18. from pipeline.component import DataTransform
  19. from pipeline.component import Reader
  20. from pipeline.interface import Data
  21. from pipeline.utils.tools import load_job_config
  22. def main(config="../../config.yaml", namespace=""):
  23. # obtain config
  24. if isinstance(config, str):
  25. config = load_job_config(config)
  26. parties = config.parties
  27. guest = parties.guest[0]
  28. host = parties.host[0]
  29. guest_train_data = {"name": "ionosphere_scale_hetero_guest", "namespace": f"experiment{namespace}"}
  30. host_train_data = {"name": "ionosphere_scale_hetero_host", "namespace": f"experiment{namespace}"}
  31. pipeline = PipeLine().set_initiator(role='guest', party_id=guest).set_roles(guest=guest, host=host)
  32. reader_0 = Reader(name="reader_0")
  33. reader_0.get_party_instance(role='guest', party_id=guest).component_param(table=guest_train_data)
  34. reader_0.get_party_instance(role='host', party_id=host).component_param(table=host_train_data)
  35. data_transform_0 = DataTransform(name="data_transform_0")
  36. data_transform_0.get_party_instance(role='guest', party_id=guest).component_param(with_label=True,
  37. label_name="LABEL",
  38. missing_fill=True,
  39. missing_fill_method="mean",
  40. outlier_replace=True)
  41. data_transform_0.get_party_instance(role='host', party_id=host).component_param(with_label=False,
  42. missing_fill=True,
  43. missing_fill_method="designated",
  44. default_value=0,
  45. outlier_replace=False)
  46. pipeline.add_component(reader_0)
  47. pipeline.add_component(data_transform_0, data=Data(data=reader_0.output.data))
  48. pipeline.compile()
  49. pipeline.fit()
  50. if __name__ == "__main__":
  51. parser = argparse.ArgumentParser("PIPELINE DEMO")
  52. parser.add_argument("-config", type=str,
  53. help="config file")
  54. args = parser.parse_args()
  55. if args.config is not None:
  56. main(args.config)
  57. else:
  58. main()