Home > front end >  How to compute the seasonality in python?
How to compute the seasonality in python?

Time:04-22

I have to computer the seasonality, but my graph gives me the wrong result. The seasonality in this dataset is quarterly (frequency of 4 months) and with an amplitude of 1.2. I would appreciate and be extremely thankful for any help!

How it should look like: enter image description here

My graph: enter image description here

import numpy as np

x_axis = np.arange(0, 200)
seasonality = np.zeros(len(x_axis))

for i, _ in enumerate(x_axis):
    seasonality[i] = 1.2 * np.sin(2 * np.pi * x_axis[i] / 4)

plt.figure(figsize=(14,5))
plt.plot(x_axis[0:13], seasonality[0:13])

This code was used by the professor so it is correct. But the example he used was different. Maybe it is the period that is incorrect.

CodePudding user response:

You don't have enough Xs to have a smooth curve. Use enter image description here

  • Related