<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Pipeline Tutorial with HeteroSecureBoost
install
Pipeline is distributed along with fate_client.
bash
pip install fate_client
To use Pipeline, we need to first specify which FATE Flow Service to connect to. Once fate_client installed, one can find an cmd enterpoint name pipeline
Step1:  Assume we have a FATE Flow Service in 127.0.0.1
Step2:  Hetero SecureBoost Example
Before start a modeling task, data to be used should be uploaded. Please refer to this guide.
The pipeline package provides components to compose a FATE pipeline.
Step3:  Make a pipeline instance
Step4:  Define a Reader to load data
Step5:  Add a DataTransform component to parse raw data into Data Instance
Step6:  Add a Intersection component to perform PSI for hetero-scenario
Step7:  Now, we define the HeteroSecureBoost component. The following parameters will be set for all parties involved.
Step8:  To show the evaluation result, an "Evaluation" component is needed.
Step9:  Add components to pipeline, in order of execution
Step10:  Now, submit(fit) our pipeline
Step11:  Once training is done, trained model may be used for prediction. Optionally, save the trained pipeline for future use.
Step12:  First, deploy needed components from train pipeline
Step13:  Define new Reader components for reading prediction data
Step14:  Optionally, define new Evaluation component.
Step15:  Add components to predict pipeline in order of execution
Step16:  Then, run prediction job
<ASSISTANT_TASK:>
Python Code:
!pipeline --help
Explanation: Pipeline Tutorial with HeteroSecureBoost
install
Pipeline is distributed along with fate_client.
bash
pip install fate_client
To use Pipeline, we need to first specify which FATE Flow Service to connect to. Once fate_client installed, one can find an cmd enterpoint name pipeline:
End of explanation
!pipeline init --ip 127.0.0.1 --port 9380
Explanation: Assume we have a FATE Flow Service in 127.0.0.1:9380(defaults in standalone), then exec
End of explanation
from pipeline.backend.pipeline import PipeLine
from pipeline.component import Reader, DataTransform, Intersection, HeteroSecureBoost, Evaluation
from pipeline.interface import Data
Explanation: Hetero SecureBoost Example
Before start a modeling task, data to be used should be uploaded. Please refer to this guide.
The pipeline package provides components to compose a FATE pipeline.
End of explanation
pipeline = PipeLine() \
        .set_initiator(role='guest', party_id=9999) \
        .set_roles(guest=9999, host=10000)
Explanation: Make a pipeline instance:
- initiator: 
    * role: guest
    * party: 9999
- roles:
    * guest: 9999
    * host: 10000
End of explanation
reader_0 = Reader(name="reader_0")
# set guest parameter
reader_0.get_party_instance(role='guest', party_id=9999).component_param(
    table={"name": "breast_hetero_guest", "namespace": "experiment"})
# set host parameter
reader_0.get_party_instance(role='host', party_id=10000).component_param(
    table={"name": "breast_hetero_host", "namespace": "experiment"})
Explanation: Define a Reader to load data
End of explanation
data_transform_0 = DataTransform(name="data_transform_0")
# set guest parameter
data_transform_0.get_party_instance(role='guest', party_id=9999).component_param(
    with_label=True)
data_transform_0.get_party_instance(role='host', party_id=[10000]).component_param(
    with_label=False)
Explanation: Add a DataTransform component to parse raw data into Data Instance
End of explanation
intersect_0 = Intersection(name="intersect_0")
Explanation: Add a Intersection component to perform PSI for hetero-scenario
End of explanation
hetero_secureboost_0 = HeteroSecureBoost(name="hetero_secureboost_0",
                                         num_trees=5,
                                         bin_num=16,
                                         task_type="classification",
                                         objective_param={"objective": "cross_entropy"},
                                         encrypt_param={"method": "paillier"},
                                         tree_param={"max_depth": 3})
Explanation: Now, we define the HeteroSecureBoost component. The following parameters will be set for all parties involved.
End of explanation
evaluation_0 = Evaluation(name="evaluation_0", eval_type="binary")
Explanation: To show the evaluation result, an "Evaluation" component is needed.
End of explanation
pipeline.add_component(reader_0)
pipeline.add_component(data_transform_0, data=Data(data=reader_0.output.data))
pipeline.add_component(intersect_0, data=Data(data=data_transform_0.output.data))
pipeline.add_component(hetero_secureboost_0, data=Data(train_data=intersect_0.output.data))
pipeline.add_component(evaluation_0, data=Data(data=hetero_secureboost_0.output.data))
pipeline.compile();
Explanation: Add components to pipeline, in order of execution:
- data_transform_0 comsume reader_0's output data
- intersect_0 comsume data_transform_0's output data
- hetero_secureboost_0 consume intersect_0's output data
- evaluation_0 consume hetero_secureboost_0's prediciton result on training data
Then compile our pipeline to make it ready for submission.
End of explanation
pipeline.fit()
Explanation: Now, submit(fit) our pipeline:
End of explanation
pipeline.dump("pipeline_saved.pkl");
Explanation: Once training is done, trained model may be used for prediction. Optionally, save the trained pipeline for future use.
End of explanation
pipeline = PipeLine.load_model_from_file('pipeline_saved.pkl')
pipeline.deploy_component([pipeline.data_transform_0, pipeline.intersect_0, pipeline.hetero_secureboost_0]);
Explanation: First, deploy needed components from train pipeline
End of explanation
reader_1 = Reader(name="reader_1")
reader_1.get_party_instance(role="guest", party_id=9999).component_param(table={"name": "breast_hetero_guest", "namespace": "experiment"})
reader_1.get_party_instance(role="host", party_id=10000).component_param(table={"name": "breast_hetero_host", "namespace": "experiment"})
Explanation: Define new Reader components for reading prediction data
End of explanation
evaluation_0 = Evaluation(name="evaluation_0", eval_type="binary")
Explanation: Optionally, define new Evaluation component.
End of explanation
predict_pipeline = PipeLine()
predict_pipeline.add_component(reader_1)\
                .add_component(pipeline, 
                               data=Data(predict_input={pipeline.data_transform_0.input.data: reader_1.output.data}))\
                .add_component(evaluation_0, data=Data(data=pipeline.hetero_secureboost_0.output.data));
Explanation: Add components to predict pipeline in order of execution:
End of explanation
predict_pipeline.predict()
Explanation: Then, run prediction job
End of explanation
<END_TASK>