Found this post searching specifically for GA selection techniques, just wanted to say that the choices() is great, but it's really not a roulette selection, it's just selecting 2 candidates with probability being equal to the fitness. In order to make a roulette wheel selection, you have to be a little more complex than that, mainly:
Very simple code:
import numpy as np
fitness = np.random.rand(50)
total_fitness = sum(fitness)
weights = fitness/total_fitness
r = np.random.rand()
acc = 0
idx = -1
while acc < r:
idx += 1
acc += weights[idx]
This is a very simple algorithm, and there are other implementations (way faster and better), but it shows the point ;).
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.