Hello my friends.
Welcome back.
Now let's learn together how to import a data set.
As a reminder, we're going to learn how to import the following data.
Set data dot CSV, which is a very simple data set of,
let's say a retail company that is doing some analysis
on which clients purchased one of their products.
So the rows in this data set correspond to different customers of this employee.
And for each of these customers, we have the country they live in their
age, their salary, and whether or not they purchased the product.
Okay.
So we're going to learn how to import that CSV
on Python using, of course, the pandas library.
Here we go.
So let's first create a new code cell.
And now let's import this data set.
So the first thing we have to do is to create a new variable.
And this variable will contain exactly the data set.
So I always like to choose simple names
for my variables representing well what we're creating.
And therefore since now we're importing the data set
and we want to integrate the data set in a variable.
I'm going to call this variable data set.
Okay. As simple as that.
So this variable what will it be equal to.
Well it will be equal to the output of a certain function by pandas.
And this certain function will exactly read
all the values of this data set
and will create what we call a data frame.
It's a certain format of data, whether it is in Python or even R.
So it will create a data frame and it will contain
exactly the same rows and columns and values as what you see here.
And this data frame will be exactly this data set variable.
All right.
So there we go.
In order to create this data frame we're going to call a certain function
by the pandas library which is called read underscore CSV.
And in this function we will only have to
input the name of the data set with the extension.
So since we're about to call a function of this, well,
the first thing we have to do is call dependance library.
And therefore remember since we gave it the shortcut named PG,
in order to call it, we need to add here PG.
And then to call a function from a library we need to add a dot.
It's always done like that.
And that's where you can call the function you want to use.
And as we said this function is named read underscore CSV.
And then you add some parenthesis to enter the argument.
So there we go. Let's do this.
This will only what you will have to do
when using this read underscore CSV function.
You have to input in quotes the name of the data set.
As a reminder, the name of the data set is data with a capital D dot csv.
So there we go.
Data dot csv okay, and this will create the data frame.
You know all the values inside this data set.
And this data frame will be exactly this data set variable okay.
So that's the first step.
But that's not enough to import data set.
You know as a first step of data preprocessing,
the next thing that you have to do is create two new entities.
The first one is the matrix of features.
And the second one is the dependent variable vector.
So let me show you exactly what they mean and what they are
in the data set right here okay.
So I'm going to give you now a very first important principle in machine learning.
In any data set with which you're going
to train a machine learning model, you have the same entities
which are the features and the dependent variable vector.
Can you guess here?
What are the features and what is the dependent variable?
Well, very simply the features are the columns
with which you're going to predict the dependent variable.
And the dependent variable of course is the last column.
Because, you know, this company would like to predict
if some future customers are going to purchase
a certain product based on these informations.
So very simply, the features or also called the independent variables,
are the variables containing some informations with which you can
predict what you want to predict, which is called the dependent variable.
All right.
So remember this very important principle in any machine
learning model that you're going to build you're going to have separately
the features usually in the first columns of your data set.
And the dependent variable, usually in the last column of your data set,
you will see that all the data sets we will use in this course
and most of the data sets you'll use in your machine learning career
will have the same format with first the features you know in the first columns
and the dependent variable vector in the last column.
Okay.
And so right now what we want to create, you know, the two entities,
we want to create our first
the matrix of features containing separately these three columns here,
you know, country age salary
and separately we want to create the dependent variable vector
containing only this last column because that's the column we want to predict.
And that's exactly what we always have to do in this first data
preprocessing phase.
So let's do this.
Let's create these two entities.
And we are going to call them x for the matrix of features
and y for the dependent variable vector.