Balanced accuracy averages per-class recall, giving each class equal weight. It is useful when a random evaluation batch may contain uneven class representation and ordinary accuracy could be biased. section 10.4
A practical evaluation flow uses balanced accuracy as the genome’s fitness:
- Sample a random batch of 256 images and labels. section 10.4
- Flatten each 28×28 image into 784 inputs and activate the network. section 10.4
- Apply SoftMax and argmax to collect predicted classes, then score predictions against labels. section 10.4
NEAT genome fitness
Use sklearn.metrics.balanced_accuracy_score(ys, yis) after collecting true labels and predicted classes; assign the result to genome.fitness. section 10.4
Listing 10.17 EDL_10_4_NEAT_Images.ipynb: Evaluating a genome fitness
from sklearn.metrics import balanced_accuracy_score yis = [] for x, y in zip(xs,ys): #1 x = np.reshape(x, (784,)) #2 output = net.activate(x) #3 class_ = softmax(output) #3 yis.append(np.argmax(class_)) #3 print(ys, yis) fitness = balanced_accuracy_score(ys, yis) #4 print(fitness)
Inspect the compact implementation that converts network outputs into class predictions and computes the score. section 10.4

