pipeline-homo-sbt-multi-cv.py 3.3 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. from pipeline.backend.pipeline import PipeLine
  18. from pipeline.component import DataTransform
  19. from pipeline.component.homo_secureboost import HomoSecureBoost
  20. from pipeline.component.reader import Reader
  21. from pipeline.interface.data 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. arbiter = parties.arbiter[0]
  31. guest_train_data = {"name": "vehicle_scale_homo_guest", "namespace": f"experiment{namespace}"}
  32. host_train_data = {"name": "vehicle_scale_homo_host", "namespace": f"experiment{namespace}"}
  33. pipeline = PipeLine().set_initiator(role='guest', party_id=guest).set_roles(guest=guest, host=host, arbiter=arbiter)
  34. data_transform_0 = DataTransform(name="data_transform_0")
  35. reader_0 = Reader(name="reader_0")
  36. reader_0.get_party_instance(role='guest', party_id=guest).component_param(table=guest_train_data)
  37. reader_0.get_party_instance(role='host', party_id=host).component_param(table=host_train_data)
  38. data_transform_0.get_party_instance(
  39. role='guest', party_id=guest).component_param(
  40. with_label=True, output_format="dense")
  41. data_transform_0.get_party_instance(
  42. role='host', party_id=host).component_param(
  43. with_label=True, output_format="dense")
  44. homo_secureboost_0 = HomoSecureBoost(name="homo_secureboost_0",
  45. num_trees=3,
  46. task_type='classification',
  47. objective_param={"objective": "cross_entropy"},
  48. tree_param={
  49. "max_depth": 3
  50. },
  51. cv_param={
  52. "need_cv": True,
  53. "shuffle": False,
  54. "n_splits": 5
  55. }
  56. )
  57. pipeline.add_component(reader_0)
  58. pipeline.add_component(data_transform_0, data=Data(data=reader_0.output.data))
  59. pipeline.add_component(homo_secureboost_0, data=Data(train_data=data_transform_0.output.data))
  60. pipeline.compile()
  61. pipeline.fit()
  62. if __name__ == "__main__":
  63. parser = argparse.ArgumentParser("PIPELINE DEMO")
  64. parser.add_argument("-config", type=str,
  65. help="config file")
  66. args = parser.parse_args()
  67. if args.config is not None:
  68. main(args.config)
  69. else:
  70. main()