開始使用免費開始

建立節日/促銷效果變數

在上一個練習裡,你已經看到一些季節性跡象,不過我們要進一步檢驗,確認是否真的存在。你的主管認為產品在聖誕節、新年和情人節前後的那些週會更受歡迎。行銷部門也提到,過去 5 年他們都在母親節前一週進行促銷活動。現在來為新年建立一個二元指標變數吧!

本練習屬於課程

用 R 預測產品需求

檢視課程

練習說明

  • 建立訓練資料集中新年週的日期索引,命名為 n.dates
  • 使用日期索引 n.dates 建立名為 newyearxts 物件。
  • 自 2014 年 1 月 19 日(你的訓練資料時間範圍)起建立長度為 154 的日期序列,命名為 dates_train
  • newyear 物件與上一點建立的訓練日期合併,並將所有遺漏值填補為 0。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Create date indices for New Year's week
n.dates <- as.Date(c("2014-12-28", "2015-12-27", "2016-12-25"))

# Create xts objects for New Year's
newyear <- as.xts(rep(1, 3), order.by = ___)

# Create sequence of 154 weeks for merging
dates_train <- seq(as.Date("2014-01-19"), length = ___, by = ___)

# Merge training dates into New Year's object
newyear <- ___(newyear, ___, fill = ___)
編輯並執行程式碼