Ex 5.2: Fixed error calculation for cross validation.