pipeline-homo-sbt-regression-cv.py 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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": "breast_homo_guest", "namespace": f"experiment{namespace}"}
  32. host_train_data = {"name": "breast_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',
  40. party_id=guest).component_param(
  41. with_label=True,
  42. output_format="dense",
  43. label_type="float")
  44. data_transform_0.get_party_instance(
  45. role='host',
  46. party_id=host).component_param(
  47. with_label=True,
  48. output_format="dense",
  49. label_type="float")
  50. homo_secureboost_0 = HomoSecureBoost(name="homo_secureboost_0",
  51. num_trees=3,
  52. task_type='regression',
  53. objective_param={"objective": "lse"},
  54. tree_param={
  55. "max_depth": 3
  56. },
  57. cv_param={
  58. "need_cv": True,
  59. "shuffle": False,
  60. "n_splits": 5
  61. }
  62. )
  63. pipeline.add_component(reader_0)
  64. pipeline.add_component(data_transform_0, data=Data(data=reader_0.output.data))
  65. pipeline.add_component(homo_secureboost_0, data=Data(train_data=data_transform_0.output.data))
  66. pipeline.compile()
  67. pipeline.fit()
  68. if __name__ == "__main__":
  69. parser = argparse.ArgumentParser("PIPELINE DEMO")
  70. parser.add_argument("-config", type=str,
  71. help="config file")
  72. args = parser.parse_args()
  73. if args.config is not None:
  74. main(args.config)
  75. else:
  76. main()