1 Reply Latest reply on Jul 26, 2019 11:36 AM by Nathan Mannheimer

    Help with running Prophet R Package in Tableau

    Jonathan Whiters

      I'm hoping someone can help with an error I receive when trying to run a forecast via the prophet package in Tableau.


      I keep getting the following error: "Unexpected number of results returned by SCRIPT function. Function expected 348 values; 349 values were returned"


      I seem to get this error due to the 'periods=.arg2[1]+1' portion of the script. When I remove '+1' the script runs, but it only forecast 1 period at a time (for example if the last day is 5/9/2019 and Number of Periods to Predict is set to 10, it will only forecast a value for 5/19/2019, no individual forecast between 5/9/2019 and 5/19/2019).


      The script I am using:






      l <- length(.arg1);

      u <- .arg1[1:(l-.arg2[1])];

      n <- length(u);

      u[n] = .arg1[l];


      df <- data.frame(ds = seq(as.Date('2018/1/1'), by = 'day', length.out = n), y=u);


      m <- prophet(df, yearly.seasonality = 20)


      future <- make_future_dataframe(m, periods=.arg2[1]+1)


      forecast <- predict (m, future)




      ",[Actual PIF UPB],[NumberofPeriodstoPredict])





      Thanks in advance,

        • 1. Re: Help with running Prophet R Package in Tableau
          Nathan Mannheimer

          Hi Jonathan,


          This script, along with the date extension trick shown in this video (Data science applications with TabPy/R - YouTube), should work for you:




          period = .arg3[1]+1



          df = data.frame('ds' = .arg1, 'y' = .arg2)

          divide = nrow(df)-period

          df = df[1:divide,]



          m = prophet(df)

          future = make_future_dataframe(m, periods=period)

          forecast = predict(m, future)


          ",ATTR([Date]),SUM([Logins]),[Periods to Forecast])


          I think the problem you are encountering is that you are not extending the date range to integrate the extra forecast dates. The video should cover how to do that.



          1 of 1 people found this helpful