online gambling singapore online gambling singapore online slot malaysia online slot malaysia mega888 malaysia slot gacor live casino malaysia online betting malaysia mega888 mega888 mega888 mega888 mega888 mega888 mega888 mega888 mega888 FbProphet — Your Solution to Forecasting Problem

摘要: In such cases, FbProphet is your savior; easy, fast and gives good performance. If you know how FbProphet works, you can use it well to fit your time-series data.

 


images/20210827_3_1.png

▲Let’s just say: Predicting future isn’t easy(來源:medium.com)

We have seen multiple breakthroughs in Natural Language Processing and Computer Vision in the domain of Artificial Intelligence. And we have seen these being applied to many applications to solve language and image-based problems. A common problem crucial to businesses around the globe is Forecasting. This can range from forecasting sales to forecasting footfall. Being able to judge how many people will visit a park or how many soda cans will be sold can be of vital importance in business; to regulate the number of employees needed in the park to cater X number of visitors in a day or the number of items that need to be ordered to manufacture X number of soda cans in a month.

Forecasting can be hourly, daily, weekly, monthly, or yearly, depending on how the business works.

Forecasting is a broad domain and it’s tricky because there are a lot of variations in trajectories of sales of different items or footfall in different locations and it’s harder to take and apply the same parameters to a different problem. And that makes it hectic to use ARIMA or LSTM for forecasting. Even though there’s AUTOARIMA for automatic selection of parameters, ARIMA performs poorly on unstructured time-series data.

In such cases, FbProphet is your savior; easy, fast and gives good performance. If you know how FbProphet works, you can use it well to fit your time-series data. So what is FbProphet made up of:

  • Trends
  • Seasonalities
  • Regressors

Let’s try to understand each of these a little better. Trend is a general trajectory that the data is following or in other words a general direction in which something is developing or changing. Here’s an example of the trend for Peyton Manning’s playoff appearances over the years:

images/20210827_3_2.png

Seasonality is a repetitive pattern the model learns. There could be weekly seasonality; a pattern that generally repeats over every week. Or a monthly pattern that generally repeats itself over a year. Yearly and weekly seasonalities are built-in in FbProphet. But you can also add custom seasonality e.g a pattern that repeats on Saturday & Sunday only. In this case, your seasonality column will have ‘True’ for Saturday and Sunday dates and be ‘False’ for the rest of the days.

Since seasonalities are dependent on Fourier order, you can increase Fourier order to capture higher frequency changes or decrease to learn a more generic pattern.

images/20210827_3_3.png

▲Fourier order = 10 (default)

images/20210827_3_4.png

▲Fourier order increased to 20

A regressor adds an additive or multiplicative effect to the model learning. A regressor column must be present in both training and prediction data frames. For example, if we are predicting footfall for a theme park, it’s a good idea to take weather into account. We can add temperature as a regressor. As a result, the model will learn the additional effect of temperature on the number of people that visit the park on a day.

images/20210827_3_5.png

You can also add holidays effect in the forecast. There are two ways of doing this.

  • You can specify the country and FbProphet would add holidays for that country.
  • If you have other recurring events that you’d like to model, you can create a data frame for them and pass them to the model as holidays, and expect the model to learn and add their effect on the forecast.

The model will learn and model the effect of those holidays on the forecast as can be seen below:

images/20210827_3_6.png

▲Effect of holidays on the forecast

When you train a FbProphet model, you can use plot_components to see what trends and seasonalities the model has learned. Below we can see an output for trend, yearly seasonality, and weekly seasonality.

images/20210827_3_7.png

▲Trend and seasonalities

You can adjust the trend flexibility using changepoint_prior_scale. By default, this is 0.05. You can increase it to make the model more flexible to changes (overfit) or decrease it to make it less flexible(underfit). In simpler terms, this parameter can be used to adjust your models behavior between overfitting and underfitting.

CODE

Let’s now dive a little into the code with a footfall dataset for a recreational place in the UK:

images/20210827_3_8.jpg

▲DataFrame for footfall count with dates

We’ll rename the columns to ‘ds’ and ‘y’ as required by the FbProphet. We’ll use the built-in weekly and yearly seasonalities and add a custom monthly seasonality as well. The period will be 30.5 (avg of 30 & 31) and we’ll use a Fourier order of 5. We’ll also add country holidays.

images/20210827_3_9.jpg

FbProphet will return predictions as yhat with upper and lower uncertainty levels (yhat_upper & yhat_lower).

images/20210827_3_10.jpg

▲Tail of the future Dataframe

When we keep include_history as True in prediction, the model does an in-sample fit as well (gives predictions for the training dataset as well). You can use this to judge better how well the model has fit both the past and future data.

Let’s do some plotting to better understand the results

images/20210827_3_11.jpg

images/20210827_3_12.png

▲forecast

images/20210827_3_13.jpg

images/20210827_3_14.png

▲Trends and seasonalities learned by the model

We can see the footfall count is generally increasing over the years. We can also see from the weekly seasonality plot, that the model has learned correctly a high footfall trend for the weekends.

There are a lot of options available for training a FbProphet model, from regressors to changepoint_prior_scale. More information can be found here.

Resources:

轉貼自Source: medium.com

若喜歡本文,請關注我們的臉書 Please Like our Facebook Page:    Big Data In Finance

 


留下你的回應

以訪客張貼回應

0
  • 找不到回應

YOU MAY BE INTERESTED