Skip to content

Instantly share code, notes, and snippets.

View Knk00's full-sized avatar
🏠
Working from home

Knk00

🏠
Working from home
View GitHub Profile
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
'''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'''
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))
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: