Okay my friends.
So we just covered the data preprocessing part and we covered it
in a flash light thanks to our data preprocessing template.
And now we're about to really build and train
the simple linear regression model on the training set of course.
Right.
So remember that we splitted that data set into the training set and the test set.
The training set will be used to train R simple linear regression model.
And the test set will be used to evaluate it.
So now we have to start with the training.
And so there we go.
Let's create a new code cell.
And let's implement the very simple linear regression model.
All right.
So the first thing we'll have to do is to import the right class
with which we're going to build this simple linear regression model.
Because indeed we could either implement it from scratch or we could use libraries.
And of course we're going to use libraries because I want to provide
a very clear coat template which allows you to build
any simple linear regression models in a flashlight.
And this library that we're going to use is scikit learn,
from which we're going to get access to a certain module called linear model.
And from this module we're going to call a certain class called linear regression.
And our simple linear regression model
which we're going to build will be exactly an instance of this class.
Right. It will be an object of this class.
All right. So let's do this.
Let's start by importing from, you know, from the scikit
learn library which has the code name sklearn.
So from sklearn then as we said we're going to get access to a certain module.
So we have to add a dot here and which is linear model.
And from this linear module of the scikit
learn library well we're going to import the linear
regress session class exactly this one linear regression.
And then as we said this simple linear regression model which we're going to
build will be an instance or an object of this linear regression class.
And therefore here we have to create a new variable
which will be exactly this instance of the linear regression class.
And we're going to call this object.
We can call it by any name but we're going to call it regressor
because indeed we are doing right now regression.
Right.
I remind a big difference between regression and classification.
Regression is when you have to predict
a continuous real value, like a salary, as we're about to do.
And classification is when you have to predict a category or, you know, a class,
which we will do in part three classification or all right.
So regressor that's a new variable which at the same time
will become the object of the linear regression class.
And you can exactly see this object as the linear regression model itself.
You know, I remind that a class allows you to implement
a couple of instructions to build something.
And well, this linear
regression class built exactly this simple linear regression model.
All right.
So you have to see this regressor object as exactly this model.
Right. So regressor.
And then to create an object of a class.
Well there's nothing more simple.
You just have to call the class itself linear regression.
And then add some parentheses and that's it.
Usually there are some parameters inside that we can implement.
But here you don't have to enter anything.
This will just create a simple linear regression model.
And it is so simple that usually
we don't have to play too much with the parameters.
All right.
And that line of code directly creates the simple linear regression model.
And that's only the building part.
You know we actually get a model.
But now of course we have to train it on the training set.
And therefore we have to connect it in some way to the training set
and the action or, you know, the function that connects it
in order to train it is called the fit function.