Code Challenges
- FizzBuzz
- Mean of a List
- Median of a List
- Variance of a List
- Standard Deviation of a List
- Sample Covariance
- Correlation Coefficient
- Simple Linear Regression
- Vector Dot Product
- Random Matrix
- 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:
Where:
x
andy
represent our two lists (random variables)n
is the sample sizex_bar
is the mean of thex
variable listy_bar
is the mean of they
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