def calculate_fitness(k, delay, y, u, dt):
    """
    Find how well the function fits the data
    """
    delay_periods = int(delay / dt)
    e = y - k * u.shift(delay_periods)
    fit = 1 - (e.var() / y.var()) ** 2
    return fit
