Hi so I'm trying to do hyperparameter tuning for a prophet model, and I'd like to see the effect of tuning the hyperparameters to the trend, seasonality, and holiday by using plot_components()
and it returns the visualization for all three components. Is there a way to only visualize one component, for example, only the seasonality, so that I can see how changing seasonality_prior_scale
parameter changes the seasonality?
您好,我正在尝试为一个预言者模型进行超参数调优,我希望看到通过使用PLOT_Components()将超参数调优到趋势、季节性和节假日的效果,它将返回所有这三个组件的可视化结果。有没有办法只可视化一个组件,例如,只显示季节性,这样我就可以看到更改季节性_PREVICE_SCALE参数是如何更改季节性的?
I tried using model.plot_components(forecast[['ds','weekly']])
but obviously it doesn't work..
我试着使用Model.Plot_Components(Forecast[[‘ds’,‘Weekly’]]),但显然不起作用。
更多回答
Please provide enough code so others can better understand or reproduce the problem.
请提供足够的代码,以便其他人能够更好地理解或重现问题。
优秀答案推荐
Is there a way to only visualize one component, for example, only the seasonality...
Absolutely yes. I do all of this work in R, so here is the R code.
绝对是的。我在R中完成所有这些工作,所以这是R代码。
- Load all packages that will be used.
library(tidyverse)
library(fpp3)
library(prophet)
library(fable.prophet)
- Break data into train and test
The fpp3 library includes a number of data sets and some amazing functions for working with time series, so we can make a reproducible example. We begin by splitting the data into training (60%) and testing (40%) amounts. The 60% and 40% are my choices, there is nothing special about those values.
Fpp3库包括许多数据集和一些用于处理时间序列的令人惊叹的函数,因此我们可以创建一个可重现的示例。我们首先将数据分为训练量(60%)和测试量(40%)。60%和40%是我的选择,这些值没有什么特殊之处。
time_series <- aus_retail %>%
filter(`Series ID` == "A3349849A") %>%
select(State, `Series ID`, Month, Turnover)
time_series_train <- time_series[1:310,]
time_series_test <- time_series[310:431,]
3, fit a model to the training data, using a prophet model:
3、使用预言者模型将模型与训练数据相匹配:
fit <- time_series_train %>%
model(
prophet = fable.prophet::prophet(Turnover)
)
- Find all the components.
A single line gives all the information you are asking about for this prophet model, such as trends, residuals, seasonality (yearly, weekly, daily), and more:
components(fit)
returns:
退货:
> components(fit)
# A dable: 310 x 11 [1M]
# Key: State, .model [1]
# : Turnover = trend * (1 + multiplicative_terms) + additive_terms + .resid
State .model Month Turnover additive_terms multiplicative_terms trend yearly weekly daily .resid
<chr> <chr> <mth> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 Australian Capital Territory prophet 1982 Apr 4.4 -0.533 0 4.35 -0.216 -0.140 -0.177 0.582
2 Australian Capital Territory prophet 1982 May 3.4 -0.0383 0 4.41 0.324 -0.185 -0.177 -0.976
3 Australian Capital Territory prophet 1982 Jun 3.6 -0.199 0 4.48 -0.282 0.260 -0.177 -0.680
4 Australian Capital Territory prophet 1982 Jul 4 -0.289 0 4.54 0.0278 -0.140 -0.177 -0.253
5 Australian Capital Territory prophet 1982 Aug 3.6 -0.00124 0 4.61 0.117 0.0585 -0.177 -1.01
6 Australian Capital Territory prophet 1982 Sep 4.2 -0.268 0 4.67 0.132 -0.224 -0.177 -0.205
7 Australian Capital Territory prophet 1982 Oct 4.8 1.24 0 4.74 1.14 0.278 -0.177 -1.18
8 Australian Capital Territory prophet 1982 Nov 5.4 0.669 0 4.80 0.893 -0.0467 -0.177 -0.0710
9 Australian Capital Territory prophet 1982 Dec 6.9 1.41 0 4.86 1.81 -0.224 -0.177 0.623
10 Australian Capital Territory prophet 1983 Jan 3.8 -1.85 0 4.93 -1.49 -0.185 -0.177 0.721
- Plot multiple seasonalities
Plotting any one of those is only two lines of code, for example here is how the trend is plotted (but all the others are handled in exactly the same method):
components(fit) %>%
autoplot(trend)
You can then plot any of the other seasonality columns to see how that changes the results. I've attached the yearly and weekly seasonality as examples.
然后,您可以绘制任何其他季节性列,以查看这将如何更改结果。我已经附上了每年和每周的季节性作为例子。
更多回答
我是一名优秀的程序员,十分优秀!