- 3 days ago
#PowerBITraining #learndataanalytics
Category
📚
LearningTranscript
00:00Hello everyone, welcome to another data science related tutorial writing slideshow.
00:06In this part, we are learning about creating an interactive Power BI dashboard with Python
00:14Seaborn library visuals.
00:16So all these visuals that you are seeing here are created with the help of Python scripting.
00:23We have imported the Seaborn library, matplotlib library.
00:27The Seaborn library is a popular library that is used to plot different kind of plots.
00:33So we will apply all of that in Power BI and these dashboards that we are creating or these
00:41visuals that we are creating are not only just visuals, just static images but for example
00:48if we are trying to apply different filters over here like regional filter you can see
00:55or you can apply any kind of other filter for example you can bring channel as a filter.
01:02So let me just show you.
01:04So I will clear that and what if we bring channel as a filter.
01:09So you will be able to see that on the basis of different filters it can be any field you
01:16will be able to see the change and change like for SMS channel what is the campaign success
01:23ratio.
01:24You can see for SMS marketing we have more successful campaigns around 60 of them and 40 were not
01:32successful.
01:33So this kind of analysis will be done in this project.
01:37So let's get started with it and just to introduce to get started I showed you three visuals but
01:45I will create some other visuals as well.
01:49Hello everyone.
01:50Welcome to the part 2 of marketing campaign success prediction with Power BI and AI where we are
01:56using Python in particular.
01:58In this part you will learn how to create these visuals.
02:03All these visuals are created with the seaborn library of python.
02:08Some of them are native Power BI just to show you that they can work together and we can use
02:14these interactive filters to filter them all.
02:18They are not just static images they are actually interactive graphs that are created with the help
02:24of this python visual.
02:26You will see the complete tutorial on python scripting to create these different visuals
02:33that we have here.
02:34So let's get started with that.
02:37So the data set that we are using here in this particular tutorial is the campaign success
02:43prediction data set which we used in the previous example where we created the entire Power BI
02:51dashboard right.
02:53So marketing campaign success prediction.
02:56So with Power BI and AI now just to introduce python we are using the same data set.
03:03So in that data set we have campaign ID marketing campaign ID what channel this marketing campaign
03:11used what our average audience size was there when we ran the campaign what was the budget for
03:18and how many days how many days it ran its click-through rate conversion rate region its product category
03:25that was being marketed previous engagement time of the year campaign success and this is the budget bin
03:34that was created.
03:35So you can ignore it for now.
03:37Now when we have to create a dashboard like this where we have to use python visuals.
03:44So let's open an empty page here.
03:47In the empty page we will simply create a text box and as you can see in the text box we will
03:55just copy this whatever we are doing here.
03:58So here I will just copy that text and I will just use it like this.
04:05So here you can see we have our text ready we can go to effects shadow visual border.
04:12This is completely native to Power BI no nothing extra is there and we can do some visual border.
04:21And this way our dashboard visuals will be ready.
04:26Now here since we are going to use python visual.
04:31So this is very very important for us.
04:33When you add a python visual Power BI may ask you to enable python visuals.
04:39Ok.
04:40So for that you can go to file and from here you can go to option and settings options.
04:47And in options you will find python scripting.
04:51So what we have done here we have used anaconda navigator's path here.
04:58So we have installed jupiter notebook.
05:02We have installed anaconda navigator ok.
05:06So if you are familiar with python data analysis with python you know that you can use anaconda
05:14navigator to create or to run self hosted Jupyter notebooks or local hosted Jupyter notebooks.
05:22Or if you have your simple python like we have python here.
05:28So you can open the file location.
05:31You will find where python is installed.
05:33Right.
05:34This is the shortcut.
05:35So you can investigate further and then you will see this is where your python is installed.
05:43So you can open you can browse and select that library.
05:47Ok.
05:48And detected python id default os program for py files.
05:53So make sure that python is properly configured here.
05:58This is very important.
05:59Now after doing that when we are creating visual.
06:04So this way python script editor will come.
06:07And in python script editor whatever you want to visualize first you have to select those columns.
06:16So in the first visual what we are doing here is we are analyzing campaign success by channel.
06:24Ok.
06:25So we ran different campaigns and we want to see campaign success.
06:30And campaign success is given as either 0 or 1.
06:34So this can be considered as a categorical column like yes or no kind of value.
06:44So we are doing campaign success by different channels.
06:48We want to know whether radio, sms, tv which one of them was more popular.
06:55So while creating the visual what you will do.
06:59We will always select campaign id because there we have all the unique values.
07:04Then we will have the campaign success column.
07:08So this is the campaign success column.
07:11So when you are selecting them you can see python visual is already preparing this data set for you.
07:18So data set is equal to pandas dot data frame.
07:22So pandas library is by default imported here.
07:26And in pandas library the data frame is a class which can create a 2d structure right.
07:34This 2d structure has rows, columns and index.
07:38So it's just like a table view you can see.
07:41So in pandas data frame you can select n number of columns that you are selecting here.
07:47So we have selected campaign id, campaign success and channel.
07:52We don't need to select everything every time.
07:55Like for example when we are trying to build this visual.
07:58We are selecting campaign id, campaign success and channel.
08:02Now first thing is to import the library.
08:06So we will import c1 as sns.
08:10We will import matplotlib.pyplot as plt.
08:19Because these 2 libraries will help us in creating the plots.
08:23Matplotlib library itself is sufficient to create the plots.
08:28But c1 has more advanced type of plots.
08:33Like which you can see here.
08:35For example distribution plot is plot, kd plot, rug plot.
08:39I will show you some examples.
08:41So that's why we are using c1 library.
08:45After doing that one simple thing that I do is I write df is equal to data set.
08:52So data frame is equal to data set.
08:55So because python stores the data set value here.
08:59This is optional.
09:00But now I am storing everything in df.
09:03Okay.
09:04So in c1 suppose this is the official documentation of c1.
09:10Let's say on c1 you have to create a bar plot or a count plot.
09:19Because we want to see how many successful campaigns are there.
09:23Right.
09:24So here you will also see a count plot.
09:28So count plot.
09:30Now in count plot first of all let's see what kind of graphs are created.
09:35Okay.
09:36Suppose we have 3 classes.
09:381st, 2nd and 3rd class.
09:40So a count plot will give us information on how many values of each kind are there.
09:49Okay.
09:50So here we write sns.countplot.
09:52There you write your data set name.
09:55You write x and in hue you can write something else that is categorical.
10:02So when we are creating this graph we want to see campaign success by channel.
10:09So we will count how many channels are there and then we will put campaign success as a hue.
10:18So when you will, hue is color.
10:20So when you will put something as a hue for every channel like here you can see for every channel like email, mobile etc. etc.
10:32It will create 2 plots.
10:34Right.
10:35For that what you will do, you will just write, you can simply copy this.
10:40So you can write sns.countplot.titanic.
10:44There as an example they are using the titanic.
10:48We are using df.
10:50X in our case will be channel because we want to see channel wise.
10:55Make sure you are writing the same case here and hue will be our target field that is campaign success.
11:03So when you will write that and then nothing will happen.
11:07Okay.
11:08So because you can see nothing is happening.
11:13It says no image was created.
11:17Now remember whenever you are using python visuals and that is the whole purpose of importing manplotlib.pyplot.
11:26We just have to use plt.show to create that image, that visual.
11:33Okay.
11:34And this will show us.
11:36Again this is a simple way of using this style.
11:41And here you can see we have a simple visual.
11:45Okay.
11:46And here the default palette is selected.
11:50And you can see in radio we have most number of successful campaigns.
11:57And then in sms then you can see for every channel they are not arranged.
12:03But you can see zero represents unsuccessful.
12:07Orange represents successful.
12:09Here I will give you this code also in one file.
12:14And in the code you can also use some other kind of palette.
12:18So for example you can set style as wide grid or use other kind of palette.
12:24So that's what we have done in this first part.
12:27So here I have used the palette that I have used is wide grid.
12:33And you can see first of all the style that I am using for visuals is wide grid.
12:41So you can use sns.set wide grid.
12:46In count plot we are using x is equal to channel y is equal to hue.
12:51Okay.
12:52So here x is equal to channel y is equal to and hue is equal to campaign success.
12:58Then you can also show it like stat is equal to percentage.
13:03Okay.
13:04So you can use that as well or just use palette.
13:07I will provide you all this code.
13:09You can also give some size to your visual.
13:14So for example here we can use palette is equal to set to.
13:20And finally if you want you can set title from here.
13:25But since we are using it in Power BI the titles will be set from here.
13:31Okay.
13:32So this so simple title for this will be campaign success by channel.
13:38And when you will put that we can use text color as this color and align it to center apply 15.
13:47So this will create the similar kind of graph that you saw there.
13:52So campaign success by channel we can increase its width and height a little bit.
13:58And here what we can do obviously one more thing.
14:02Like we have displayed the title we can increase it height.
14:05We can make it bold etc can be done.
14:08And when you will increase its height it will be responsive.
14:13So it will take that container.
14:15Now in this container we can go to effects.
14:18We can enable a shadow a visual border.
14:22And we can select some border color from here.
14:25And apply like this.
14:27So this is how you can create your first visual.
14:30Then what this visual is representing.
14:33This is when we have to see conversion rate.
14:37Like conversion rate is kind of representing our success.
14:41Right.
14:42And campaign success is either 0 or 1.
14:47So conversion rate and CTR.
14:50That means click through rate of the campaign.
14:53So you saw an advertisement.
14:55You clicked on it.
14:56So click through rate is 2.62 percentage.
14:59Right.
15:00So click through rate and conversion rate.
15:03On the basis of click through rate.
15:05What is conversion rate?
15:06We are just seeing that.
15:08So when you have two numerical values.
15:10You can create a simple scatter plot in Powerbiya also.
15:14Here also we are creating a simple scatter plot.
15:17So here since we are selecting three elements.
15:22Which is CTR, conversion rate and campaign success.
15:26Okay.
15:27So now you will just create a pie visual.
15:30Let me show you in blank.
15:32So you will just create a pie visual.
15:36And in pie visual you will select.
15:39For example here we want CTR, conversion rate and campaign success.
15:45Okay.
15:46And now you will create the simple graph.
15:49For example we have the graph here.
15:52So here you will create SNS dot scatter plot.
15:57In SNS dot scatter plot same arguments.
16:00Data is equal to DF.
16:02Your X will be something that is independent.
16:06That is your click through rate.
16:08Y will be on the basis of click through rate.
16:11How much?
16:12What is the conversion rate?
16:14And hue that is color.
16:16So we are categorizing as campaign success.
16:19So we will simply copy this entire thing.
16:22So import C1, import matplot, SNS dot set.
16:26So for all visuals.
16:27This is a weird thing.
16:29But for all visuals we have to do this.
16:32And just after these comments are finished.
16:35You just have to create that.
16:37And then your second graph will be created.
16:42Right.
16:43And as you did for earlier graph.
16:45You can enable visual border, shadow.
16:49You can choose a different type of color for your borders.
16:55And you can also make your title bold.
16:58Increase its height.
17:00Make its center.
17:01Align its center.
17:02Use bold font.
17:04So you can use it like that.
17:06For your border you can give some kind of rounded shape.
17:10So all of that can be done here.
17:13So this is how you can create the second chart.
17:16For the third chart that we have quarterly budget.
17:20So here now you can understand.
17:23We want to show quarterly budget.
17:26In the data set time is given as quarter only.
17:30Like quarter 1, 2, 3, 4.
17:33So we want to see quarterly budget.
17:35And for every quarter.
17:38So you can see for all the successful campaigns.
17:42For different quarters.
17:44What is the quarterly budget.
17:46And for unsuccessful campaigns.
17:50What is the quarterly budget.
17:52Which kind of gives an indication that.
17:55On the basis of quarterly budget.
17:57We can.
17:58Like if quarterly budget is more.
17:59Chances of having a successful campaign.
18:00Are also more.
18:01So here.
18:02Same thing.
18:03Seaborn matplot clip.
18:04We create data set.
18:05Here the plot that we are creating.
18:06Is a line plot.
18:07So.
18:08We have seen account plot.
18:09To count.
18:10Count of different.
18:11Categorical values.
18:12In your data.
18:13Then we use a scatter plot.
18:14To create relationship between.
18:15To find out relationship between two.
18:16numerical values.
18:17Like.
18:18If you increase one.
18:19What is the effect on other.
18:20Then this is line plot.
18:34Suitable for something related to time.
18:35When it is on x axis.
18:37So we can create a line plot.
18:40That's why.
18:41If it's a line plot.
18:42so we can create our line code that's why on x-axis we are putting time of year
18:47y-axis we are putting budget and hue that is our target field which we are selecting as
18:53campaign success whether zero or one so we have created this so let's copy this
19:00and we will simply put it here now to create the interactive filters okay we have some area over
19:09here which we can use for creating filters so to create a filter we use a slicer so we will put
19:21a slicer over here let's reduce its width because we need to create more slicers we will use format
19:29painter to format everything and in the slicer the first thing that we will bring is our channel
19:37our channels can be email radio etc in slicer setting in previous example i use tile okay so when
19:46you will use tile you will be able to see that it will create a button like effect so just we can see
19:55tile email radio etc but you if you will show it like a drop down then also it will be easier for
20:02user to interact with now here we have a slicer header let's select a different color let's select
20:12a green color for our heading then it is channel we can increase its height and these are values
20:22so for values we will select a blue color as we did in previous example also and we will select bold
20:29bold so now we have channel as a filter and we will create another copy of it okay and since we have
20:39selected channel second thing that we have selected is quarter so time of year which can be a quarter
20:47we will select here so let's say performance in quarter one so you will see it will filter everything
20:54okay because here we are showing quarterly so you will be able to see that and we will select quarter
21:00one and two let's see now you can see this graph will pick both the quarters right so this way for
21:06every quarter you will be able to see the performance obviously this will be little bit slower than native
21:12power bi visuals but here we are just exploring if we can create some hybrid kind of report right it's not
21:24necessarily that you put all python visuals here let's say we want to include one visual here where we want
21:32to see product category wise uh you know conversion average conversion rate so we can bring product category here and in values we can bring conversion rate and we can bring average conversion rate so this
21:51is a native visual right a native to power bi so we can include that just i am showing you and
21:58these all will work together like a family so here also we can add shadow visual border obviously i can
22:07copy them copy the styling but i have seen when i copy styling from python visuals it somehow you know
22:16interacts with like it resets something so i'm just not doing that in title you will simply choose this color
22:25make it apply you know align it center so this is average conversion rate by
22:35category or product category whatever you want to write
22:41so this we can show here and we can make it bold so this is our native graph and you can see
22:48see these filters will work here so this is faster but they they will take some time to load but
22:58now this gives us more versatility this gives us more freedom to use our python knowledge or c bonds
23:06library because in c bonds library there are some visuals which are really really great and particularly in
23:13python also right we can apply different type of machine learning visualizations here which we will cover
23:20also in this project we are using all of this right we are using marketing company success prediction with
23:30power bi then we are just demonstrating how to use c bond python's library for it and then after exploring
23:39everything we will apply some machine learning algorithms with the help of the sk learn library
23:49here i also want to show you the use of some other plot for example that is not there but in
24:00power bi by default for example
24:02we want to see distribution of something so we have hist plot histogram histogram histogram is not by
24:13default there in power bi although there are ways to create histogram so here in histogram you use one single
24:21variable okay so we want to see distribution of something for example like what is the distribution of
24:32total budget right or audience size anything so we will see budget here and for that let's create a visual
24:45so in this visual what i am going to select is campaign id and budget these two things okay then i will import
24:54see one as sns etc so let's copy quickly so i will just copy this much because this will be the same for every graph
25:06now to create a histogram plot we write sns dot hist plot right so we write it like this sns dot hist plot
25:17and x and x in data set we will write df and in x i will write budget because that is what we want to see as a distribution
25:29and then you can use palette etc whatever but here when you will do that you will see the distribution
25:37and again we have to write plt dot show in order to show the image
25:43so when you will do that it will start showing us a simple distribution right now let's explore other
25:52parameters so that's what you have to do as a accessence here there are many other parameters like
25:58bins how many bins do you want currently the bins is equal to auto okay element is bar so bins let's say we
26:08want to show five bins currently there are many bins right so we can say bins is equal to five let's try
26:17that so when you will do that so it will show us five bins so this is important and what it is showing us
26:27that campaigns in budget range of 0 to 5 000 are more or 25 000 to 30 000 are more in the range of 15 000
26:38are less so this is showing us distribution of campaigns on the basis of budget range so this is
26:45maybe 5000 5000 to 10 000 10 000 15 000 20 000 to 25 000 so on right now as a hue here also if we bring
27:00campaign success so but i have not selected that so let's select campaign success so as a when i will
27:08select campaign success as a simply write it here campaign so it technically it should show us the distribution right so now it is
27:23showing us that when the budget is more okay it will adjust itself so when the budget is more we have more
27:32successful campaigns okay when the budget is less we have more unsuccessful campaigns so this is what we
27:41can get from and this is why it is very important so now we will do the same thing enable that actually i
27:50tried copy the copying the formatting but somehow it reset and everything so i am just doing it manually
27:59every time so this is distribution of budget and success like campaign success and we will align it to center method goal
28:14so this way we can see you know how on the basis of budget distribution we have more successful campaigns
28:25and this is something that is evident from this particular quarterly budget and success also now there is one more interesting plot in c bond that is called a joint plot
28:39so they have given example of penguin data set where penguins bill length and bill depth they are trying to see the relationship between bill length and bill depth
28:49and we are also seeing the distribution of these two numerical values on the top so let's try whether we can build this in our case the campaign success data set
29:06so again the simple thing is first let's create a pipe that what i want to analyze is if they have some previous engagements right
29:17so if they had previous engagements then on the basis of previous engagements what is the effect
29:25on conversion rate or what is the effect on ctr right so you can select any one of them
29:34or even we can simply select campaign success because in campaign success we have either zero or one
29:40so but we will select previous engagement versus conversion rate so the values that we are going to select is campaign id
29:51which because it's unique so we are selecting it every time previous engagements and conversion rate
29:59and campaign success okay now we will do the same thing copy this thing here and now we will use the joint plot
30:13so sns dot joint plot which takes x and y so we will provide x as how many previous engagements did they have
30:24and on the basis of that what is conversion rate and write plt dot show okay let's try to create the visual
30:37so it is not showing let's see why and before seeing why i can see the data is different so i forgot to change the data
30:46so let's see so now you can see that graph first we are going to change the title which is previous engagement versus
31:01conversion rate right versus conversion rate let's use 15 make it bold choose this color align it to center
31:14now we have the graph so what this is showing us is that there is no evident relation between
31:25previous engagement and conversion rate first of all like we can see it's not we are seeing some linear trend
31:33or something so this is scattered all over the place in terms of distribution of previous engagements
31:39you can see you can see we have more cases where previous number of engagements are 80 and similarly in
31:48case of conversion rate we have more campaigns with conversion rate between this range 1.6 to 1.75 this is
31:57what we can see here and since more all of the graphs in c1 support hue like in hue we can put our
32:09target field so you can see here that we can see the campaign success now now there is an interesting thing
32:19so all the successful campaigns are plan we have more previous engagement versus conversion rate you can see
32:28and unsuccessful campaigns are when we have less number of previous engagements and successful rate
32:35so that means these three variables these two variables are very much important for us to put in our
32:42you know machine learning model and you can see the distribution also like more number of cases are of
32:49successful campaigns here and this is how distribution what distribution is showing us so from these two
32:57plots we can see the example so this is very very important chart and very useful i will say to understand
33:07the effect of conversion rate and previous engagement like what sort of values are effective so that means if
33:14we create a campaign that can drive more engagement so we can drive more conversion rate also and hence more
33:23successful campaigns that's why you will see campaigns which have more interesting things like people don't skip those
33:32advertisements or some kind of text that works like a click bait kind of thing in a positive way or distracts
33:42people in a positive way those type of campaigns work well because dudes have more click-through rate and
33:51once we have more click-through rate then obviously our chances of success are also there but obviously
33:58when people you know go to your landing page so then also the content quality of your content should match
34:08everything so this is very important and now this is what our simple python visual tells us so this is part two
34:18where after doing it in power bi we are doing it here and we have full chapter of c1 like
34:30we have our udemy course where we have taught data analysis using pandas c1 matplotlib etc
34:40libraries in detail i will provide that link to you that udemy course link you can enroll into that if you want
34:48or just keep following our series subscribe to our channel so that you can receive more interesting
34:55videos like this thanks for watching have a nice day
35:08you
Recommended
10:25
|
Up next
22:17
1:12
0:46
2:11