from ailever.utils import source source('ST-0000')
time series
TS( N,N) - Simple Exponential Smoothing
import statsmodels.api as sm import statsmodels.tsa.api as smt import matplotlib.pyplot as plt # dataset target = sm.datasets.sunspots.load_pandas().data['SUNACTIVITY'] target.plot(marker='o', color='black', legend=True, figsize=(12,5)) # TS(N,N) : Simple Exponential Smoothing model = smt.SimpleExpSmoothing(target).fit(smoothing_level=0.9, optimized=False) model.fittedvalues.plot(style='--', color='blue', label=r'$\alpha=%s$'%model.model.params['smoothing_level']) forecast = model.forecast(24).rename(r'$\alpha=%s$'%model.model.params['smoothing_level']) forecast.plot(marker='o', color='blue') plt.legend() plt.show() # [smt.SimpleExpSmoothing] # initialization_method :(str) None, ‘estimated’, ‘heuristic’, ‘legacy-heuristic’, ‘known’ # initial_level:(float)
TS( A,N) - Holt Linear Method
import statsmodels.api as sm import statsmodels.tsa.api as smt import matplotlib.pyplot as plt # dataset target = sm.datasets.sunspots.load_pandas().data['SUNACTIVITY'] + 10 target.plot(marker='o', color='black', legend=True, figsize=(12,5)) # Holt TS(A,N) model = smt.Holt(target).fit() model.fittedvalues.plot(style='--', color='blue', label=r'$\alpha=%s$'%model.model.params['smoothing_level']) forecast = model.forecast(24).rename(r'$\alpha=%s$'%model.model.params['smoothing_level']) forecast.plot(marker='o', color='blue') plt.legend() plt.show() # [smt.Holt] # exponential :(bool) # damped_trend :(bool) # initialization_method :(str) None, ‘estimated’, ‘heuristic’, ‘legacy-heuristic’, ‘known’ # initial_level :(float) # initial_trend :(float)
TS(Ad,N) - Additive Damped Trend Method
import statsmodels.api as sm import statsmodels.tsa.api as smt import matplotlib.pyplot as plt # dataset target = sm.datasets.sunspots.load_pandas().data['SUNACTIVITY'] + 10 target.plot(marker='o', color='black', legend=True, figsize=(12,5)) # Holt TS(Ad,N) model = smt.Holt(target, exponential=True, damped_trend=True).fit() model.fittedvalues.plot(style='--', color='blue', label=r'$\alpha=%s$'%model.model.params['smoothing_level']) forecast = model.forecast(24).rename(r'$\alpha=%s$'%model.model.params['smoothing_level']) forecast.plot(marker='o', color='blue') plt.legend() plt.show() # [smt.Holt] # exponential :(bool) # damped_trend :(bool) # initialization_method :(str) None, ‘estimated’, ‘heuristic’, ‘legacy-heuristic’, ‘known’ # initial_level :(float) # initial_trend :(float)
TS( A,A) - Additive Holt-Winters' Method
import statsmodels.api as sm import statsmodels.tsa.api as smt import matplotlib.pyplot as plt # dataset target = sm.datasets.sunspots.load_pandas().data['SUNACTIVITY'] + 10 target.plot(marker='o', color='black', legend=True, figsize=(12,5)) # Holt-Winter's TS(A,A) model = smt.ExponentialSmoothing(target, seasonal_periods=24, trend='add', seasonal='add', damped_trend=False).fit(use_boxcox=True) model.fittedvalues.plot(style='--', color='blue', label=r'$\alpha=%s$'%model.model.params['smoothing_level']) forecast = model.forecast(24).rename(r'$\alpha=%s$'%model.model.params['smoothing_level']) forecast.plot(marker='o', color='blue') plt.legend() plt.show() # [smt.ExponentialSmoothing] # trend :(str) “add”, “mul”, “additive”, “multiplicative”, None # damped_trend :(bool) # seasonal :(str) “add”, “mul”, “additive”, “multiplicative”, None # initialization_method :(str) None, ‘estimated’, ‘heuristic’, ‘legacy-heuristic’, ‘known’ # initial_level :(float) # initial_trend :(float) # initial_seasonal :(array_like) # use_boxcox : {True, False, ‘log’, float} # bounds :(dict)[str, tuple[float, float]] # dates :(array_like) of datetime # freq :(str) ‘B’, ‘D’, ‘W’, ‘M’, ‘A’, or ‘Q’ # missing :(str) ‘none’, ‘drop’, and ‘raise’
TS( A,M) - Multiplicative Holt-Winters' Method
import statsmodels.api as sm import statsmodels.tsa.api as smt import matplotlib.pyplot as plt # dataset target = sm.datasets.sunspots.load_pandas().data['SUNACTIVITY'] + 10 target.plot(marker='o', color='black', legend=True, figsize=(12,5)) # Holt-Winter's TS(A,M) model = smt.ExponentialSmoothing(target, seasonal_periods=24, trend='add', seasonal='mul', damped_trend=False).fit(use_boxcox=True) model.fittedvalues.plot(style='--', color='blue', label=r'$\alpha=%s$'%model.model.params['smoothing_level']) forecast = model.forecast(24).rename(r'$\alpha=%s$'%model.model.params['smoothing_level']) forecast.plot(marker='o', color='blue') plt.legend() plt.show() # [smt.ExponentialSmoothing] # trend :(str) “add”, “mul”, “additive”, “multiplicative”, None # damped_trend :(bool) # seasonal :(str) “add”, “mul”, “additive”, “multiplicative”, None # initialization_method :(str) None, ‘estimated’, ‘heuristic’, ‘legacy-heuristic’, ‘known’ # initial_level :(float) # initial_trend :(float) # initial_seasonal :(array_like) # use_boxcox : {True, False, ‘log’, float} # bounds :(dict)[str, tuple[float, float]] # dates :(array_like) of datetime # freq :(str) ‘B’, ‘D’, ‘W’, ‘M’, ‘A’, or ‘Q’ # missing :(str) ‘none’, ‘drop’, and ‘raise’
TS(Ad,M) - Holt-Winters Damped Method
import statsmodels.api as sm import statsmodels.tsa.api as smt import matplotlib.pyplot as plt # dataset target = sm.datasets.sunspots.load_pandas().data['SUNACTIVITY'] + 10 target.plot(marker='o', color='black', legend=True, figsize=(12,5)) # Holt-Winter's TS(Ad,M) model = smt.ExponentialSmoothing(target, seasonal_periods=24, trend='add', seasonal='mul', damped_trend=True).fit(use_boxcox=True) model.fittedvalues.plot(style='--', color='blue', label=r'$\alpha=%s$'%model.model.params['smoothing_level']) forecast = model.forecast(24).rename(r'$\alpha=%s$'%model.model.params['smoothing_level']) forecast.plot(marker='o', color='blue') plt.legend() plt.show() # [smt.ExponentialSmoothing] # trend :(str) “add”, “mul”, “additive”, “multiplicative”, None # damped_trend :(bool) # seasonal :(str) “add”, “mul”, “additive”, “multiplicative”, None # initialization_method :(str) None, ‘estimated’, ‘heuristic’, ‘legacy-heuristic’, ‘known’ # initial_level : (float) # initial_trend : (float) # initial_seasonal : (array_like) # use_boxcox : {True, False, ‘log’, float} # bounds : (dict)[str, tuple[float, float]] # dates : (array_like) of datetime # freq : (str) ‘B’, ‘D’, ‘W’, ‘M’, ‘A’, or ‘Q’ # missing : (str) ‘none’, ‘drop’, and ‘raise’
ETS(A,N,N) - Simple Exponential Smoothing with Additive Errors
import statsmodels.api as sm import statsmodels.tsa.api as smt import matplotlib.pyplot as plt # dataset target = sm.datasets.sunspots.load_pandas().data['SUNACTIVITY'] + 10 target.plot(marker='o', color='black', legend=True, figsize=(12,5)) # ETS(A,N,N) model = smt.ETSModel(target, seasonal_periods=24, error='add', trend=None, seasonal=None, damped_trend=False).fit(use_boxcox=True) model.fittedvalues.plot(style='--', color='blue', label=r'$ETS$') forecast = model.forecast(24).rename(r'$ETS$') forecast.plot(marker='o', color='blue') plt.legend() plt.show() # [smt.ETSModel] # error :(str) “add”-default or “mul”. # trend :(str) “add”, “mul”, or None-default # damped_trend :(bool) True, False-Default # seasonal :(str) “add”, “mul”, or None-default # seasonal_periods :(int) # initialization_method :(str) None, ‘estimated’-default, ‘heuristic’, ‘known’ # initial_level : (float) # initial_trend : (float) # initial_seasonal : (array_like) # use_boxcox : {True, False, ‘log’, float} # bounds : (dict)[str, tuple[float, float]] # - “smoothing_level” # - “smoothing_trend” # - “smoothing_seasonal” # - “damping_trend” # - “initial_level” # - “initial_trend” # - “initial_seasonal.0”, …, “initial_seasonal.(m-1)” # dates : (array_like) of datetime # freq : (str) ‘B’, ‘D’, ‘W’, ‘M’, ‘A’, or ‘Q’ # missing : (str) ‘none’, ‘drop’, and ‘raise’
ETS(M,N,N) - Simple Exponential Smoothing with Multiplicative Errors
import statsmodels.api as sm import statsmodels.tsa.api as smt import matplotlib.pyplot as plt # dataset target = sm.datasets.sunspots.load_pandas().data['SUNACTIVITY'] + 10 target.plot(marker='o', color='black', legend=True, figsize=(12,5)) # ETS(M,N,N) model = smt.ETSModel(target, seasonal_periods=24, error='mul', trend=None, seasonal=None, damped_trend=False).fit(use_boxcox=True) model.fittedvalues.plot(style='--', color='blue', label=r'$ETS$') forecast = model.forecast(24).rename(r'$ETS$') forecast.plot(marker='o', color='blue') plt.legend() plt.show() # [smt.ETSModel] # error :(str) “add”-default or “mul”. # trend :(str) “add”, “mul”, or None-default # damped_trend :(bool) True, False-Default # seasonal :(str) “add”, “mul”, or None-default # seasonal_periods :(int) # initialization_method :(str) None, ‘estimated’-default, ‘heuristic’, ‘known’ # initial_level : (float) # initial_trend : (float) # initial_seasonal : (array_like) # use_boxcox : {True, False, ‘log’, float} # bounds : (dict)[str, tuple[float, float]] # - “smoothing_level” # - “smoothing_trend” # - “smoothing_seasonal” # - “damping_trend” # - “initial_level” # - “initial_trend” # - “initial_seasonal.0”, …, “initial_seasonal.(m-1)” # dates : (array_like) of datetime # freq : (str) ‘B’, ‘D’, ‘W’, ‘M’, ‘A’, or ‘Q’ # missing : (str) ‘none’, ‘drop’, and ‘raise’
ETS(A,A,N) - Holt’s Linear Method with Additive Errors
import statsmodels.api as sm import statsmodels.tsa.api as smt import matplotlib.pyplot as plt # dataset target = sm.datasets.sunspots.load_pandas().data['SUNACTIVITY'] + 10 target.plot(marker='o', color='black', legend=True, figsize=(12,5)) # ETS(A,A,N) model = smt.ETSModel(target, seasonal_periods=24, error='add', trend='add', seasonal=None, damped_trend=False).fit(use_boxcox=True) model.fittedvalues.plot(style='--', color='blue', label=r'$ETS$') forecast = model.forecast(24).rename(r'$ETS$') forecast.plot(marker='o', color='blue') plt.legend() plt.show() # [smt.ETSModel] # error :(str) “add”-default or “mul”. # trend :(str) “add”, “mul”, or None-default # damped_trend :(bool) True, False-Default # seasonal :(str) “add”, “mul”, or None-default # seasonal_periods :(int) # initialization_method :(str) None, ‘estimated’-default, ‘heuristic’, ‘known’ # initial_level : (float) # initial_trend : (float) # initial_seasonal : (array_like) # use_boxcox : {True, False, ‘log’, float} # bounds : (dict)[str, tuple[float, float]] # - “smoothing_level” # - “smoothing_trend” # - “smoothing_seasonal” # - “damping_trend” # - “initial_level” # - “initial_trend” # - “initial_seasonal.0”, …, “initial_seasonal.(m-1)” # dates : (array_like) of datetime # freq : (str) ‘B’, ‘D’, ‘W’, ‘M’, ‘A’, or ‘Q’ # missing : (str) ‘none’, ‘drop’, and ‘raise’
ETS(M,A,N) - Holt’s Linear Method with Multiplicative Errors
import statsmodels.api as sm import statsmodels.tsa.api as smt import matplotlib.pyplot as plt # dataset target = sm.datasets.sunspots.load_pandas().data['SUNACTIVITY'] + 10 target.plot(marker='o', color='black', legend=True, figsize=(12,5)) # ETS(M,A,N) model = smt.ETSModel(target, seasonal_periods=24, error='mul', trend='add', seasonal=None, damped_trend=False).fit(use_boxcox=True) model.fittedvalues.plot(style='--', color='blue', label=r'$ETS$') forecast = model.forecast(24).rename(r'$ETS$') forecast.plot(marker='o', color='blue') plt.legend() plt.show() # [smt.ETSModel] # error :(str) “add”-default or “mul”. # trend :(str) “add”, “mul”, or None-default # damped_trend :(bool) True, False-Default # seasonal :(str) “add”, “mul”, or None-default # seasonal_periods :(int) # initialization_method :(str) None, ‘estimated’-default, ‘heuristic’, ‘known’ # initial_level : (float) # initial_trend : (float) # initial_seasonal : (array_like) # use_boxcox : {True, False, ‘log’, float} # bounds : (dict)[str, tuple[float, float]] # - “smoothing_level” # - “smoothing_trend” # - “smoothing_seasonal” # - “damping_trend” # - “initial_level” # - “initial_trend” # - “initial_seasonal.0”, …, “initial_seasonal.(m-1)” # dates : (array_like) of datetime # freq : (str) ‘B’, ‘D’, ‘W’, ‘M’, ‘A’, or ‘Q’ # missing : (str) ‘none’, ‘drop’, and ‘raise’
TITLE2
Reference