Hello my friends.
Welcome back to the. Practical activities, this time.
On the A club model still in.
Association rule learning.
All right.
So this tutorial is actually going to be a quick one because.
As you understood in Kairos Intuition. Lecture.
Well the model is actually a simplified version
of the Priory model because we only deal with the supports.
And we don't even have. Rules.
We only consider a set of products of which we analyze the support.
So it's way simpler than the Priory model.
And therefore that leads to the second reason why this will be quick.
Really, if you have to choose.
An association rule learning model to.
Do association rule. Mining.
I by no doubt. Recommend the Priory model.
However, it's possible.
That in some.
Business problems you will only consider the support.
You know you're only. Interested in doing. A support analysis.
And therefore you might. Use it.
In exceptional. Situations.
But still, even with a priory you can do this.
So that's why it's going to be quick.
And besides, the way we're going to build.
You know, in Python.
Is by just adapting our A.
Priory.
Model so that we only consider the support right.
Because indeed the class doesn't.
Include any confidence or.
Lift. Analysis. Okay.
So let's do this quickly.
This will. You know, give you an extra. Association. Rule.
Learning model in the toolkit.
So that's still good anyways.
But really the focus should be on the Priory model.
All right.
So before we start let's make sure.
Everyone here is on the same page.
I give you the link to this folder right before this tutorial.
So make sure to connect to it.
And now.
Let's all go into part five Association.
Rule learning.
Then section 29 Eeglab and Python where you will find two.
Files the.
Clamato in ipynb format and the same data.
Set market basket. Optimization.
Let's quickly remind the scenario.
There is a shop. Owner in the south of France.
Who would like to boost the sales of the shop, and therefore.
He's trying to find the best association of.
Products to sell to the.
Customers in a deal.
And the deal.
That this owner. Has in mind is the following.
Buy one product and get another one for free.
So this time we're going to use.
A Clat analysis to analyze the highest supports.
Of combination of. Products. Here.
Two products because the deal is buy.
One, get another. One for free.
So well, that's exactly.
The same scenario as an a. Priori.
And therefore let's directly.
Get into the implementation.
All right. Let's open. It. We're going to open it.
With either Google Colaboratory or Jupyter Notebook.
Choose your favorite. And
now the notebook is opening.
Soon it will be laying out.
And in a second we should have it.
There we go.
All right. So loading it.
Then laying it out and there. We go. We have it.
So that's the. Implementation.
As you will notice it.
Is very similar to the a.
Priori implementation because.
Indeed the way I built.
The model.
Is just by adapting this binary package to the.
Model by only considering the. Support.
And I'm going to show you. Exactly how I. Did it.
You know, I'm going to show you from. Scratch how I.
Turned that.
A priori.
Implementation into.
This new. Implementation.
So here instead of, you know, creating.
A copy of this.
Implementation and then, you know, removing.
All the cells and. Re-Implementing them from scratch.
We're. Going to take instead.
Our a priori. Implementation.
Then we're going.
To create a copy of.
This implementation by clicking here on. Save a.
Copy and drive. And then. That's where.
You know that's on this.
Copy that.
I will show you how I.
Transformed this a priori implementation into. The.
Implementation. All right. Are you ready.
Let's do this.
So the first thing I did was to well, very.
Simply change the name here. Of the.
Ipynb file. And I called. It.
All right.
Let's start with the simplest change then.
Still very simple.
I change the title here from primary.
To I'm really showing you everything I did.
To make that extra implementation.
Then I looked.
Section after section and see if I had to change anything.
Here we still have to install this package because.
You know, we're building the model.
Through a simplified. Version of. The.
Primary model. So let's keep this.
We can remove all.
The outputs here because we will rerun.
Everything.
Then I get the three. Same libraries. Here.
I came to the same data preprocessing phase.
You know because indeed we still need that transactions list
containing all the transactions into a list.
All right.
Then here when training the primary model on the data. Set.
Well same.
I kept everything we could.
Even, you know, remove the min confidence.
And min lived here in order to.
Really only consider the support.
But I recommend to still keep them
because, you know, these two will give you even stronger associations.
So I don't. Recommend to remove them. And then.
I kept these because we're.
Still in the same scenario to find the. Best deals.
Buy one product, get another product for. Free.
So we still have to keep this.
But then in the end, I'll explain how to. Run.
Some analysis on a. Larger set of product.
Right? Because remember that. With Eeglab.
We're not considering rules.
But sets of. Products.
And that's because we're only considering the supports. You know.
The support of a set of products like let's say A, B, C, which is of course.
The number of transactions containing the.
Products A, B and C divided by the.
Total number of transactions. Right. So that's why there is not this.
Direction and. Therefore these rules okay.
So here I kept exactly the same.
We can, you know, change.
A priory here by a if you want.
Depending on how you. Want to see it. Okay.
And then when visualizing the.
Results that's where I'll show you what I did.
As a main change.
You know, as an essential change here.
I didn't change anything.
I still displayed all the rules.
You know, in this.
List of complicated structure.
But then. Here. When, you know, putting.
All the results, you know, all the rules well.
Organized into a pandas dataframe.
Well, I'm going to show. You what I did.
Let's scroll. Down.
Well, this time, since we no longer.
Have. Confidences and.
Lifts for our rules, well, very simply I took this.
And then I removed.
These two. Rows.
You know, the confidences and the. Lifts.
Removed. Of. That inspect function.
And then same.
Obviously we have to remove that here as well.
Right. Because for.
The A there is no confidence or. Lift.
So there we go.
And same in the columns names here.
You know when creating the final data frame nicely visualizing the result.
Well I removed of course confidence and lift here.
And I even.
Replaced. You know left hand side.
By actually.
Product one and right hand side by.
Product two.
And that's because.
You know in the middle there is no. Rule.
You know, we're only considering. Set of products and therefore.
There is no question of left hand.
Side or right hand side of a rule. All right.
So that's what. I changed in the.
Cell. Then. In this. Cell.
Well I simply had. To remove it because you know.
The principle of the model is just to.
Return the different. Sets by.
Descending supports, you know, from the highest.
Support to the lowest. One.
And therefore here we absolutely need to sort these supports directly.
So I just remove the cell. And this one as well.
So that we can directly display the results by.
Descending not. Lifts but supports.
All right.
And of course to do this here we had to replace lift by support.
And now it.
Should be all good.
Let's remove this and. Let's.
Rerun everything.
You know we can also remove this by the way.
Right. We have no. Output.
So now we're going to rerun everything.
But first let's. Not forget to upload the.
Data set inside a notebook.
All right.
So right now the notebook is connecting to a runtime to enable file browsing.
And in a second we.
Should see that upload. Button. There we go.
All right let's upload.
Then please fine.
Your machine learning is that and.
Data set folder. In your machine and go to.
Part five Association Rule. Learning.
Then section 29 Python.
And there you go.
Please select your data sets market basket optimization.
All right.
So this will. Upload it inside a. Notebook.
In a second.
Right.
It's a big data set. There we go. Perfect.
And now we're simply going to run everything and make sure.
Everything works properly by clicking.
Runtime here.
And then run.
Oh. So first.
It will install. That a binary package.
The same way by first
downloading it from the link and then installing it into the notebook.
There we go.
Then importing the libraries and data preprocessing. Phase.
Then the training and then the. Results.
So here we have of course the same results as before.
But then. For the.
Final results, which are.
Supposed to be the final output of the model.
Well there you go.
You have them.
Here displaying the results sorted by.
Descending support. And indeed. We see the.
Combination of two products, you know, the. Set of two.
Products from the highest.
Support, oh point.
0159, which means one point.
Six. Percent down to.
The lowest.
Support, you know, for the ten highest. Support.
Ten sets. Of products. With the ten highest. Support.
All right.
And that's, you know, exactly what the output.
Of the model. Is supposed to be.
So you see, we simply built this.
Model by.
Adapting. The Priory model. To the. Model.
And returning the exact same.
Output as it is supposed to.
Give us, meaning.
The set of products having the highest supports.
And then if you want to perform an.
Analysis with larger sets of bricks.
Because here we only do this for sets of two products.
Well, very simply, you just need to.
You know, in the training.
Cell, you just need to.
Change these parameters from index equals to you can keep this one
but then increasing the maximum length. And this will.
Give you some larger set of products.
And even if you know you will have.
This set of several.
Products here and then one per here, because, you know, there is still.
This. Direction as in a rule.
Well, that's fine, because then the support.
Of a rule with several products.
On the left hand side and one product on the right hand side.
Well, is still.
The same support. Of the.
Set containing all. These products. All right.
So that's how you would use this.
Implementation for a.
Larger set of products okay. So good.
Let's have a quick look at the result.
Well we have. Kind of the same ones as. Before, but.
This time in a different. Order because we.
Sorted them by descending. Supports.
But there you go.
The set of two products that.
Appear most frequently in the store.
You know there uppercase most frequently are herb.
And pepper with ground beef.
Whole wheat pasta with olive oil, pasta with scallop.
Mushroom cream sauce with scallop.
You know.
All. These seem very relevant associations.
Leading to exquisite meals cooked at home.
Right?
All this actually makes me kind of hungry.
Okay, so there you go.
So you have now an extra association rule learning model in your toolkit.
That is all nicely.
Adapted. From the Priory model.
But remember my recommendation.
I still. Recommend to.
Work with the Priory. Model.
Because these extra metrics, such as the.
Confidence and the lift.
Will give you.
Much stronger results in the end.
But good that you have. The two models.
And now we're going to move on.
To a very exciting part, which is.
Reinforcement learning.
And you have to know. That here we will.
Actually make a.
Step a lot closer to artificial.
Intelligence. Because reinforcement.
Learning is two branch of machine learning.
With which you know. You can implement.
Robotics. You know, robots.
And of course, in part six we will not implement a robot.
But still you will get the basics of.
Artificial intelligence and how you can build.
Robots.
So I can't wait to. See you in this next part.
You can actually hear by the sound of my voice.
That reinforcement.
Learning is one of my favorite branches of machine learning, and my favorite.
Application. Of. AI. So I'll be more than happy to.
Teach it to you. And until then, enjoy machine learning.