def damped(data,  forecast_length):
    fitted_model = Holt(data, damped=True).fit()
    prediction = fitted_model.predict(0, len(data) + forecast_length - 1)
    params = fitted_model.params
    params['initial_seasons'] = params['initial_seasons'].tolist()
    return prediction, params
def MAPE(pred, org):
    temp = np.abs((pred - org)) * 100 / org
    return np.mean(temp)


#MAPE Mean Absolute Percentage Error (Lower is better)
#Subtract MAPE from 100 to provide accuracy in terms of percentage

# Simple Exponential Method
ses_model = SimpleExpSmoothing(Train["Passengers"]).fit()
pred_ses = ses_model.predict(start=Test.index[0], end=Test.index[-1])
se_MAPE = MAPE(pred_ses, Test.Passengers)  # 7.846321

# Holt method
hw_model = Holt(Train["Passengers"]).fit()
pred_hw = hw_model.predict(start=Test.index[0], end=Test.index[-1])
hw_MAPE = MAPE(pred_hw, Test.Passengers)  # 7.261176729658341

# Holts winter exponential smoothing with additive seasonality and additive trend
hwe_model_add_add = ExponentialSmoothing(Train["Passengers"],
                                         seasonal="add",
                                         trend="add",
                                         seasonal_periods=12,
                                         damped=True).fit()
pred_hwe_add_add = hwe_model_add_add.predict(start=Test.index[0],
                                             end=Test.index[-1])
hwe_MAPE = MAPE(pred_hwe_add_add, Test.Passengers)  # 4.500954

# Holts winter exponential smoothing with multiplicative seasonality and additive trend
hwe_model_mul_add = ExponentialSmoothing(Train["Passengers"],
                                         seasonal="mul",
示例#3
0
Train = sales.head(36)
Test = sales.tail(6)
model = []
mape = []

# Simple Exponential Smoothing Method
ses_model = SimpleExpSmoothing(Train["Sales"]).fit()
pred_ses = ses_model.predict(start=Test.index[0], end=Test.index[-1])
mape_ses = np.mean(np.abs((Test["Sales"] - pred_ses) / Test["Sales"])) * 100
model.append("Simple Exponential")
mape.append(mape_ses)

# Holts method / Double Exponential Smoothing Method

holt_model = Holt(Train["Sales"]).fit()
pred_holts = holt_model.predict(start=Test.index[0], end=Test.index[-1])
mape_holts = np.mean(np.abs(
    (Test["Sales"] - pred_holts) / Test["Sales"])) * 100
model.append("Holts method / Double Exponential Smoothing Method")
mape.append(mape_holts)

# Holts Winter Exponential Smoothing with Additive Seasonality and Additive Trend

hwe_model_add_add = ExponentialSmoothing(Train["Sales"],
                                         seasonal="additive",
                                         trend="additive",
                                         seasonal_periods=4,
                                         damped=True).fit()
pred_hwe_add_add = hwe_model_add_add.predict(start=Test.index[0],
                                             end=Test.index[-1])
mape_hwe_add_add = np.mean(