-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
55 lines (48 loc) · 1.49 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import flwr as fl
from flwr.server.strategy import FedXgbBagging
import matplotlib.pyplot as plt
import numpy as np
import time
# FL experimental settings
pool_size = 4
num_rounds = 20
num_clients_per_round = 4
num_evaluate_clients = 4
x=np.arange(1,num_rounds+1)
y=[]
time_taken=[]
def evaluate_metrics_aggregation(eval_metrics):
"""Return an aggregated metric (AUC) for evaluation."""
total_num = sum([num for num, _ in eval_metrics])
auc_aggregated = (
sum([metrics["AUC"] * num for num, metrics in eval_metrics]) / total_num
)
metrics_aggregated = {"AUC": auc_aggregated}
y.append(auc_aggregated)
print("\nAccuracy Score : ",auc_aggregated)
print("\n")
return metrics_aggregated
# Define strategy
strategy = FedXgbBagging(
fraction_fit=(float(num_clients_per_round) / pool_size),
min_fit_clients=num_clients_per_round,
min_available_clients=pool_size,
min_evaluate_clients=num_evaluate_clients,
fraction_evaluate=1.0,
evaluate_metrics_aggregation_fn=evaluate_metrics_aggregation,
)
start_time = time.time()
# Start Flower server
fl.server.start_server(
server_address="0.0.0.0:8085",
config=fl.server.ServerConfig(num_rounds=num_rounds),
strategy=strategy,
)
time_taken.append(time.time() - start_time)
print("Time taken:", time_taken[0], "seconds")
plt.plot(x,y,color='red')
plt.grid(color="green",linewidth=0.5,linestyle='--')
plt.xlabel('number of epoch')
plt.ylabel('Accuracy score')
plt.title('Federated Learning')
plt.show()