def run_experiment(train_data, test_data, batch_size, learning_rate, epoch): print("hyper-parameters:") print("batch size: {0}".format(batch_size)) print("learning rate: {0}".format(learning_rate)) Xa_train, Xb_train, y_train = train_data Xa_test, Xb_test, y_test = test_data print("################################ Wire Federated Models ############################") # create local models for both party A and party B party_a_local_model = LocalModel(input_dim=Xa_train.shape[1], output_dim=10, learning_rate=learning_rate) party_b_local_model = LocalModel(input_dim=Xb_train.shape[1], output_dim=20, learning_rate=learning_rate) # create lr model for both party A and party B. Each party has a part of the whole lr model and only party A has # the bias since only party A has the labels. party_a_dense_model = DenseModel(party_a_local_model.get_output_dim(), 1, learning_rate=learning_rate, bias=True) party_b_dense_model = DenseModel(party_b_local_model.get_output_dim(), 1, learning_rate=learning_rate, bias=False) partyA = VFLGuestModel(local_model=party_a_local_model) partyA.set_dense_model(party_a_dense_model) partyB = VFLHostModel(local_model=party_b_local_model) partyB.set_dense_model(party_b_dense_model) party_B_id = "B" federatedLearning = VerticalMultiplePartyLogisticRegressionFederatedLearning(partyA) federatedLearning.add_party(id=party_B_id, party_model=partyB) federatedLearning.set_debug(is_debug=False) print("################################ Train Federated Models ############################") fl_fixture = FederatedLearningFixture(federatedLearning) # only party A has labels (i.e., Y), other parties only have features (e.g., X). # 'party_list' stores X for all other parties. # Since this is two-party VFL, 'party_list' only stores the X of party B. train_data = {federatedLearning.get_main_party_id(): {"X": Xa_train, "Y": y_train}, "party_list": {party_B_id: Xb_train}} test_data = {federatedLearning.get_main_party_id(): {"X": Xa_test, "Y": y_test}, "party_list": {party_B_id: Xb_test}} fl_fixture.fit(train_data=train_data, test_data=test_data, epochs=epoch, batch_size=batch_size)
def run_experiment(train_data, test_data, batch_size, learning_rate, epoch): Xa_train, Xb_train, Xc_train, y_train = train_data Xa_test, Xb_test, Xc_test, y_test = test_data print("################################ Wire Federated Models ############################") # create local models for both party A, party B and party C party_a_local_model = LocalModel(input_dim=Xa_train.shape[1], output_dim=60, learning_rate=learning_rate) party_b_local_model = LocalModel(input_dim=Xb_train.shape[1], output_dim=60, learning_rate=learning_rate) party_c_local_model = LocalModel(input_dim=Xc_train.shape[1], output_dim=60, learning_rate=learning_rate) # create lr model for both party A, party B and party C. Each party has a part of the whole lr model and # only party A has the bias since only party A has the labels. party_a_dense_model = DenseModel(party_a_local_model.get_output_dim(), 1, learning_rate=learning_rate, bias=True) party_b_dense_model = DenseModel(party_b_local_model.get_output_dim(), 1, learning_rate=learning_rate, bias=False) party_c_dense_model = DenseModel(party_c_local_model.get_output_dim(), 1, learning_rate=learning_rate, bias=False) partyA = VFLGuestModel(local_model=party_a_local_model) partyA.set_dense_model(party_a_dense_model) partyB = VFLHostModel(local_model=party_b_local_model) partyB.set_dense_model(party_b_dense_model) partyC = VFLHostModel(local_model=party_c_local_model) partyC.set_dense_model(party_c_dense_model) party_B_id = "B" party_C_id = "C" federatedLearning = VerticalMultiplePartyLogisticRegressionFederatedLearning(partyA) federatedLearning.add_party(id=party_B_id, party_model=partyB) federatedLearning.add_party(id=party_C_id, party_model=partyC) print("################################ Train Federated Models ############################") fl_fixture = FederatedLearningFixture(federatedLearning) train_data = {federatedLearning.get_main_party_id(): {"X": Xa_train, "Y": y_train}, "party_list": {party_B_id: Xb_train, party_C_id: Xc_train}} test_data = {federatedLearning.get_main_party_id(): {"X": Xa_test, "Y": y_test}, "party_list": {party_B_id: Xb_test, party_C_id: Xc_test}} fl_fixture.fit(train_data=train_data, test_data=test_data, epochs=epoch, batch_size=batch_size)