pipeline-homo-recursive-binning-select-cols.py 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. import json
  18. from pipeline.backend.pipeline import PipeLine
  19. from pipeline.component import DataTransform
  20. from pipeline.component import HomoFeatureBinning
  21. from pipeline.component import Reader
  22. from pipeline.interface import Data
  23. from pipeline.utils.tools import load_job_config
  24. def main(config="../../config.yaml", namespace=""):
  25. # obtain config
  26. if isinstance(config, str):
  27. config = load_job_config(config)
  28. parties = config.parties
  29. guest = parties.guest[0]
  30. host = parties.host[0]
  31. arbiter = parties.arbiter[0]
  32. guest_train_data = {"name": "breast_homo_guest", "namespace": f"experiment{namespace}"}
  33. host_train_data = {"name": "breast_homo_host", "namespace": f"experiment{namespace}"}
  34. # initialize pipeline
  35. pipeline = PipeLine()
  36. # set job initiator
  37. pipeline.set_initiator(role='guest', party_id=guest)
  38. # set participants information
  39. pipeline.set_roles(guest=guest, host=host, arbiter=arbiter)
  40. # define Reader components to read in data
  41. reader_0 = Reader(name="reader_0")
  42. # configure Reader for guest
  43. reader_0.get_party_instance(role='guest', party_id=guest).component_param(table=guest_train_data)
  44. # configure Reader for host
  45. reader_0.get_party_instance(role='host', party_id=host).component_param(table=host_train_data)
  46. # define DataTransform components
  47. data_transform_0 = DataTransform(
  48. name="data_transform_0",
  49. with_label=True,
  50. output_format="dense") # start component numbering at 0
  51. homo_binning_0 = HomoFeatureBinning(name='homo_binning_0', sample_bins=1000, method="recursive_query",
  52. bin_indexes=[0, 2, 4, 6])
  53. # add components to pipeline, in order of task execution
  54. pipeline.add_component(reader_0)
  55. pipeline.add_component(data_transform_0, data=Data(data=reader_0.output.data))
  56. # set data input sources of intersection components
  57. pipeline.add_component(homo_binning_0, data=Data(data=data_transform_0.output.data))
  58. # compile pipeline once finished adding modules, this step will form conf and dsl files for running job
  59. pipeline.compile()
  60. # fit model
  61. pipeline.fit()
  62. # query component summary
  63. # print(json.dumps(pipeline.get_component("homo_binning_0").get_summary(), indent=4, ensure_ascii=False))
  64. if __name__ == "__main__":
  65. parser = argparse.ArgumentParser("PIPELINE DEMO")
  66. parser.add_argument("-config", type=str,
  67. help="config file")
  68. args = parser.parse_args()
  69. if args.config is not None:
  70. main(args.config)
  71. else:
  72. main()