This file contains 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
from scipy.stats import kruskal | |
def seasonality_test(series): | |
seasoanl = False | |
idx = np.arange(len(series.index)) % 12 | |
H_statistic, p_value = kruskal(series, idx) | |
if p_value <= 0.05: | |
seasonal = True | |
return seasonal |
This file contains 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
'''Helper Funciton to check if seasonality is present''' | |
def seasonality_test(self, series): | |
self.__seasonal__ = False | |
idx = np.arange(len(series.index)) % 12 | |
H_statistic, p_value = kruskal(series, idx) | |
if p_value <= 0.05: | |
self.__seasonal__ = True | |
return seasonal | |
'''Helper Function to check if trend is present''' |
This file contains 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 ADF_test (self, series): | |
adf = adfuller(series) | |
print('ADF test') | |
print("\tADF Statistic: {}\n".format (adf[0])) | |
print("\tp-value: {}\n".format (adf[1])) #Since the p-value is far from 0.05 it not stationary | |
print ("\tCritical values : \n") | |
for key, value in adf[4].items(): | |
print("\t\t{} : {}\n".format(key, value)) |
This file contains 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
class model: | |
'''Attributes of the class are the same as the ones the describe any time series : Trend, Seasonality; additionally | |
Root-Mean-Squared Error and Model type (additive/multiplicative) are also taken into consideration''' | |
def __init__(self, series, rmse = None, model = None): | |
if rmse == None: | |
self.rmse : float = float('inf') | |
else: |