Created
August 24, 2019 00:26
-
-
Save kperry2215/90119d522a9115a868e18c30f9ae16d6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def decompose_time_series(series, desired_frequency): | |
""" | |
Perform STL decomposition on the time series. | |
Arguments: | |
series: Pandas series. Time series sequence that we wish to decompose. | |
desired_frequency: Integer. Time frequency of the series. If we want to detect | |
a yearly trend, we'd set the value equal to 365. | |
Outputs: | |
Plot of time series STL decomposition. | |
""" | |
result = seasonal_decompose(series, model='additive', freq=desired_frequency) | |
result.plot() | |
plt.show() | |
##EXECUTE IN MAIN BLOCK | |
#APPLY S-ESD ALGORITHM TO DETECT ANOMALIES | |
#Decompose time series on a yearly interval | |
#Set Date as index for the time series | |
gasoline_price_df.index=gasoline_price_df['Date'] | |
decompose_time_series(series=gasoline_price_df['Gasoline_Price'], | |
desired_frequency=365) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment