improvements in docstrings and testing for disabling uncertainty

This commit is contained in:
Ben Letham 2020-02-04 13:22:08 -08:00
parent 8d0f23f8be
commit be25372090
4 changed files with 10 additions and 6 deletions

View file

@ -242,8 +242,8 @@ performance_metrics <- function(df, metrics = NULL, rolling_window = 0.1) {
if (is.null(metrics)) {
metrics <- valid_metrics
}
if (!('yhat_lower' %in% colnames(df)) | (!('yhat_upper' %in% colnames(df))) & ('coverage' %in% metrics)){
metrics <- valid_metrics[valid_metrics != 'coverage']
if ((!('yhat_lower' %in% colnames(df)) | !('yhat_upper' %in% colnames(df))) & ('coverage' %in% metrics)){
metrics <- metrics[metrics != 'coverage']
}
if (length(metrics) != length(unique(metrics))) {

View file

@ -167,7 +167,7 @@ prophet_plot_components <- function(
#' @param fcst Dataframe output of `predict`.
#' @param name String name of the component to plot (column of fcst).
#' @param uncertainty Optional boolean to plot uncertainty intervals, which will
#' only be done if m$uncertainty.samples > 0.
#' only be done if m$uncertainty.samples > 0.
#' @param plot_cap Boolean indicating if the capacity should be shown in the
#' figure, if available.
#'
@ -233,7 +233,7 @@ seasonality_plot_df <- function(m, ds) {
#'
#' @param m Prophet model object
#' @param uncertainty Optional boolean to plot uncertainty intervals, which will
#' only be done if m$uncertainty.samples > 0.
#' only be done if m$uncertainty.samples > 0.
#' @param weekly_start Integer specifying the start day of the weekly
#' seasonality plot. 0 (default) starts the week on Sunday. 1 shifts by 1 day
#' to Monday, and so on.
@ -276,7 +276,7 @@ plot_weekly <- function(m, uncertainty = TRUE, weekly_start = 0,
#'
#' @param m Prophet model object.
#' @param uncertainty Optional boolean to plot uncertainty intervals, which
#' will only be done if m$uncertainty.samples > 0.
#' will only be done if m$uncertainty.samples > 0.
#' @param yearly_start Integer specifying the start day of the yearly
#' seasonality plot. 0 (default) starts the year on Jan 1. 1 shifts by 1 day
#' to Jan 2, and so on.
@ -321,7 +321,7 @@ plot_yearly <- function(m, uncertainty = TRUE, yearly_start = 0,
#' @param m Prophet model object.
#' @param name String name of the seasonality.
#' @param uncertainty Optional boolean to plot uncertainty intervals, which
#' will only be done if m$uncertainty.samples > 0.
#' will only be done if m$uncertainty.samples > 0.
#'
#' @return A ggplot2 plot.
#'

View file

@ -99,6 +99,8 @@ test_that("cross_validation_uncertainty_disabled", {
m, horizon = 4, units = "days", period = 4, initial = 115)
expected.cols <- c('y', 'ds', 'yhat', 'cutoff')
expect_equal(expected.cols, colnames(df.cv))
df.p <- performance_metrics(df.cv)
expect_false('coverage' %in% colnames(df.p))
}
})

View file

@ -114,6 +114,8 @@ class TestDiagnostics(TestCase):
m, horizon='4 days', period='4 days', initial='115 days')
expected_cols = ['ds', 'yhat', 'y', 'cutoff']
self.assertTrue(all(col in expected_cols for col in df_cv.columns.tolist()))
df_p = diagnostics.performance_metrics(df_cv)
self.assertTrue('coverage' not in df_p.columns)
def test_performance_metrics(self):
m = Prophet()