All problems
Exponentially Weighted Mean
Problem
Return the final exponentially weighted mean with smoothing factor alpha: y_0 = data[0] and y_t = alpha*x_t + (1-alpha)*y_(t-1). Return 0.0 for empty input.
Hint
Loop once, updating y from the previous value.
Test cases
case 1
in: [[1,2,3,4,5],0.5]
expected: 4.0625
case 2
in: [[10,20,30],0.5]
expected: 22.5
case 3
in: [[5],0.3]
expected: 5
case 4
in: [[],0.5]
expected: 0
case 5
in: [[1,1,1],0.9]
expected: 1
Starter codePython
def ewma(data, alpha):
# Your code here
pass5 test cases · run your code against them in the editor