Question: Define a new Python function smoothing(ts, alpha) to implement simple exponential smoothing. The input ts will be a 1-D numerical array (the vector x from

Define a new Python function smoothing(ts, alpha)  to implement simple exponential smoothing. The input ts will be a 1-D numerical array (the vector x from the formula above), and the input alpha (the scalar α from the formula above) will be a floating point number between 0 and 1.
n the math notation xt is ts[t], and $\hat{x_t}$ is our prediction for xt:
Initial conditions
s0 = x0. This is our initial guess.
$\hat{x_0}$ is undefined. We can't call the first guess a prediction since it's actually the first observation.
For t > 0
st = α(xt) + (1 − α)st − 1
$\hat{x_t} = s_{t-1}$
When α is closer to 1 the model is more sensitive to recent observations. When α is closer to 0 the model is more sensitive to past observations.
The function should implement the formula above and return the vector x̂ as a 1-D array.
Since $\hat{x_0}$ is undefined, the first element in your result should be np.nan.
Since x̂n + 1 is well-defined for x ∈ ℛn, your result should have exactly one more element than the input ts.
Input example:
1_D_array = np.array([100., 105., 120., 110., 115.])
Execute the function :
print(smoothing(1_D_array , 0.5))
Output example:
[ nan 100. 102.5 111.25 110.625 112.8125].

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Algorithms Questions!