getting an error called "TypeError: argument of type 'History' is not iterable""

Hi , i am an undergrad student from Bangladesh. I am working on a project and trying to classify brain tumor using federated learning. I choose flower framework for this and developed a code. During evaluating the performance of the updated local model on the test dataset (X_test , y_test ) to determine its accuracy, its showing an error.
##HERE IS THE CODE THAT I AM USING FOR SIMULATION

##HERE IS THE RESULT

##HERE IS THE CODE THAT I AM USING FOR PERFORMANCE EVALUATION

AND PROVIDING THIS ERROR MESSAGE

can you help me to resolve this problem. If you need i can share my code.

2 Likes

Hi @sejan16, the History object indeed is not iterable. You’ll need to access one of its attributes that are iterable. For example, to access the centralized accuracy you’d do:

   history = fl.simulation.start_simulation(...)

   # extract centralized accuracy
   cen_accuracy = history.metrics_centralized["accuracy"] # <-- this is a list of tuples

  # then you can create a simple line plot like this
  import matplotlib.pyplot as plt
  round_index = [idx for idx, _ in cen_accuracy]
  global_acc = [acc for _, acc in cen_accuracy]
  plt.plot(round_index, global_acc)

I believe something like the above should do. Let me know if it works!