A beach kiosk rents out kites. For several days it wrote down the average wind speed (km/h) and the number of kites rented. Position i of wind and position i of kites belong to the same day.
Write kite_covariance(wind, kites) that returns a tuple (population, sample):
populationis the covariance of the pairs with the sum of products of deviations divided byn,sampleis the same sum divided byn - 1, orNonewhen there is only one day.
Both are floats. A positive covariance means windy days tend to be busy days; a negative one means the opposite.
The setup provides kite_days(n, seed), which returns a random pair of lists (wind, kites) of length n for experiments.
Examples
Input: wind = [10, 20, 30], kites = [4, 9, 8]
Output: (13.333333333333334, 20.0)
Explanation: the means are 20 and 7. The deviations are (-10, -3), (0, 2), (10, 1),
their products 30, 0 and 10, which sum to 40. 40 / 3 = 13.33 and 40 / 2 = 20.
Input: wind = [12], kites = [5]
Output: (0.0, None)
Constraints
1 <= len(wind) == len(kites) <= 10**5- values are integers or floats with absolute value at most
10**4 - floats are compared with a tolerance of
1e-6
Goals
- Compute the covariance of two paired lists from deviations about the means
- Give both the population (divide by n) and the sample (divide by n - 1) version
- Read the sign of a covariance as the direction of a relationship