GithubHelp home page GithubHelp logo

Use dygraphs for plotting about prophet HOT 27 CLOSED

facebook avatar facebook commented on April 24, 2024 2
Use dygraphs for plotting

from prophet.

Comments (27)

seanjtaylor avatar seanjtaylor commented on April 24, 2024 2

I hadn't seen dygraphs! Looks neat. Let's get this into the 0.2 release.

from prophet.

jaredlander avatar jaredlander commented on April 24, 2024 2

@lgaliano Familiar with plotly. Good for quickly converting ggplot2 to JavaScript. For a built-in function like this it might as well be written natively in a JavaScript format.

from prophet.

jaredlander avatar jaredlander commented on April 24, 2024 1

@wjhrdy We can also use dyEvent for marking change points.

from prophet.

lgaliano avatar lgaliano commented on April 24, 2024 1

@jaredlander , @seanjtaylor Not sure if you noticed, but plot(m, forecast) works directly with plotly, so you could also do ggplotly(plot(m, forecast)) if you were looking for interactivity (but prophet_plot_components(m, forecast) won't work without a few changes to generate the components with facet_grid())

from prophet.

pravj avatar pravj commented on April 24, 2024 1

To produce interactive forecasts, I have been working on Prophetly to integrate Prophet with Plotly.

It's currently in development phase, but I would be happy to have some feedback and discussion. :octocat:

from prophet.

bletham avatar bletham commented on April 24, 2024 1

Great! Be sure to make it on the v0.2 branch.

from prophet.

Olof-Hojvall avatar Olof-Hojvall commented on April 24, 2024 1

For Python, I would expect Plotly to be the best choice for interactive plots. I did a plot of the forecast here: https://nbviewer.jupyter.org/gist/Olof-Hojvall/d5cbbfdab8f69ce26e11a46750104158 I tried to follow the design of the existing forecast plots.

Would this be an interesting solution @bletham ? If so I could make a PR for it.

from prophet.

bletham avatar bletham commented on April 24, 2024 1

@mkrasmus I think the issue is that it looks like you included the period at the end of the sentence as part of the command. If you just do

dyplot.prophet(m, forecast)

(no period at the end) it should work.

from prophet.

jaredlander avatar jaredlander commented on April 24, 2024

It's a really cool package. All of these htmlwidgets packages do some great stuff and really extend our viz capabilities.

from prophet.

wjhrdy avatar wjhrdy commented on April 24, 2024

I also find it very useful to add shaded regions for the holidays.
This can be accomplished with this code:

for (i in 1:nrow(holidays)) {
     dyBase <- dyBase %>% dyShading(from = holidays$ds[i] + holidays$lower_window[i], 
                                        to = holidays$ds[i] + holidays$upper_window[i]) 
     dyBase <- dyBase %>% presAnnotation(holidays$ds[i], text = holidays$holiday[i])
   }

from prophet.

smach avatar smach commented on April 24, 2024

@seanjtaylor Adding dygraphs would be great, looking forward to it in 0.2. Thanks!

from prophet.

LaurentBerder avatar LaurentBerder commented on April 24, 2024

Plotly is also a great alternative for interactive graphs, and is both available in R and Python...

from prophet.

GanJianhao avatar GanJianhao commented on April 24, 2024

df_for_plotting ??

from prophet.

jaredlander avatar jaredlander commented on April 24, 2024

@GanJianhao that's an internal prophet function.

from prophet.

bletham avatar bletham commented on April 24, 2024

The v0.2 release is coming up soon, and this will need a PR to make it in. Anyone interested?

I think we'd want to pull the ggplot / dygraphs / plotly / ... code out of prophet.R into their own files so as to not clutter prophet.R with a dozen different plotting functions (almost there as is).

from prophet.

wjhrdy avatar wjhrdy commented on April 24, 2024

I'll make a pull request. I think this is a really useful way to explore regressors and features in your data.

from prophet.

wjhrdy avatar wjhrdy commented on April 24, 2024

Sorry I didn't make it into v0.2 here is the pull request: #320

from prophet.

bletham avatar bletham commented on April 24, 2024

Thanks to @wjhrdy for the PR! This is now in the v0.3 branch and can be used like

dyplot.prophet(m, forecast)

With time we can add component plots in dygraphs also, so I'll leave this issue open for that.

from prophet.

bletham avatar bletham commented on April 24, 2024

The dygraphs plot of the forecast is now available in v0.3, so I'll go ahead and close this and we can open a new issue if we want to expand dygraph plotting to components plots in the future.

from prophet.

wushengzhong avatar wushengzhong commented on April 24, 2024

Is dyplot.prophet(m,forecast) supported in R only? I tried this in python and it doesn't work for me.

from prophet.

bletham avatar bletham commented on April 24, 2024

It is in R only, I didn't realize there was a python interface to dygraphs. Re-opening, if anyone would like to translate what was done in R (https://github.com/facebook/prophet/blob/master/R/R/plot.R#L391) into Python that would be extremely helpful.

from prophet.

bletham avatar bletham commented on April 24, 2024

@Olof-Hojvall that sounds great, I've been using plotly for some other stuff and it's been working very nicely there. I'd definitely merge that.

from prophet.

bletham avatar bletham commented on April 24, 2024

Documented in 4e5e223

from prophet.

seekerknow avatar seekerknow commented on April 24, 2024

Hi - apologies if this question doesn't fit in here - I am just wondering if there is a way to share the interactive dygraph (after saving it as an local html file) to someone else (with no R or Python on their machines) in the organisation?

Thanks,
Seeker

from prophet.

jaredlander avatar jaredlander commented on April 24, 2024

Hi - apologies if this question doesn't fit in here - I am just wondering if there is a way to share the interactive dygraph (after saving it as an local html file) to someone else (with no R or Python on their machines) in the organisation?

Thanks,
Seeker

@seekerknow It should be a self-contained HTML file so you could share the file with anyone who has a modern browser.

from prophet.

mkrasmus avatar mkrasmus commented on April 24, 2024

Hi I'm following the quick start guide for R:

library('prophet')

# First we read in the data and create the outcome variable. As in the Python API, this is a dataframe with columns ds and y, containing the date and numeric value respectively. The ds column should be YYYY-MM-DD for a date, or YYYY-MM-DD HH:MM:SS for a timestamp. As above, we use here the log number of views to Peyton Manning’s Wikipedia page, available here.
df <- read.csv('raw/example_wp_log_peyton_manning.csv')


# We call the prophet function to fit the model. The first argument is the historical dataframe. Additional arguments control how Prophet fits the data and are described in later pages of this documentation.
m <- prophet(df)

# Predictions are made on a dataframe with a column ds containing the dates for which predictions are to be made. The make_future_dataframe function takes the model object and a number of periods to forecast and produces a suitable dataframe. By default it will also include the historical dates so we can evaluate in-sample fit.
# R
future <- make_future_dataframe(m, periods = 365)
tail(future)


# As with most modeling procedures in R, we use the generic predict function to get our forecast. The forecast object is a dataframe with a column yhat containing the forecast. It has additional columns for uncertainty intervals and seasonal components.
# R
forecast <- predict(m, future)
tail(forecast[c('ds', 'yhat', 'yhat_lower', 'yhat_upper')])

# You can use the generic plot function to plot the forecast, by passing in the model and the forecast dataframe.
# R
plot(m, forecast)

# You can use the prophet_plot_components function to see the forecast broken down into trend, weekly seasonality, and yearly seasonality.
# R
prophet_plot_components(m, forecast)

# An interactive plot of the forecast using Dygraphs can be made with the command dyplot.prophet(m, forecast).
library(dygraphs)
dyplot.prophet(m, forecast).

But end up with the following error message:

Error: unexpected symbol in "dyplot.prophet(m, forecast)."

Anyone else get the same?

from prophet.

Jose-Gallegos avatar Jose-Gallegos commented on April 24, 2024

@mkrasmus I think the issue is that it looks like you included the period at the end of the sentence as part of the command. If you just do

dyplot.prophet(m, forecast)

(no period at the end) it should work.

After doing dyplot.prophet(m, forecast), how can I get the output directory and file? Or how can I set the output directory and file name? I want to upload the output to a site.

Thanks.

from prophet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.