﻿1
00:00:00,133 --> 00:00:00,966
Hello, my friends.

2
00:00:00,966 --> 00:00:04,033
All right, here we are at the final,
very exciting step

3
00:00:04,033 --> 00:00:07,633
of this implementation
where we visualize the results.

4
00:00:07,633 --> 00:00:11,066
So we're going to clearly visualize
the rules and see for each of them,

5
00:00:11,133 --> 00:00:13,933
you know, their support, their confidence
and their lift.

6
00:00:13,933 --> 00:00:17,133
And mostly we're going to see
which are going to be the best deals

7
00:00:17,133 --> 00:00:19,400
by one product
and get another one for free.

8
00:00:19,400 --> 00:00:23,500
Will clearly see which food goes
well with some other food

9
00:00:23,666 --> 00:00:26,500
for these French people
in the south of France.

10
00:00:26,500 --> 00:00:28,266
Okay, so let's do this.

11
00:00:28,266 --> 00:00:32,500
We already have the rules here, which were
the output of this primary function.

12
00:00:32,833 --> 00:00:36,266
So you will see that
it will be very simple to display them.

13
00:00:36,366 --> 00:00:41,633
Therefore let's select that cell in order
to create a new code cell just below.

14
00:00:41,800 --> 00:00:45,766
And indeed, in order
to have a first look at these rules, well,

15
00:00:45,766 --> 00:00:49,766
we simply need to create a new variable
which we're going to call results.

16
00:00:49,800 --> 00:00:53,300
You know, the results of this, a model
which are nothing else than the rule.

17
00:00:53,333 --> 00:00:55,133
But see what I'm going to do?

18
00:00:55,133 --> 00:01:00,000
I'm going to set this result variable
as a list of

19
00:01:00,266 --> 00:01:03,800
the rules, which will just put these rules
into a list.

20
00:01:03,800 --> 00:01:05,066
Right? As simple as that.

21
00:01:05,066 --> 00:01:07,700
We just want to have our rules
into a list.

22
00:01:07,700 --> 00:01:11,033
So that then when we display the results,
you know, by

23
00:01:11,033 --> 00:01:14,866
just calling this variable
and executing this cell, indeed

24
00:01:15,000 --> 00:01:18,733
we will get in the output
all our rules in this list.

25
00:01:18,733 --> 00:01:21,900
You recognize the square brackets here
and at the end as well.

26
00:01:22,100 --> 00:01:22,400
All right.

27
00:01:22,400 --> 00:01:27,166
So all these rules are listed one by one,
you know in different rows.

28
00:01:27,600 --> 00:01:30,133
All right so there you go.
These are all the rules.

29
00:01:30,133 --> 00:01:33,933
You know all the rules
following these criteria a minimum support

30
00:01:33,933 --> 00:01:38,400
of 0.3 percent, a minimum confidence
of 0.2, a minimum lift of three.

31
00:01:38,533 --> 00:01:39,166
And of course

32
00:01:39,166 --> 00:01:42,900
two products in the rules, you know,
one on the left and one on the right.

33
00:01:43,466 --> 00:01:43,733
All right.

34
00:01:43,733 --> 00:01:47,066
So let's have a look at them
one by one starting with the first one.

35
00:01:47,066 --> 00:01:48,600
So that's the first rule here.

36
00:01:48,600 --> 00:01:50,000
And what do we see.

37
00:01:50,000 --> 00:01:53,100
Well I'm just going to you know
highlight it.

38
00:01:53,400 --> 00:01:55,333
All right. So that's the first rule.

39
00:01:55,333 --> 00:01:56,666
All right. So let's see.

40
00:01:56,666 --> 00:02:01,466
First we see that the two products in
this rule are live cream and chicken.

41
00:02:01,466 --> 00:02:03,633
But be careful the order is not.

42
00:02:03,633 --> 00:02:06,466
If customers buy light cream
then they will buy chicken.

43
00:02:06,466 --> 00:02:08,366
No it's actually the other way around.

44
00:02:08,366 --> 00:02:12,300
Because indeed if we scroll to the right
well that's important.

45
00:02:12,300 --> 00:02:17,433
You see, items base
is equal to light cream and then items add

46
00:02:17,600 --> 00:02:18,766
is equal to chicken.

47
00:02:18,766 --> 00:02:22,500
So that means that actually the left hand
side of the rule is light cream.

48
00:02:22,633 --> 00:02:26,400
And the right hand
side of the rule is chicken okay.

49
00:02:26,400 --> 00:02:29,300
So that means that
if people buy live cream

50
00:02:29,300 --> 00:02:32,033
then they will have a high chance to buy
chicken.

51
00:02:32,033 --> 00:02:36,300
And that high chance is actually measured
by the confidence, which is 0.19 here.

52
00:02:36,300 --> 00:02:40,300
So that means that if customers
buy light cream, then they will have

53
00:02:40,300 --> 00:02:44,366
29% chance of buying chicken,
which makes sense, right?

54
00:02:44,400 --> 00:02:47,533
Well, at least in France,
because usually French people love to put

55
00:02:47,533 --> 00:02:52,100
some nice light cream with lemon
as a sauce for their chicken.

56
00:02:52,100 --> 00:02:54,666
Right?
It's a common traditional French meal.

57
00:02:54,666 --> 00:02:56,866
I actually really enjoyed myself.

58
00:02:56,866 --> 00:02:57,266
All right.

59
00:02:57,266 --> 00:03:00,933
And then we can also see the lift,
which is very good. 14.

60
00:03:00,933 --> 00:03:05,700
84 I remind that all our rules here
will have lift larger than three.

61
00:03:05,866 --> 00:03:07,200
And then where is the support?

62
00:03:07,200 --> 00:03:09,600
The support is right here.

63
00:03:09,600 --> 00:03:14,000
The support is 0.0 45,
meaning that the rule containing

64
00:03:14,000 --> 00:03:18,700
these two products appears in
oh point 45% of the transactions.

65
00:03:19,166 --> 00:03:20,733
All right then, let's see what we have.

66
00:03:20,733 --> 00:03:24,000
So the second one is mushroom cream sauce.

67
00:03:24,000 --> 00:03:27,933
But same the items base is mushroom
cream sauce.

68
00:03:27,933 --> 00:03:32,100
And the items at is zero,
meaning that if customers buy

69
00:03:32,100 --> 00:03:36,033
mushroom cream sauce then they will have
a high chance of buying scallop.

70
00:03:36,166 --> 00:03:39,866
And that high chance is 30%, right, 30%,

71
00:03:39,866 --> 00:03:42,866
and the lift is 3.793.8

72
00:03:43,033 --> 00:03:46,600
and the support is 0.05.

73
00:03:46,633 --> 00:03:47,766
Okay. Good.

74
00:03:47,766 --> 00:03:50,166
So you see you have all these rules.
They look great.

75
00:03:50,166 --> 00:03:54,766
But we would actually appreciate
a nice way to have a look at them

76
00:03:54,866 --> 00:03:57,966
because here you see we have to do
these scrolls to the right and left.

77
00:03:57,966 --> 00:03:59,533
And it's a bit overwhelming.

78
00:03:59,533 --> 00:04:04,133
So don't worry I actually found
a good code snippet online.

79
00:04:04,133 --> 00:04:07,333
I think it was from StackOverflow
or another source like that.

80
00:04:07,500 --> 00:04:12,166
So we're going to use that code snippet
to actually put the results

81
00:04:12,166 --> 00:04:15,166
well organized into a pandas dataframe.

82
00:04:15,233 --> 00:04:18,900
We won't have to re-implement that code
snippet from scratch, because, you know,

83
00:04:19,133 --> 00:04:23,266
it is very specific to this association
rule learning implementation.

84
00:04:23,266 --> 00:04:26,100
And therefore
you will just see that once in your life.

85
00:04:26,100 --> 00:04:27,700
So it's not essential.

86
00:04:27,700 --> 00:04:31,933
And therefore we will just copy and paste
it here from our original implementation.

87
00:04:32,100 --> 00:04:35,100
But of course
I will explain to you the code.

88
00:04:35,100 --> 00:04:36,200
So let's get it first.

89
00:04:36,200 --> 00:04:40,166
It's actually at the bottom
and it is this one.

90
00:04:40,266 --> 00:04:40,933
All right.

91
00:04:40,933 --> 00:04:45,166
We make an inspect function
which will return the rules.

92
00:04:45,166 --> 00:04:48,600
Meaning these rules will organized
into a pandas dataframe.

93
00:04:48,600 --> 00:04:51,766
And the cool thing about this
is that we will even be able

94
00:04:51,766 --> 00:04:55,733
to sort the rules
by a descending metric, right?

95
00:04:55,733 --> 00:04:58,766
Because if we notice here, well,
they're not sorted.

96
00:04:58,766 --> 00:05:04,033
You know, the lift store at 4.84
then goes down to 3.79

97
00:05:04,033 --> 00:05:07,700
and then goes back up to 4.7
and here 5.16.

98
00:05:08,000 --> 00:05:11,233
And remember that
the lift is actually the most relevant

99
00:05:11,266 --> 00:05:14,466
metric to measure the strength of a rule,
you know.

100
00:05:14,466 --> 00:05:18,466
So if we want to store the rule, you know,
to get the strongest one, if we want to,

101
00:05:18,466 --> 00:05:22,233
you know, select a few deals, well,
we would rather do it with the lift.

102
00:05:22,466 --> 00:05:24,000
So what will be really nice here.

103
00:05:24,000 --> 00:05:28,133
You know, when putting these results into
a well organized pandas dataframe is that

104
00:05:28,133 --> 00:05:33,233
then we will be able to sort easily
the rules by the lift or another metric.

105
00:05:33,600 --> 00:05:36,233
All right. So let's get this function.

106
00:05:36,233 --> 00:05:38,933
I'm going to copy it here

107
00:05:38,933 --> 00:05:44,333
and we will paste it inside our
implementation right here.

108
00:05:45,300 --> 00:05:45,966
There we go.

109
00:05:45,966 --> 00:05:46,766
Paste.

110
00:05:46,766 --> 00:05:49,000
And now let me explain to you
how it works.

111
00:05:49,000 --> 00:05:53,666
So as we can see it is a function
that takes as input the results meaning

112
00:05:53,733 --> 00:05:57,966
these results, the rules as they are
right now, you know, organized this way.

113
00:05:58,500 --> 00:06:00,966
And then it will take separately
the left hand

114
00:06:00,966 --> 00:06:03,966
side of the rule, meaning the product
at the left hand side of the rule,

115
00:06:04,000 --> 00:06:06,766
then the product at the right hand
side of the rule,

116
00:06:06,766 --> 00:06:10,300
then the support of all the rules,
then the confidences,

117
00:06:10,500 --> 00:06:12,200
the lift of these rules,

118
00:06:12,200 --> 00:06:15,066
and then it will return all the rules
with the left hand sides

119
00:06:15,066 --> 00:06:16,133
and the right hand side.

120
00:06:16,133 --> 00:06:19,433
And there are supports, confidences
and lifts inside the list.

121
00:06:19,433 --> 00:06:22,166
Right. That's
why we have this list function here again.

122
00:06:22,166 --> 00:06:24,633
All right. So that's what
this inspect function will do.

123
00:06:24,633 --> 00:06:27,633
And then at the end
we create the final pandas dataframe

124
00:06:27,700 --> 00:06:31,266
which takes as input
the output of this inspect function.

125
00:06:31,466 --> 00:06:33,266
And besides we add the column names.

126
00:06:33,266 --> 00:06:36,266
You know the first column
will be the left hand side of the rule.

127
00:06:36,266 --> 00:06:39,000
The second column will be the right hand
side of the rule.

128
00:06:39,000 --> 00:06:42,233
The third column will be the support
for the confidence.

129
00:06:42,233 --> 00:06:43,600
And finally the lift.

130
00:06:43,600 --> 00:06:47,266
So we will have a super nice table
with these columns

131
00:06:47,500 --> 00:06:51,433
and giving all the important informations
for each of the rules.

132
00:06:51,433 --> 00:06:54,066
Okay, so that will be super practical.

133
00:06:54,066 --> 00:06:57,800
And now let me explain how you know
we get each of these elements,

134
00:06:57,800 --> 00:07:01,200
you know the left hand side
and then the right hand side.

135
00:07:01,533 --> 00:07:01,800
All right.

136
00:07:01,800 --> 00:07:04,966
So the first thing to notice
is that for loop inside a single

137
00:07:04,966 --> 00:07:08,800
row indeed we take the full list
of all the rules here.

138
00:07:08,800 --> 00:07:11,400
You know that's the full list of results.

139
00:07:11,400 --> 00:07:14,966
And then for each of the rule
in this full list of rules,

140
00:07:15,100 --> 00:07:18,866
well we're going to access each of
these elements and take them separately.

141
00:07:19,200 --> 00:07:21,333
And so let's start with left hand side.

142
00:07:21,333 --> 00:07:24,866
How do we take that left hand side
which is you know right here

143
00:07:24,966 --> 00:07:28,300
the item space frozen set light cream
basically light cream.

144
00:07:28,533 --> 00:07:29,833
Well let's see.

145
00:07:29,833 --> 00:07:32,233
So first we take the single rule.

146
00:07:32,233 --> 00:07:34,700
You know let's say for example
this one to explain

147
00:07:34,700 --> 00:07:36,300
how we're going to get these elements.

148
00:07:36,300 --> 00:07:37,600
So we take these rules.

149
00:07:37,600 --> 00:07:40,733
And then in this rule
we first access the index to.

150
00:07:41,000 --> 00:07:43,200
All right.
So let's access it step by step.

151
00:07:43,200 --> 00:07:46,733
This element here you know up to the comma

152
00:07:46,733 --> 00:07:50,133
is the element of index zero okay.

153
00:07:50,500 --> 00:07:54,566
Then this element
is the element of index one.

154
00:07:54,566 --> 00:07:55,966
This is the second element.

155
00:07:55,966 --> 00:08:00,666
And then this full element
you know up to the closing

156
00:08:00,666 --> 00:08:04,966
square brackets
here is actually the element of index two.

157
00:08:05,100 --> 00:08:05,400
All right.

158
00:08:05,400 --> 00:08:08,400
So all I've highlighted here
is the element of index two.

159
00:08:08,433 --> 00:08:11,900
So now in that element of index two
then we're going to access

160
00:08:11,900 --> 00:08:14,900
the element of index zero
meaning the first element.

161
00:08:15,000 --> 00:08:16,033
And the first element

162
00:08:16,033 --> 00:08:19,533
is actually the first element
of that list, you know in square brackets.

163
00:08:19,800 --> 00:08:24,900
And that is of course all this, you know,
ordered statistic up to be careful,

164
00:08:24,900 --> 00:08:29,433
you know, up to the closing parenthesis
here, meaning right here.

165
00:08:29,633 --> 00:08:34,133
So all this is the first element
inside that,

166
00:08:34,200 --> 00:08:37,400
you know, big element
which I've just highlighted before,

167
00:08:37,400 --> 00:08:41,100
you know, from ordered statistics
up to actually the end.

168
00:08:41,500 --> 00:08:41,766
All right.

169
00:08:41,766 --> 00:08:44,766
So this is the element of index zero.

170
00:08:44,766 --> 00:08:47,333
And then in this new element of index zero

171
00:08:47,333 --> 00:08:50,866
we're going to access the first element
you know of index zero again.

172
00:08:51,166 --> 00:08:54,966
And well you know we have to look inside
this parenthesis and that

173
00:08:54,966 --> 00:09:00,033
of course this element
which is indeed the left hand side right.

174
00:09:00,033 --> 00:09:02,366
Because this is what we want to get.

175
00:09:02,366 --> 00:09:05,100
Left hand side item space.
That's the same.

176
00:09:05,100 --> 00:09:06,900
And that is light cream.

177
00:09:06,900 --> 00:09:09,000
And then for the right hand side
that's the same.

178
00:09:09,000 --> 00:09:11,500
You know we took the same
first element of the next two.

179
00:09:11,500 --> 00:09:14,666
Then that whole element of index

180
00:09:14,833 --> 00:09:17,833
zero inside this
first element of the next two.

181
00:09:17,833 --> 00:09:21,266
And then instead of taking the index zero
here we take the index one,

182
00:09:21,433 --> 00:09:26,966
which is that element items add frozen
set chicken.

183
00:09:27,300 --> 00:09:28,133
All right.

184
00:09:28,133 --> 00:09:31,433
So that element is you know
that element of index two then index zero

185
00:09:31,500 --> 00:09:32,333
then next one.

186
00:09:32,333 --> 00:09:36,333
And then that index is to indeed catch
what's inside, you know chicken.

187
00:09:36,566 --> 00:09:40,700
And same for that index zero here
there was two catch light cream.

188
00:09:41,166 --> 00:09:41,433
All right.

189
00:09:41,433 --> 00:09:44,633
So you see we just play with the indexes
to access what we want.

190
00:09:44,633 --> 00:09:47,300
But really you will only have to do that
once in your life.

191
00:09:47,300 --> 00:09:51,100
So don't worry too much about this kind
of overwhelming code, even if it's quite

192
00:09:51,100 --> 00:09:54,900
funny to, you know, follow the indexes
path to find the products.

193
00:09:55,266 --> 00:09:58,633
But then the good news is that for the
support, it's going to be much simpler.

194
00:09:58,900 --> 00:10:01,333
Indeed,
we just need to take the full rule.

195
00:10:01,333 --> 00:10:02,300
You know, the single rule.

196
00:10:02,300 --> 00:10:05,100
So you know, this whole rule.

197
00:10:05,100 --> 00:10:09,233
And then very simply we access
the element of index one directly.

198
00:10:09,433 --> 00:10:12,466
So remember and this full single rule.

199
00:10:12,666 --> 00:10:16,066
Well all this is
the element of index zero.

200
00:10:16,333 --> 00:10:19,333
And then all
this is elements of index one.

201
00:10:19,333 --> 00:10:22,300
And that's exactly the support
which is what we want.

202
00:10:22,300 --> 00:10:26,900
And we do this for each of the rules
in this whole list of rules okay

203
00:10:27,433 --> 00:10:28,666
then confidences.

204
00:10:28,666 --> 00:10:30,866
Once again it's a bit more complicated.

205
00:10:30,866 --> 00:10:34,566
But just like before
first we get the element of index two.

206
00:10:34,566 --> 00:10:36,266
So let's take it again.

207
00:10:36,266 --> 00:10:38,766
This is the element of index zero.

208
00:10:38,766 --> 00:10:40,833
Then this is the element of the next one.

209
00:10:40,833 --> 00:10:46,700
And then all
this is the element of index two okay.

210
00:10:46,933 --> 00:10:50,500
Then inside this whole element
of index two well we're going to access

211
00:10:50,500 --> 00:10:54,600
the element of index zero 
which is let's take it again.

212
00:10:54,600 --> 00:10:57,566
So we start from here
you know ordered statistic.

213
00:10:57,566 --> 00:11:00,866
And then we go up to actually the closing

214
00:11:00,866 --> 00:11:04,100
parenthesis of here
which should be right here.

215
00:11:04,466 --> 00:11:06,666
Right. Let's check the parenthesis here.

216
00:11:06,666 --> 00:11:10,300
So that's the first opening one
then the second opening one.

217
00:11:10,300 --> 00:11:11,400
Closing here.

218
00:11:11,400 --> 00:11:13,900
Then this is a new opening one,
the closing here.

219
00:11:13,900 --> 00:11:15,866
And then there you go okay.

220
00:11:15,866 --> 00:11:20,966
So that's the closing parenthesis
of indeed this element of index two.

221
00:11:20,966 --> 00:11:23,500
Then index zero.
And then inside this element.

222
00:11:23,500 --> 00:11:27,000
Now we're going to get access
to the element of index two.

223
00:11:27,233 --> 00:11:31,200
So that's the element of index zero.

224
00:11:31,400 --> 00:11:34,400
Then that's the element of index one.

225
00:11:34,400 --> 00:11:37,400
And then finally
that's the element of index two.

226
00:11:37,500 --> 00:11:40,700
And that's exactly the confidence
which is what we want to get right now.

227
00:11:41,033 --> 00:11:42,166
And then same for the lift.

228
00:11:42,166 --> 00:11:43,833
So same same path.

229
00:11:43,833 --> 00:11:46,766
First
we get access to the index two then zero.

230
00:11:46,766 --> 00:11:48,566
So just like we were right now.

231
00:11:48,566 --> 00:11:51,733
But then instead of taking the index two
like for the confidence

232
00:11:51,900 --> 00:11:54,833
we take the next one
which is the index three

233
00:11:54,833 --> 00:11:57,400
and which corresponds to
of course, the lift.

234
00:11:57,400 --> 00:11:59,433
All right. And that's how we get the lift.

235
00:11:59,433 --> 00:12:02,233
So you see the idea just again
with the indexes,

236
00:12:02,233 --> 00:12:07,000
we access the elements inside
this whole complicated list of rules.

237
00:12:07,133 --> 00:12:10,000
But at least
we will get a nice result in the end.

238
00:12:10,000 --> 00:12:13,066
And really you don't have to worry
too much about this code.

239
00:12:13,066 --> 00:12:16,666
It is very unique, very specific,
and you will probably not have to

240
00:12:16,833 --> 00:12:18,600
re-implement it again in your life.

241
00:12:18,600 --> 00:12:20,566
You can just take it,
you know, I just took it

242
00:12:20,566 --> 00:12:24,700
online and indeed it is very practical
for what we're doing right now.

243
00:12:24,700 --> 00:12:27,066
Meaning association rule learning.

244
00:12:27,066 --> 00:12:27,500
Okay.

245
00:12:27,500 --> 00:12:28,333
So good.

246
00:12:28,333 --> 00:12:31,266
Now let's have a look
at the beautiful result.

247
00:12:31,266 --> 00:12:34,700
So we are going to play the self first to,

248
00:12:34,733 --> 00:12:39,100
you know build that inspect function
and then create that new data frame

249
00:12:39,100 --> 00:12:43,733
which I called results in data frame
and which will contain the same rules

250
00:12:43,733 --> 00:12:47,600
here, but better organized
and more beautifully organized, let's say.

251
00:12:47,933 --> 00:12:50,933
And so now
we're going to create a new code cell here

252
00:12:50,966 --> 00:12:55,866
just before this text cell to first
display the results non sorted.

253
00:12:56,300 --> 00:13:00,933
And to do this well we simply need to call
what we created here meaning results

254
00:13:02,000 --> 00:13:03,533
in data frame.

255
00:13:03,533 --> 00:13:04,366
All right.

256
00:13:04,366 --> 00:13:07,466
And then when pressing play
you will see that

257
00:13:07,666 --> 00:13:11,233
we will get a very nice table
containing all the rules

258
00:13:11,233 --> 00:13:13,433
with the different elements
and separate columns.

259
00:13:13,433 --> 00:13:16,833
So that's the left hand side of the rule,
the right hand side of the rule.

260
00:13:17,033 --> 00:13:18,266
And then the support of the rule,

261
00:13:18,266 --> 00:13:20,700
the confidence of the rule
and the lift of the rule.

262
00:13:20,700 --> 00:13:23,466
So let's have a look at the rules
one by one for the first one.

263
00:13:23,466 --> 00:13:26,700
As we saw earlier,
if customers buy light cream,

264
00:13:26,866 --> 00:13:31,166
then they will have actually 29%
chance of buying chicken.

265
00:13:31,500 --> 00:13:31,933
All right.

266
00:13:31,933 --> 00:13:33,466
And this rule appears

267
00:13:33,466 --> 00:13:37,533
0.4 percent of the time, you know,
and 0.4 percent of the transactions.

268
00:13:37,533 --> 00:13:41,333
And it has left a 4.84,
which is indeed very good.

269
00:13:41,833 --> 00:13:44,833
Then the second rule,
if people buy mushroom cream sauce,

270
00:13:45,000 --> 00:13:47,033
then they have a good chance
of buying scallop

271
00:13:47,033 --> 00:13:52,066
and that good chance is 30%
and it has a lift of 3.79.

272
00:13:52,066 --> 00:13:53,366
Pretty good still.

273
00:13:53,366 --> 00:13:57,700
Then if people buy pasta, then they will
have a good chance of buying a scallop.

274
00:13:57,933 --> 00:14:00,200
And that good chance
is actually pretty good indeed.

275
00:14:00,200 --> 00:14:03,066
If customers buy pasta,
then they will have 30%

276
00:14:03,066 --> 00:14:06,100
chance of buying a scallop
and the lift is 4.7.

277
00:14:06,333 --> 00:14:07,100
Then check this out.

278
00:14:07,100 --> 00:14:09,633
We have a good lived here for from us
the honey.

279
00:14:09,633 --> 00:14:13,300
Yes of course from us non
honey is a delicious French dessert.

280
00:14:13,300 --> 00:14:15,033
I actually really enjoyed that.

281
00:14:15,033 --> 00:14:17,200
Dessert is one of my favorites.

282
00:14:17,200 --> 00:14:20,400
And indeed
when you buy from us as a French person,

283
00:14:20,400 --> 00:14:23,400
you will definitely enjoy
putting some honey on it.

284
00:14:23,400 --> 00:14:25,466
All right, so indeed, that's a great rule.

285
00:14:25,466 --> 00:14:29,000
And I would definitely make this deal,
you know, buy from us below

286
00:14:29,066 --> 00:14:30,833
and get honey for free, right?

287
00:14:30,833 --> 00:14:33,633
Because indeed the lift is 5.6.

288
00:14:33,633 --> 00:14:35,333
So very very good then.

289
00:14:35,333 --> 00:14:36,900
Herb and pepper, ground beef.

290
00:14:36,900 --> 00:14:40,100
Yes of course French people or even,
you know, other people

291
00:14:40,100 --> 00:14:43,633
from other nationalities love to put herb
and pepper on ground beef.

292
00:14:43,633 --> 00:14:45,633
This is actually exquisite.

293
00:14:45,633 --> 00:14:48,966
And indeed we have a good confidence
for that rule and actually, well,

294
00:14:49,000 --> 00:14:50,366
not that high of olives.

295
00:14:50,366 --> 00:14:51,600
Okay then.

296
00:14:51,600 --> 00:14:52,800
Same for tomato sauce.

297
00:14:52,800 --> 00:14:55,800
It's nice to put tomato sauce on ground
beef.

298
00:14:55,966 --> 00:15:00,000
The lift is still close to
for light cream, olive oil.

299
00:15:00,000 --> 00:15:03,000
Well I don't really see the association,
but why not?

300
00:15:03,000 --> 00:15:05,566
I'm not really a good cook,
but maybe there is a recipe

301
00:15:05,566 --> 00:15:08,700
where we can combine olive oil
and like cream.

302
00:15:09,000 --> 00:15:10,066
I'm not so sure about that.

303
00:15:10,066 --> 00:15:12,333
But however, this one is

304
00:15:12,333 --> 00:15:15,900
definitely something I would do
whenever I buy whole wheat pasta.

305
00:15:15,900 --> 00:15:19,200
I also get olive oil and indeed
the lift is pretty high.

306
00:15:19,433 --> 00:15:20,933
And then pasta and shrimps.

307
00:15:20,933 --> 00:15:25,300
Yes, that's a very good specialty of south
of France, especially near the coast.

308
00:15:25,466 --> 00:15:29,166
French people, of course,
love mixing bass and shrimps all right.

309
00:15:29,166 --> 00:15:31,633
And the lift is 4.5 so very good.

310
00:15:31,633 --> 00:15:34,733
So you see,
these are much better to observe.

311
00:15:35,000 --> 00:15:39,200
But then we still don't have them salted
which here is fine because you know

312
00:15:39,233 --> 00:15:40,433
we don't have that many rules.

313
00:15:40,433 --> 00:15:44,033
But in other situations
you can end up with many more rules

314
00:15:44,033 --> 00:15:46,200
and therefore you would like to sort them,

315
00:15:46,200 --> 00:15:49,933
for example by descending lift, because
the lift is a very relevant measure.

316
00:15:50,266 --> 00:15:52,566
So I'm going to show you right now
how to do this.

317
00:15:52,566 --> 00:15:55,166
It's very, very simple thanks to blenders.

318
00:15:55,166 --> 00:15:56,766
So let's create a new cocktail.

319
00:15:56,766 --> 00:15:58,900
And here we're going to take again.

320
00:15:58,900 --> 00:16:02,733
Well our new beautiful data
frame results in data frame.

321
00:16:03,033 --> 00:16:06,600
And now we're going to use
a pre-built function by the library

322
00:16:06,600 --> 00:16:09,900
to indeed sort
the results of this data frame

323
00:16:09,900 --> 00:16:13,733
by a specific column, which we are
of course going to specify here.

324
00:16:13,866 --> 00:16:14,166
All right.

325
00:16:14,166 --> 00:16:15,100
So let's do this.

326
00:16:15,100 --> 00:16:16,866
To do this we need to add a dot here

327
00:16:16,866 --> 00:16:20,800
because we're going to call a specific
method of the data frame class.

328
00:16:20,800 --> 00:16:22,900
You know because this results in data

329
00:16:22,900 --> 00:16:26,800
frame is actually an object of the data
frame class by pandas.

330
00:16:27,033 --> 00:16:30,133
And that method is called and largest.

331
00:16:30,800 --> 00:16:32,400
There we go this one.

332
00:16:32,400 --> 00:16:35,633
And inside
we just have to enter three arguments.

333
00:16:35,766 --> 00:16:36,633
As we can see here.

334
00:16:36,633 --> 00:16:39,500
You know you have all the info
thanks to Google Collab.

335
00:16:39,500 --> 00:16:43,866
So the three parameters are first n which
is the number of rows we want to return.

336
00:16:44,000 --> 00:16:47,400
So I'll just put that as you know,
if I was doing a code template

337
00:16:47,400 --> 00:16:52,600
I'll just put n equals ten to you know
in general return the ten best rules.

338
00:16:52,600 --> 00:16:56,400
So n equals ten then keep
we will keep the default values.

339
00:16:56,400 --> 00:16:58,000
You know that's in case
we have duplicates.

340
00:16:58,000 --> 00:17:02,266
But that's fine for us
I actually check them and then columns.

341
00:17:02,266 --> 00:17:02,533
All right.

342
00:17:02,533 --> 00:17:05,366
So that's the other parameter
I want to input here.

343
00:17:05,366 --> 00:17:06,300
And that's of course

344
00:17:06,300 --> 00:17:10,000
you know to specify by which column
you want to have your results sorted.

345
00:17:10,333 --> 00:17:10,600
All right.

346
00:17:10,600 --> 00:17:13,600
So columns equals and

347
00:17:13,600 --> 00:17:17,000
well you know the most relevant metric
is perhaps to lift.

348
00:17:17,000 --> 00:17:19,566
So we're going to sort these rules
by the lift.

349
00:17:19,566 --> 00:17:22,500
And to do this
well we simply need to specify

350
00:17:22,500 --> 00:17:26,500
the lift value in quotes
for that columns parameter.

351
00:17:26,633 --> 00:17:29,633
So in quotes I'm going to enter here lift.

352
00:17:30,100 --> 00:17:30,800
All right.

353
00:17:30,800 --> 00:17:31,566
And that's it.

354
00:17:31,566 --> 00:17:36,033
This is simply what you have to do
in order to sort your rules by the column.

355
00:17:36,033 --> 00:17:36,466
You want.

356
00:17:36,466 --> 00:17:36,966
Here.

357
00:17:36,966 --> 00:17:39,966
Lift if you want to order them
by confidence which is also great.

358
00:17:40,233 --> 00:17:43,166
You would just specify here in quotes
confidence.

359
00:17:43,166 --> 00:17:44,100
All right. So let's try.

360
00:17:44,100 --> 00:17:47,966
Let's play the cell and there we go.

361
00:17:47,966 --> 00:17:52,000
Now we have indeed
the rules sorted by the lift.

362
00:17:52,000 --> 00:17:55,100
This is the highest lift 5.16 down

363
00:17:55,100 --> 00:17:58,100
to the lowest lift 3.11.

364
00:17:58,633 --> 00:17:59,300
And so let's see.

365
00:17:59,300 --> 00:18:00,500
Well as I told you,

366
00:18:00,500 --> 00:18:04,066
you know that's a very popular association
especially for French people.

367
00:18:04,066 --> 00:18:06,633
They love to put honey in from each below.

368
00:18:06,633 --> 00:18:10,333
Each time you go to a French restaurant,
you will see in the dessert menu, well,

369
00:18:10,333 --> 00:18:11,333
from us with honey.

370
00:18:11,333 --> 00:18:14,200
And even if you don't see it,
you can always ask the restaurants.

371
00:18:14,200 --> 00:18:15,966
They always have honey, not too far.

372
00:18:15,966 --> 00:18:19,033
So that's definitely
a very strong rule here.

373
00:18:19,200 --> 00:18:23,500
And you know, if I was the owner of the
shop, I would definitely make that too.

374
00:18:23,500 --> 00:18:26,900
You buy from us and get honey for free
then same.

375
00:18:26,900 --> 00:18:29,900
This is the second strongest rule
light cream chicken.

376
00:18:30,066 --> 00:18:31,733
So another great deal would be

377
00:18:31,733 --> 00:18:34,466
if you buy light cream,
you will get chicken for free.

378
00:18:34,466 --> 00:18:36,200
And that's actually a very good deal.

379
00:18:36,200 --> 00:18:41,000
But you know, as I told you, the owner
can put some smart prices that you know

380
00:18:41,000 --> 00:18:44,000
would amount to a good price for,
you know, buying the two.

381
00:18:44,100 --> 00:18:44,400
Right.

382
00:18:44,400 --> 00:18:45,533
But that's another story here.

383
00:18:45,533 --> 00:18:48,766
We're doing association rule
not pricing strategy.

384
00:18:49,066 --> 00:18:51,066
So there we go.
Let's move on to the next rule.

385
00:18:51,066 --> 00:18:55,800
If people buy pasta then they will
enjoy buying scallop as well.

386
00:18:55,800 --> 00:18:59,833
So a third great deal would be buy pasta
and get scallop for free.

387
00:19:00,266 --> 00:19:02,233
And then same with pasta and shrimp.

388
00:19:02,233 --> 00:19:05,533
Of course if you bypass
so you can get shrimps for free,

389
00:19:05,900 --> 00:19:09,400
then if you buy whole wheat pasta
you can get olive oil for free.

390
00:19:09,400 --> 00:19:12,866
You know these deals
will be very attractive to the customers

391
00:19:12,866 --> 00:19:17,000
because indeed customers
buy these association of products.

392
00:19:17,000 --> 00:19:18,266
Okay. All right.

393
00:19:18,266 --> 00:19:19,066
So there you go.

394
00:19:19,066 --> 00:19:22,200
These rules, you know
for most of them actually make sense.

395
00:19:22,200 --> 00:19:24,600
And there you go
my friends. Congratulations.

396
00:19:24,600 --> 00:19:29,433
You built your first association rule
learning model to identify clear rules

397
00:19:29,433 --> 00:19:33,400
that will create some added value
to a retail business.

398
00:19:33,400 --> 00:19:37,666
So your job is done and now you can enjoy
the beautiful days of South of France

399
00:19:37,833 --> 00:19:41,300
after completing successfully
this new data science mission.
