How To Create A Forecast Model In Power BI With Python

Enterprise DNA
21 Nov 202212:00

Summary

TLDRThis tutorial demonstrates how to create a forecast in Power BI using Python, enhancing the built-in forecasting feature to capture both seasonal patterns and trends in data. The video guides through using exponential smoothing in a Jupyter notebook, adjusting for seasonality and trends, and integrating the Python model's predictions back into Power BI. It highlights the advantage of optimizing models in Python over Power BI's default settings and encourages further learning through additional resources.

Takeaways

  • 📊 The tutorial demonstrates how to create a forecast in Power BI using Python to enhance the built-in forecasting feature.
  • 🔍 The script identifies seasonality and trend in the data, which are important for an accurate forecast model.
  • 📈 Power BI's forecasting feature can visually forecast data with seasonality and trend, but Python can offer more customization.
  • 🤖 The use of Python allows for the implementation of models like exponential smoothing, which can be adjusted for seasonality and trends.
  • 📝 The script explains the process of decomposing a time series to understand the underlying trend and seasonality.
  • 📚 There are different models available for forecasting, such as additive and multiplicative trends, which can be optimized for better predictions.
  • 🔧 The tutorial walks through the process of training a model using a subset of the data to prevent overfitting.
  • 📅 The forecast model can predict data for a specific period, such as 30 days in advance, which is demonstrated in the script.
  • 🔄 The process of integrating the Python forecast model with Power BI is shown, including adjusting the data and appending forecasts.
  • 🛠 The tutorial highlights the advantage of using Python for more detailed model optimization compared to Power BI's built-in tools.
  • 📘 Additional resources like webinars and further learning materials are available for those interested in deepening their knowledge on forecasting.

Q & A

  • What is the main topic of the video script?

    -The main topic of the video script is how to create a forecast in Power BI using Python, specifically focusing on handling seasonality and trends in the data.

  • What type of data is being analyzed in the script?

    -The data being analyzed in the script is page views, which shows some peaks and a weekly seasonality pattern along with an increasing trend in the last month.

  • How does Power BI's forecasting feature handle seasonality?

    -Power BI's forecasting feature can visually forecast data and automatically picks up seasonality. Users can adjust the seasonality by adding a specific number, such as seven for weekly seasonality.

  • What is the significance of the 95% confidence intervals in the forecast?

    -The 95% confidence intervals in the forecast provide a range within which the actual values are likely to fall, indicating the reliability of the forecast.

  • Why is the trend line turned on in the visual?

    -The trend line is turned on to identify and incorporate the upward trend in the data into the forecast model, which is not being picked up well by the Power BI model alone.

  • What Python library is used for the exponential smoothing model in the script?

    -The script uses the 'statsmodels' library for the exponential smoothing model, specifically the Holt-Winters method.

  • What does the term 'additive' refer to in the context of the trend in the exponential smoothing model?

    -In the context of the trend, 'additive' refers to a model where the trend component is added to the data in a linear fashion, as opposed to a 'multiplicative' trend, which grows exponentially.

  • How does the script handle the training of the exponential smoothing model?

    -The script trains the model on a subset of the data, specifically the first 290 days out of 298, to prevent overfitting and allow the model to learn effectively.

  • What is the purpose of the 'seasonal_periods' parameter in the exponential smoothing model?

    -The 'seasonal_periods' parameter is used to define the length of the seasonal cycle in the data, which is set to seven days in the script to match the weekly seasonality.

  • How does the script implement the forecast in Power Query?

    -The script implements the forecast in Power Query by creating a new custom column for the forecast, appending the forecast data to the original dataset, and ensuring that the columns match for easy comparison.

  • What are the advantages of using Python for forecasting over Power BI's built-in feature?

    -Using Python for forecasting allows for more optimization of the model by adjusting the nature of the trend and seasonality, and it enables the inclusion of detailed predictions directly into the actual dataset.

Outlines

00:00

📊 Power BI Forecasting with Python

This paragraph introduces a tutorial on creating a forecast in Power BI using Python. The speaker demonstrates the Power BI's built-in forecasting feature, which visualizes data trends and seasonality. The data set in question shows weekly seasonality and an increasing trend over time. The tutorial aims to enhance the model to capture both the seasonality and the upward trend more effectively than the default settings in Power BI. The speaker also mentions the use of a Python model to achieve this, and introduces the tools and libraries used in the process, such as pandas, matplotlib, and the exponential smoothing model for a more customized forecast.

05:01

🔍 Analyzing Seasonality and Trend with Python

The second paragraph delves into the technical aspects of using Python for forecasting in Power BI. It discusses the use of exponential smoothing with additive and multiplicative trends and seasonality, and how these affect the forecast. The speaker explains the difference between additive and multiplicative trends in the context of the data's growth pattern. The paragraph also covers the process of training the model on historical data and using it to forecast future values. The speaker illustrates how to implement the Python script within Power Query to integrate the forecasted data with the actual data for a comprehensive view.

10:04

🚀 Optimizing Forecasts and Integrating with Power BI

The final paragraph wraps up the tutorial by discussing the advantages of using Python for forecasting over the default Power BI tools. It highlights the ability to optimize the model by adjusting the nature of the trend and seasonality, which is more limited in Power BI. The speaker also shows how to append the forecasted data to the actual dataset in Power BI, providing a seamless integration of historical and predicted values. The paragraph concludes with a call to action for viewers to like, subscribe, and visit the Enterprise DNA website for more resources, emphasizing the continuous support and educational content available for Power BI users.

Mindmap

Keywords

💡Forecasting

Forecasting in the context of the video refers to the process of predicting future values based on historical data. It is central to the video's theme as it demonstrates how to use Power BI and Python for making predictions about future data points, such as page views. The script mentions using Power BI's forecasting feature and later introduces a Python model to improve and customize the forecast.

💡Power BI

Power BI is a business analytics service by Microsoft that provides interactive visualizations and business intelligence capabilities. In the video, it is the primary tool used for data analysis and forecasting. The script discusses Power BI's built-in forecasting feature and how to utilize it to predict data trends.

💡Python

Python is a high-level programming language widely used for general-purpose programming. The video script describes using Python in conjunction with Power BI to create a more customized forecast model. It is highlighted as a tool for implementing complex models and optimizing forecasts beyond the capabilities of Power BI alone.

💡Seasonality

Seasonality refers to the predictable and recurring fluctuations in data that occur within a calendar year. In the script, seasonality is identified as a weekly pattern in the page views data. The video shows how to adjust for seasonality in both Power BI and the Python model to improve the accuracy of forecasts.

💡Trend

A trend in data analysis is a general direction in which something is changing over time. The script identifies an upward trend in the data, indicating that page views are increasing over the last month. The video explains how to incorporate this trend into the forecasting model to ensure that the forecast reflects the data's direction of change.

💡Exponential Smoothing

Exponential smoothing is a time series forecasting method for univariate data that can be extended to support data with a systematic trend or seasonal component. The script mentions using an exponential smoothing model in Python, specifically the Holt-Winters method, to capture both trend and seasonality in the data.

💡Confidence Intervals

Confidence intervals provide a range of values within which the true value of a parameter is likely to fall, with a certain level of confidence. In the video, a 95% confidence interval is used in the Power BI forecast to indicate the reliability of the predictions.

💡Jupyter Notebook

A Jupyter Notebook is an open-source web application that allows creation and sharing of documents that contain live code, equations, visualizations, and narrative text. The script describes using a Jupyter Notebook to implement the Python code for the custom forecasting model.

💡Holt-Winters Method

The Holt-Winters method, also known as the triple exponential smoothing method, is a time series forecasting method that includes parameters for the level, trend, and seasonality components. The script refers to this method when discussing the Python model, indicating its use for more accurate forecasting by accounting for trend and seasonality.

💡Additive vs. Multiplicative

Additive and multiplicative are terms used to describe the nature of the trend and seasonality in a time series. Additive models assume that changes are constant over time, while multiplicative models assume that changes are proportional. The script discusses experimenting with both additive and multiplicative trends and seasonality in the Python model to find the best fit for the data.

💡Optimization

Optimization in the context of the video refers to the process of adjusting the parameters of a forecasting model to achieve the best possible predictive accuracy. The script explains how changing the nature of the trend and seasonality from additive to multiplicative in the Python model can optimize the forecast results.

Highlights

Introduction to forecasting in Power BI using Python for more control over seasonality and trends.

Power BI's built-in forecasting feature effectively handles seasonality, especially weekly patterns.

Identifying the limitation of Power BI in capturing strong upward trends in the data.

Switching to Python in Jupyter Notebook to enhance the forecasting model by incorporating trends and seasonality.

Using exponential smoothing in Python as the forecasting model for better accuracy.

Introduction to Seasonal Decomposition to visualize and separate trend and seasonality in the data.

Explanation of how the exponential smoothing model works, including the concepts of additive and multiplicative trends.

Experimenting with additive and multiplicative models to optimize the forecast based on the data's behavior.

Training the model on 290 out of 298 days of data to allow it to learn and forecast accurately.

Visual comparison of the additive and multiplicative models' impact on the forecast.

Demonstrating how to implement the Python forecast code within Power BI’s Power Query editor.

Merging actual and forecasted data in Power BI to visualize the complete forecast model.

Highlighting the flexibility and advantages of using Python for more tailored forecasts compared to Power BI's built-in options.

Encouragement to explore different models and settings for better forecasting outcomes in specific scenarios.

Conclusion with resources for further learning, including videos and webinars on forecasting and seasonality decomposition.

Transcripts

play00:00

[Music]

play00:10

thank you

play00:13

hi I want to show you how to create a

play00:15

forecast in power bi using python of

play00:18

course we can utilize the power bi

play00:20

forecasting feature

play00:22

which allows us to visually forecast

play00:25

the data that we have to a specific day

play00:28

and as you see here these are our

play00:30

actuals they're just page views we can

play00:32

see there are some peaks in the data but

play00:35

it looks very seasonal and you can see

play00:37

that this is a weekly seasonality but we

play00:40

also see this trend where we see

play00:42

increasing data in the last month and we

play00:45

want to be able to pick that up in our

play00:47

model

play00:48

so if we go down here to the power bi

play00:51

model you can see that we have a

play00:53

seasonality and we can definitely

play00:55

control that seasonality so I can click

play00:57

into this and if I go over to the

play01:01

analysis icon and I hover down to

play01:06

the forecast feature you can see what I

play01:09

did I forecasted 30 days out

play01:12

and then we have a 95 confidence

play01:15

intervals that I didn't have it was able

play01:18

to predict the seasonality but you can

play01:20

just add seven because we know it's a

play01:23

weekly seasonality and if we apply it

play01:25

nothing's going to change because power

play01:26

bi does a very good job in picking up

play01:29

that seasonality the only thing that

play01:31

we're not being able to pick up very

play01:34

well is the excellent Trend here so if I

play01:37

turn the trend line on on this visual

play01:40

you can see that someone of upward trend

play01:43

going and we should be able to add that

play01:46

Trend into our data which will influence

play01:50

the forecast now we're able to do that

play01:53

with our python

play01:56

um

play01:57

model and you can see that instead of

play01:59

staying flat here we're able to pick up

play02:01

this trend and seasonality and I'm going

play02:04

to walk you through how to do that it's

play02:06

very easy so I'm going to jump over to a

play02:08

Jupiter notebook and then I'm going to

play02:10

jump back here and just show you how

play02:12

easy it is to implement the code

play02:17

so what we're doing in our Jupiter

play02:20

notebook we're just bring in the data

play02:22

that we need we're bringing in pandas

play02:24

matplotlibs Seaborn which we won't use

play02:27

but the model we're using is exponential

play02:30

smoothing now there are other models we

play02:32

can use that will probably be much more

play02:34

accurate but they will take a little bit

play02:35

more optimization

play02:37

then I'm bringing in seasonal decompose

play02:39

because I want to show you how we can

play02:41

see the seasonality and Trend and then

play02:43

I'm reading our data in using the web

play02:46

forecast here

play02:48

what I'm doing here is just switching

play02:50

the date I'm setting my index for my

play02:53

particular data set to date and I'm

play02:57

calling that data set TS

play03:00

then I need to set the frequency of that

play03:03

data set so we know that we have daily

play03:06

data so I'm just setting the frequency

play03:08

as d as in day and saving over it then

play03:13

if I plot that you can see exactly what

play03:15

we saw in our power bi notebook

play03:19

now here's what we can use to get a

play03:21

better idea of the components in our

play03:24

actual Trend so this first line is your

play03:26

actuals you can see it there

play03:29

but you can see the trend line here

play03:31

which we pick up with this seasonal

play03:33

decompose and we did do a video

play03:35

previously on how to decompose a Time

play03:37

series so you can see here that this is

play03:41

a trend that we need to add to the model

play03:43

here's a seasonality that we can add to

play03:45

both power bi model and the exponential

play03:49

smoothing model and you can see that

play03:51

here are the residuals or kind of the

play03:54

things that are unexpected in the data

play03:56

and those would be these particular

play03:58

points here and you can see as we get

play04:01

down to the end of our data we can see

play04:04

that there's a lot more events going on

play04:07

there

play04:08

so with this model we actually need to

play04:11

train it so the model is going to train

play04:15

on some data and then if we can test the

play04:18

model on some data we don't need to test

play04:20

this because

play04:21

um we're just going to use what the

play04:23

model gives us

play04:24

now there are 298 days in our data set

play04:28

and I told the model to remember

play04:32

290 of those days because we don't want

play04:35

to give the data the model all of the

play04:37

data because then it can't learn it's

play04:39

just copying

play04:41

so we have this training set which would

play04:44

just be the first 298 days out of that

play04:47

two for the 290 days out of the 298

play04:52

and then what I'm going to do is I'm

play04:55

going to use our model

play04:56

so you can see I've saved a variable

play04:58

model and then I am using exponential

play05:01

smoothing I'm passing in that training

play05:03

data set which is 290

play05:06

um days now I'm for my Trend I'm using

play05:09

an additive

play05:11

and for my seasonality I'm using

play05:13

multiplicative and for the season

play05:15

seasonal periods I'm using seven and

play05:19

then I'm fitting that data to the model

play05:21

now what does that additive Trend in a

play05:24

multiplicative trend mean so let me give

play05:26

you an idea of that

play05:29

so if we look at this visual here you

play05:33

can see if it's an additive model it's

play05:36

slowly adding

play05:38

you can see it slowly adds and then for

play05:41

a multiplicative model you can see

play05:43

there's quite a lot that is going on is

play05:45

exponentially growing so we can actually

play05:48

add that

play05:50

um seasonality additive or

play05:52

multiplicative to get a different type

play05:56

of prediction now I played around with

play05:58

it and usually you might play around

play06:00

with using a multiplicative here and an

play06:03

additive here to get a better idea but I

play06:05

think we can see for my data it is

play06:07

really growing when it comes to

play06:10

um the trend so I thought maybe

play06:13

additive but we can use multiplicative

play06:15

to see what we would get and then the

play06:18

seasonality here we can see that it's

play06:21

slightly growing also so like I said we

play06:24

can definitely change these so if I

play06:27

change both of these to additive and I

play06:30

run that particular uh

play06:33

data

play06:35

you can see it changes the actual

play06:39

prediction so if I add multiplicative to

play06:42

our model so mul

play06:44

and run that so now we have a

play06:46

multiplicative trend

play06:48

you can see that trend

play06:50

is a little bit bigger so if we add

play06:53

multiplicative to both so mul to Trend

play06:57

and seasonality and this would be you

play07:00

optimizing that model to give you the

play07:02

best result

play07:04

so

play07:05

once we have this forecast model we can

play07:09

use it to forecast 30 days in advance

play07:12

and that's what we're doing here we're

play07:14

using it to forecast a whole month in

play07:17

advance and we are doing the same in our

play07:20

power bi notebook

play07:21

so

play07:23

you can see if I go back to our power bi

play07:25

forecast

play07:28

look at the options we just doing that

play07:30

30 day length and now I'm going to show

play07:33

you how I implemented that code very

play07:35

easily within the power query so I'm

play07:38

going to go to transform data

play07:40

okay

play07:42

so now that we have that data in what we

play07:45

in the power query editor what we have

play07:47

we have our actuals and all I did was

play07:50

bring in the data and then added a new

play07:52

category uh with a custom category Uh

play07:56

custom column and use actuals because I

play07:58

want to be able to split between our

play08:00

actuals and forecasts

play08:01

so now if I go to forecast it you can

play08:04

see it's a much smaller data set it's

play08:06

that 30 days in the future

play08:09

and if we look at our python script you

play08:12

will see similar information here I

play08:16

brought in a data set saved it as DF

play08:18

because it's just easier to write I've

play08:20

created a date change the date to

play08:23

actually a date time set the index to

play08:26

date set our frequency

play08:29

to day then I brought in our exponential

play08:33

smoothing model from Holtz winter

play08:36

I took the first

play08:38

290 days as my training set and then I

play08:41

added that data to our model here so the

play08:45

model is our exponential smoothing model

play08:47

we add the training data we're using the

play08:50

trends here and I think we said we liked

play08:53

multiplicative so I'm going to change

play08:55

that back to mul and then we fit we gave

play08:58

it to seasonal periods which would be

play09:00

seven days which we could see in our

play09:02

data then all I did was get a new data

play09:05

frame or table with a forecast I reset

play09:09

the index and I just made sure they were

play09:11

named date and page view to match what

play09:15

we have in our original data so I'm just

play09:16

going to hit OK with that

play09:18

and you can see we are given all the

play09:20

variables within that data

play09:23

but we'll let the script run for a

play09:25

second

play09:27

then if I go down to

play09:29

what we have we have our predicted

play09:32

values here and then we have uh just a

play09:34

custom column which I have forecast now

play09:37

that we have all the same columns I just

play09:39

appended the two data sets where we have

play09:42

you know the actuals and the forecast

play09:48

then I'm just going to close close and

play09:51

apply this

play09:56

hopefully we didn't do anything to

play09:59

damage what we already created

play10:04

and now you can see that model slightly

play10:06

changed when we got to the

play10:08

multiplicative side of things so we can

play10:12

definitely easily do a forecast and

play10:15

maybe the advantage over the power bi

play10:17

one is that we can optimize the model a

play10:20

little bit more uh by changing the the

play10:23

additive nature of the trend and the

play10:27

seasonality which we are only given the

play10:30

option for seasonality here and also we

play10:32

can add Dell's predictions into our

play10:36

actual data set so I hope that helps you

play10:39

get a little bit better idea of how we

play10:42

can use forecasting uh there's a lot of

play10:45

different models out there but I kind of

play10:46

wanted to just give you a taste of what

play10:48

we could do we do have a few videos uh

play10:51

one of the videos I did before on

play10:53

seasonality decomposition which would be

play10:56

very helpful and there's a webinar that

play10:58

we have that goes over forecasting

play11:01

please ask any questions and I hope that

play11:03

helps hey everyone Thanks for tuning in

play11:06

to Enterprise DNA TV if you enjoyed the

play11:09

contents covered in this particular

play11:11

tutorial please throw the video a like

play11:13

it really helps us and we really

play11:15

appreciate it also don't forget to

play11:17

subscribe to the Enterprise DNA TV

play11:20

channel we we have a huge amount of

play11:22

content coming out all the time from

play11:24

myself and a range of content creators

play11:26

all dedicated to improving the way that

play11:30

you use power bi and the Power Platform

play11:33

lastly check out Enterprise DNA's

play11:35

website Plenty of resources and further

play11:38

learning that you can access very easily

play11:41

all the best

play11:43

take care

play11:45

[Music]

play11:58

[Music]

Rate This

5.0 / 5 (0 votes)

関連タグ
Power BIPythonForecastingData AnalysisSeasonalityTrend AnalysisExponential SmoothingModel OptimizationTime SeriesPredictive Analytics
英語で要約が必要ですか?