pipeline-homo-data-split-validate.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 HomoDataSplit
  20. from pipeline.component import Reader
  21. from pipeline.interface import Data
  22. from pipeline.utils.tools import load_job_config
  23. def main(config="../../config.yaml", namespace=""):
  24. # obtain config
  25. if isinstance(config, str):
  26. config = load_job_config(config)
  27. parties = config.parties
  28. guest = parties.guest[0]
  29. host = parties.host[0]
  30. guest_train_data = {"name": "breast_homo_guest", "namespace": f"experiment{namespace}"}
  31. host_train_data = {"name": "breast_homo_host", "namespace": f"experiment{namespace}"}
  32. pipeline = PipeLine().set_initiator(role='guest', party_id=guest).set_roles(guest=guest, host=host)
  33. reader_0 = Reader(name="reader_0")
  34. reader_0.get_party_instance(role='guest', party_id=guest).component_param(table=guest_train_data)
  35. reader_0.get_party_instance(role='host', party_id=host).component_param(table=host_train_data)
  36. data_transform_0 = DataTransform(name="data_transform_0")
  37. data_transform_0.get_party_instance(
  38. role='guest',
  39. party_id=guest).component_param(
  40. with_label=True,
  41. output_format="dense",
  42. label_name="y",
  43. label_type="int")
  44. data_transform_0.get_party_instance(role='host', party_id=host).component_param(with_label=True)
  45. homo_data_split_0 = HomoDataSplit(name="homo_data_split_0", stratified=True, validate_size=0.2)
  46. pipeline.add_component(reader_0)
  47. pipeline.add_component(data_transform_0, data=Data(data=reader_0.output.data))
  48. pipeline.add_component(homo_data_split_0, data=Data(data=data_transform_0.output.data))
  49. pipeline.compile()
  50. pipeline.fit()
  51. print(pipeline.get_component("homo_data_split_0").get_summary())
  52. if __name__ == "__main__":
  53. parser = argparse.ArgumentParser("PIPELINE DEMO")
  54. parser.add_argument("-config", type=str,
  55. help="config file")
  56. args = parser.parse_args()
  57. if args.config is not None:
  58. main(args.config)
  59. else:
  60. main()