|
@@ -4,8 +4,9 @@ context("Prophet diagnostics tests")
|
|
|
## Makes R CMD CHECK happy due to dplyr syntax below
|
|
|
globalVariables(c("y", "yhat"))
|
|
|
|
|
|
-DATA <- head(read.csv('data.csv'), 100)
|
|
|
-DATA$ds <- as.Date(DATA$ds)
|
|
|
+DATA_all <- read.csv('data.csv')
|
|
|
+DATA_all$ds <- as.Date(DATA_all$ds)
|
|
|
+DATA <- head(DATA_all, 100)
|
|
|
|
|
|
test_that("simulated_historical_forecasts", {
|
|
|
skip_if_not(Sys.getenv('R_ARCH') != '/i386')
|
|
@@ -132,3 +133,72 @@ test_that("performance_metrics", {
|
|
|
sort(colnames(df_horizon)) == sort(c('coverage', 'mse', 'horizon'))
|
|
|
))
|
|
|
})
|
|
|
+
|
|
|
+test_that("copy", {
|
|
|
+ skip_if_not(Sys.getenv('R_ARCH') != '/i386')
|
|
|
+ df <- DATA_all
|
|
|
+ df$cap <- 200.
|
|
|
+ df$binary_feature <- c(rep(0, 255), rep(1, 255))
|
|
|
+ inputs <- list(
|
|
|
+ growth = c('linear', 'logistic'),
|
|
|
+ yearly.seasonality = c(TRUE, FALSE),
|
|
|
+ weekly.seasonality = c(TRUE, FALSE),
|
|
|
+ daily.seasonality = c(TRUE, FALSE),
|
|
|
+ holidays = c('null', 'insert_dataframe')
|
|
|
+ )
|
|
|
+ products <- expand.grid(inputs)
|
|
|
+ for (i in 1:length(products)) {
|
|
|
+ if (products$holidays[i] == 'insert_dataframe') {
|
|
|
+ holidays <- data.frame(ds=c('2016-12-25'), holiday=c('x'))
|
|
|
+ } else {
|
|
|
+ holidays <- NULL
|
|
|
+ }
|
|
|
+ m1 <- prophet(
|
|
|
+ growth = as.character(products$growth[i]),
|
|
|
+ changepoints = NULL,
|
|
|
+ n.changepoints = 3,
|
|
|
+ yearly.seasonality = products$yearly.seasonality[i],
|
|
|
+ weekly.seasonality = products$weekly.seasonality[i],
|
|
|
+ daily.seasonality = products$daily.seasonality[i],
|
|
|
+ holidays = holidays,
|
|
|
+ seasonality.prior.scale = 1.1,
|
|
|
+ holidays.prior.scale = 1.1,
|
|
|
+ changepoints.prior.scale = 0.1,
|
|
|
+ mcmc.samples = 100,
|
|
|
+ interval.width = 0.9,
|
|
|
+ uncertainty.samples = 200,
|
|
|
+ fit = FALSE
|
|
|
+ )
|
|
|
+ out <- prophet:::setup_dataframe(m1, df, initialize_scales = TRUE)
|
|
|
+ m1 <- out$m
|
|
|
+ m1$history <- out$df
|
|
|
+ m1 <- prophet:::set_auto_seasonalities(m1)
|
|
|
+ m2 <- prophet:::prophet_copy(m1)
|
|
|
+ # Values should be copied correctly
|
|
|
+ args <- c('growth', 'changepoints', 'n.changepoints', 'holidays',
|
|
|
+ 'seasonality.prior.scale', 'holidays.prior.scale',
|
|
|
+ 'changepoints.prior.scale', 'mcmc.samples', 'interval.width',
|
|
|
+ 'uncertainty.samples')
|
|
|
+ for (arg in args) {
|
|
|
+ expect_equal(m1[[arg]], m2[[arg]])
|
|
|
+ }
|
|
|
+ expect_equal(FALSE, m2$yearly.seasonality)
|
|
|
+ expect_equal(FALSE, m2$weekly.seasonality)
|
|
|
+ expect_equal(FALSE, m2$daily.seasonality)
|
|
|
+ expect_equal(m1$yearly.seasonality, 'yearly' %in% names(m2$seasonalities))
|
|
|
+ expect_equal(m1$weekly.seasonality, 'weekly' %in% names(m2$seasonalities))
|
|
|
+ expect_equal(m1$daily.seasonality, 'daily' %in% names(m2$seasonalities))
|
|
|
+ }
|
|
|
+ # Check for cutoff and custom seasonality and extra regressors
|
|
|
+ changepoints <- seq.Date(as.Date('2012-06-15'), as.Date('2012-09-15'), by='d')
|
|
|
+ cutoff <- as.Date('2012-07-25')
|
|
|
+ m1 <- prophet(changepoints = changepoints)
|
|
|
+ m1 <- add_seasonality(m1, 'custom', 10, 5)
|
|
|
+ m1 <- add_regressor(m1, 'binary_feature')
|
|
|
+ m1 <- fit.prophet(m1, df)
|
|
|
+ m2 <- prophet:::prophet_copy(m1, cutoff)
|
|
|
+ changepoints <- changepoints[changepoints <= cutoff]
|
|
|
+ expect_equal(prophet:::set_date(changepoints), m2$changepoints)
|
|
|
+ expect_true('custom' %in% names(m2$seasonalities))
|
|
|
+ expect_true('binary_feature' %in% names(m2$extra_regressors))
|
|
|
+})
|