• Save
  • Run All Cells
  • Clear All Output
  • Runtime
  • Download
  • Difficulty Rating

Loading Runtime

Create a function called sample_covariance.

This function will be passed two lists of numbers of equal length and should return the sample covariance of the two lists.

As a reminder, the equation for sample covariance is as follows:

Sample Covariance Equation

Where:

  • x and y represent our two lists (random variables)
  • n is the sample size
  • x_bar is the mean of the x variable list
  • y_bar is the mean of the y variable list
  • (x_i - x_bar)(y_i - y_bar) represents finding the product of the two deviations (which we will calculate for each pair of values across the two lists in an element-wise fashion)

The final number that is returned by your function must be accurate to two decimal places, but does not need to be rounded to two decimal places.


Example:

sample_covariance([3,6,8,4,5,9], [8,5,3,0,4,3])

Returns: -1.833333333333333

Reset Code