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!

1 Like

Thank you Javier. i have solved that problem, and now i can generate confusion metrics, accuracy and loss curve. But now i am getting a new problem:
image

Hi @sejan16 , it’s great to hear that you got that working. About your new error, it seems that the last_round_metrics you are creating in line 44 is already of type float. With the ["accuracy"][-1] you are already getting the last round metrics, so i think the final [1] in line 44 might not be needed?

In case of doubt, the best is to add some print statements to see what’s wrong.

Thank you Brother. I will let you know my advancement of my work.

1 Like