Hello my friends,
and welcome to the practical activity of this new part.
Part four clustering, where we're going to build two
clustering models K-means and Hierarchical Clustering.
And of course we're going to start with.
K-means which is actually the most popular model in clustering.
And indeed we will see together that it provides fantastic results.
So you just saw the intuition lectures with Kirill.
And now we're going to put that theory into practice
by building this K-means clustering model in both Python and R.
And now we should all be on the same page.
And therefore we're going to go to this folder here part for clustering.
And then we will attack K-means clustering.
And we're going to start with Python of course.
And this is your folder containing two files.
First to K-means clustering implementation in the Ipy and the format
which therefore you can open with either Google Collaboratory or Jupyter Notebook.
And then you have mode customers dot CSV, which is the CSB file.
You know, the data set with which we will work in this section
to build our K-means clustering model.
All right.
So first step as usual I will explain what this dataset is about,
which will allow me to explain the purpose of this mission.
You know the why we want to build the K-means algorithm and what for.
And then we'll start of course, our implementation from scratch,
step by step, and you'll take action with me to build the K-means algorithm.
All right.
So what is this dataset about?
Well, as you can see by the title of this data set mode customers.
Well, it's actually a data set made by among, you know, the strategic
team, let's say, of a model that collected some data about their customers.
So here it's important to see it this way.
Each row corresponds to a customer of the model.
And for each of these customers of the model.
Well, the data analyst of this team gathered the following information.
First the customer ID, then the joint male female, then the age, the annual income.
And let's expand this.
Well I can't do it here, but that last variable is the spinning score.
And it can take values between 1 and 100.
So all these features are pretty clear.
Let me explain what this one means.
The spending score is a metric made by the model
to measure you know how much each customer spends.
And so they made this metric which takes values from 1 to 100.
You know, that's the scale of the metric such that well, the lower the score,
the less the customer spends and the higher the score, the more
the customer spends.
You know, in a certain period of time, let's say in the past year.
Okay.
So for example, this customer actually spends
a lot in this model, you know, because he has a score of 81.
However, this customer spends very few
in the model because she has a score of six.
All right.
So that's just a metric measuring the spending of each customer.
And so now what is the purpose of this mission.
What did this strategic team or analytics team want to do?
Well, as you might guess, since right now we're doing clustering,
this team wants to very simply understand its customers.
You know, they want to identify some patterns
within its customers, within its base of customers.
And that's the key thing to understand here.
You know, when doing clustering this time as opposed to, you know, previously
with regression and classification, where we were actually knowing what to predict.
Well, this time we actually have no idea what to predict.
But even though we don't know what specifically to predict,
we still know that we want to identify some patterns.
And that's the why of this mission.
You know, the purpose of this mission.
Okay.
So it's good we understand the why.
And now let's understand how how are we going to identify
such patterns?
Well, we will do this with K-means of course.
And more specifically, what we will do is
we will create a dependent variable, right?
We will create a dependent variable which will take a finite number of values.
You know, let's say 4 or 5 values.
And actually each of the values will be a class
of this dependent variable we're going to create.
And that's exactly what clustering means.
You know technically in the details if you want to be broad on how to explain
clustering, you would say that we are identifying some patterns in the data.
But if you want to clearly explain how to identify these patterns in the data,
well you would say that we are building a dependent variable.
You know, we are creating it
in such a way that each of the values of this future dependent variable,
we are creating are actually the classes of this dependent variable.
All right.
So this will become much more clear once you know we build our K-means
algorithm and we get that dependent variable we are creating.
But please remember this we are creating a dependent variable.