mirror of
https://github.com/saymrwulf/prophet.git
synced 2026-09-15 22:10:22 +00:00
Store dates from history with y NaN for make_future_dataframe
This commit is contained in:
parent
1a57d19148
commit
5677d8c7ce
2 changed files with 9 additions and 5 deletions
|
|
@ -107,7 +107,8 @@ prophet <- function(df = df,
|
||||||
changepoints.t = NULL,
|
changepoints.t = NULL,
|
||||||
stan.fit = NULL,
|
stan.fit = NULL,
|
||||||
params = list(),
|
params = list(),
|
||||||
history = NULL
|
history = NULL,
|
||||||
|
history.dates = NULL
|
||||||
)
|
)
|
||||||
validate_inputs(m)
|
validate_inputs(m)
|
||||||
class(m) <- append("prophet", class(m))
|
class(m) <- append("prophet", class(m))
|
||||||
|
|
@ -455,6 +456,7 @@ logistic_growth_init <- function(df) {
|
||||||
fit.prophet <- function(m, df, ...) {
|
fit.prophet <- function(m, df, ...) {
|
||||||
history <- df %>%
|
history <- df %>%
|
||||||
dplyr::filter(!is.na(y))
|
dplyr::filter(!is.na(y))
|
||||||
|
m$history.dates <- sort(zoo::as.Date(df$ds))
|
||||||
|
|
||||||
out <- setup_dataframe(m, history, initialize_scales = TRUE)
|
out <- setup_dataframe(m, history, initialize_scales = TRUE)
|
||||||
history <- out$df
|
history <- out$df
|
||||||
|
|
@ -839,10 +841,10 @@ sample_predictive_trend <- function(model, df, iteration) {
|
||||||
#' @export
|
#' @export
|
||||||
make_future_dataframe <- function(m, periods, freq = 'd',
|
make_future_dataframe <- function(m, periods, freq = 'd',
|
||||||
include_history = TRUE) {
|
include_history = TRUE) {
|
||||||
dates <- seq(max(m$history$ds), length.out = periods + 1, by = freq)
|
dates <- seq(max(m$history.dates), length.out = periods + 1, by = freq)
|
||||||
dates <- dates[2:(periods + 1)] # Drop the first, which is max(history$ds)
|
dates <- dates[2:(periods + 1)] # Drop the first, which is max(history$ds)
|
||||||
if (include_history) {
|
if (include_history) {
|
||||||
dates <- c(m$history$ds, dates)
|
dates <- c(m$history.dates, dates)
|
||||||
}
|
}
|
||||||
return(data.frame(ds = dates))
|
return(data.frame(ds = dates))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,7 @@ class Prophet(object):
|
||||||
self.stan_fit = None
|
self.stan_fit = None
|
||||||
self.params = {}
|
self.params = {}
|
||||||
self.history = None
|
self.history = None
|
||||||
|
self.history_dates = None
|
||||||
self.validate_inputs()
|
self.validate_inputs()
|
||||||
|
|
||||||
def validate_inputs(self):
|
def validate_inputs(self):
|
||||||
|
|
@ -350,6 +351,7 @@ class Prophet(object):
|
||||||
The fitted Prophet object.
|
The fitted Prophet object.
|
||||||
"""
|
"""
|
||||||
history = df[df['y'].notnull()].copy()
|
history = df[df['y'].notnull()].copy()
|
||||||
|
self.history_dates = pd.to_datetime(df['ds']).sort_values()
|
||||||
|
|
||||||
history = self.setup_dataframe(history, initialize_scales=True)
|
history = self.setup_dataframe(history, initialize_scales=True)
|
||||||
self.history = history
|
self.history = history
|
||||||
|
|
@ -608,7 +610,7 @@ class Prophet(object):
|
||||||
return trend * self.y_scale
|
return trend * self.y_scale
|
||||||
|
|
||||||
def make_future_dataframe(self, periods, freq='D', include_history=True):
|
def make_future_dataframe(self, periods, freq='D', include_history=True):
|
||||||
last_date = self.history['ds'].max()
|
last_date = self.history_dates.max()
|
||||||
dates = pd.date_range(
|
dates = pd.date_range(
|
||||||
start=last_date,
|
start=last_date,
|
||||||
periods=periods + 1, # An extra in case we include start
|
periods=periods + 1, # An extra in case we include start
|
||||||
|
|
@ -617,7 +619,7 @@ class Prophet(object):
|
||||||
dates = dates[:periods] # Return correct number of periods
|
dates = dates[:periods] # Return correct number of periods
|
||||||
|
|
||||||
if include_history:
|
if include_history:
|
||||||
dates = np.concatenate((np.array(self.history['ds']), dates))
|
dates = np.concatenate((np.array(self.history_dates), dates))
|
||||||
|
|
||||||
return pd.DataFrame({'ds': dates})
|
return pd.DataFrame({'ds': dates})
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue