All right.
So let's do this starting with X.
So how are we going to create x.
Basically that simple.
We have our data sets you know containing exactly all this
all these columns.
And in order to create X well we simply have to take the three
first columns of this data set.
Because, you know, X will be exactly all these values here.
You know with the three first columns.
And so what we're simply going to do is play with the indexes to collect.
Indeed the indexes of these three first columns, basically of the columns
of all the columns of the data set except the last one.
So let's do this.
Let me show you how to do this.
First, what you're going to do is take your data set that exact
same variable which you created in this first line of code here okay.
Data set.
Then from this data set and I'm adding a dot here because we were about to use
a function, you know, one of the attribute functions of a pandas dataframe.
And that function is I look.
And what will it allow us to do.
Well as you can see I look here stands for locate indexes.
And therefore what this function will do is it will take the indexes
of the columns we want to extract from the data set,
not only the indexes of the columns, but also the indexes of the rows.
And actually we have to start here with the rows.
We can specify the rows that we want to get and put into x.
And of course these are all the rows.
You know we want to get all the rows into x.
We only want to take the first columns which we want to keep all the rows.
And the trick to take all the rows, whatever data set
you have with whatever number of rows is to add here a column.
Why is that?
Because of column in Python means a range.
And when we specify a range without the lower bound and neither
the upper bounds, that means in Python that we're taking everything in the range.
Therefore here all the rows.
So that's the trick to take all the rows.
And you will always have to take all the rows.
So here you won't have anything to change then.
Now we have to specify which columns want to select with the indexes
and to separate the rows that we just took from the columns
we need here to add a comma.
And now we can take care of the columns.
All right.
So now I'm going to show you a trick in order to take all the columns
except the last one.
Because indeed, as I told you, most of the data sets
you will use to train your machinery models will have first
the features you know, in the first columns
and last the dependent variable vector in the last column.
So now we're going to use a trick so that we can take automatically,
you know, regardless of the number of columns
in your data set all the columns except the last one,
because all the columns except the last one are exactly the matrix of features.
And the trick to do that is to add a new range here,
which this time will be column minus one.
So what does it mean?
Well, as we said, the column here means the range.
We know we're taking a range here on the left.
We have nothing.
That means that we're taking the first index.
You know, the index zero because indexes in Python start at zero.
And then you know we're going up to minus one.
So what does this minus one mean.
Well minus one means here the last column minus
one in Python means the index of the last column.
However.
And that's a very important principle in Python which you must absolutely know.
A range in Python includes the lower bound.
Therefore we including here the lower bound zero to index
zero, but exclude the upper bound.
And therefore here we're excluding this index minus one meaning
the index of the last column.
And therefore what this will do is it will take all the columns
excluding the last one.
And that's exactly what we want for our matrix of features x.
So voila. There you go.
Now you just collected the right indexes to create your matrix of features X.
And the beauty of this is that you won't have anything to change
when creating the future matrices of features X
of your future data sets, but make sure that your future data
sets indeed have the features in the first columns
and the dependent variable vector in the last column.
Okay, perfect.
So in order to finish this line of code, we just need to add here dot values.
And this just means that we're taking indeed all the values in all the rows
of this data set, and in all the columns except the last one of this data set.
Perfect. So now you're learning a lot.
Don't worry if this feels a bit overwhelming at the beginning.
I promise you that we will use this trick many, many times,
so you will just soon be so familiar with it and master it like a pro.