All right.
So remember that the cluster numbers don't go from 1 to 5,
but from 0 to 4 because indexes in Python start from zero.
So let's see let's open this again.
What these numbers mean is that well the first customer, customer I.D.
number one belongs to the last cluster.
You know, cluster number five.
Then the second customer belongs to cluster number four.
Third customer belongs to cluster number five or cluster the next four as you want.
Then customer number four belongs to cluster number four.
All right. So this is how you should read it.
And the last customer in this data set you know
the customer actually number 200.
This one of age 30 and earning a high salary and spending a lot actually
in them all belongs to the third cluster or cluster of index.
All right. So that's how you should read it.
And now now let's visualize the final clusters.
You know, now that we have this dependent variable that we just created
through the hierarchical clustering process.
And so there you go I'm going to close this.
We're going to run that cell to indeed find
actually you know the same clusters as with K-means with remember
this cluster representing the customers that earn a low salary and don't
spend much in the middle, and therefore we should just not target them too much
because we want to be socially responsible and don't push them to consume too much.
Right?
However, this cluster is the cluster of the customers
having a high annual income but a low spending score.
And therefore we want to target these customers to offer them
some more attractive deals in order to incentivize them
to spend more in the mall, because otherwise the mall is missing out.
Then this cluster is the cluster of customers
having a low annual income but a high spending score.
And therefore with these customers, you know you want to be
the maximum socially responsible and maybe protect them
from spending too much and potentially more than they could afford.
So to these customers, we, for example, want to reduce any kind of advertising.
Then we have this cluster, which is the best cluster, you know,
the one who want to target the most because it is the cluster of the customers
having a high annual income and at the same time spending a lot.
So we definitely want to target these customers to, you know,
offer them the new products and new deals, because we know that
we have a high chance to have a high conversion rates with them.
All right.
And then we have this cluster which is the average cluster,
you know, average annual income and average spending score.
And for this cluster, well, we don't have much specific to do.
All right.
So these are the same five clusters as with K-means.
But now I'm very curious to see what we get with three clusters.
And therefore what we're going to do is try no.
And cluster is equal three here.
But then be careful.
We need to actually remove two lines here.
When, you know, visualizing the clusters.
Because each scatterplot here corresponds to one cluster.
And therefore.
Now since we're about to
have three clusters well we need to remove two clusters here.
So we're going to remove cluster four and cluster five.
All right.
And therefore we're just going to end up with you know cluster
one cluster two and cluster three of colors red blue and green.
All right.
So let's just run this again.
You know we can leave the previous cells and just rerun this one to indeed
get a new hierarchical clustering model, this time identifying three clusters.
We can print this again in order to get the new dependent variable with this time.
Indeed three clusters the cluster of index zero,
which seems to contain most of the first customers,
then the cluster of index one, the second cluster and the cluster
index to the third cluster. Okay.
And now I'm really curious to see what we get when visualizing the cluster.
So here we go.
We just have to play this cell again and let's see what we get okay.
So yeah really
five clusters was actually a better number because here with three clusters.
Well the model just puts all these customers, you know
actually the low income customers with both a low spending score,
a high spending score into a same cluster, also taking the average one.
And then we have these two other clusters, the high spinning score
with the high annual income and the low spending score with the high annual income
and you know, this still actually makes some sense, because remember that
the clusters of customers that we really want to target after all,
this one and this one
and this, you know, is something we don't really want to target
but maybe protect, you know, you know, as per your social responsibility.
So this actually still makes kind of sense.
And we indeed end up
with the same focus of targeting these two important customers.
That can boost indeed the sales.
All right. So that was very interesting.
I, I didn't expect actually to show you the result with three clusters.
I was just curious to see and that's very interesting because indeed we end up
with kind of the same final marketing decisions of targeting our customers.
All right. So I hope you enjoyed clustering.
Now we're going to move on
to the next part, part five on association rule learning.
It's going to be pretty exciting.
We're going to work on two new models Priory and Eclat.
And so I will either meet you in this next part
or if you want to learn as well, I will meet you in the next section
to build the Hierarchical Clustering model in R.
And either way, I look forward to building another model with you
and until then, enjoy machine learning.