Hello and welcome to this art tutorial.
So in the following tutorials
we're going to implement a simple linear regression model on R.
So it's going to be the same steps as in Python.
And let's start with the first step.
So the first step is to actually set the working directory.
As you can see right now I'm on my desktop.
So I'm going to go to my machine learning A-Z folder path to regression
and then section for simple linear regression.
And here we are.
That's the folder we want to set as working directory.
Make sure that it contains your salary data dot csv file.
That's the data on which we will build our simple linear regression model.
So make sure it is here and now.
To set this folder as working directory,
you just need to click on this more button here.
And then click on Set as Working Directory.
And that's it. That's done.
Now we're ready to start.
We are ready to start with the real first step of making a machine learning model,
which is the data pre-processing step.
So we're going to use of course
the data pre-processing template that we made in part one.
So I'm just going to copy the template here only this
copy and then paste it
here.
All right.
And now we just need to change a few things to adapt it to our data set.
So of course we will need to change the name of the data set here.
It is not data dot CSV but salary underscore data okay.
So then I'm going to select this to have a look at the data set.
Here we go. Let's have a look.
Here's the data set okay.
So just to remind what this data set is about this data
set contains some information of employees in a company.
And these two informations are the number of years of experience
the employee has and the salary.
So we are trying to understand if there is a correlation
between the salary and the number of years of experience.
And mostly we're trying to see if it's a linear correlation.
That means if it's a,
that means if there is a linear dependency between these two variables.
And so what we need to understand that the first reflex that we must have
when we make a model is that we must understand
which is the independent variable and which is the dependent variable.
So the independent variable
is the number of years of experience, and the dependent variable is the salary.
And so what happens is that we are trying to predict
the dependent variable salary based on the information
of the independent variable years of experience okay.
So that's the data set.
And now let's continue with our model.
So let's go back to a simple linear regression here.
And we don't need to specify any column of interest.
We have all we need.
So we won't use this line here okay.
Now we are ready to split the data set into the training set and the test set.
So we perhaps need to change the split ratio.
Let's see.
the data set contains 30 observations.
So what what would be a good split ratio.
It's really as you prefer.
I know that I told you that a good split ratio is 75%.
But just for the sake of beauty, let's take 20 observations
in a training set and ten observations in a test set so that would be that
the split ratio would be two third.
Okay.
And of course, let's not forget to change the name of the dependent variable
because this was the name of the data in the template.
And now let's see what the name is.
The name is salary.
So here you know that's the name of the dependent variable.
So we need to change purchased into salary.
And now I think it's ready.
We are ready to split the data set into the training set and the data set.
So let's do it and let's see what happens.
Here we go.
It's worked perfectly.
So now let's have a look at the training set and the test set
okay.
The training set contains the 20 observations generated from the splits.
And in the test set we have our ten observations.
So we are going to train our simple linear regression model on the training set.
That means that our model is going to learn the correlations
between the number of years of experience
and the salary in this set here in the training set.
And then later we will test its performance,
its power of prediction on the test set.
So let's continue.
the last step of the data pre-processing is feature scaling.
But the simple linear regression package that we are going to use here
in R takes care of this.
So we won't need to apply feature scaling manually.
So we will be fine with that.
And actually the data pre-processing phase is ready.
So awesome.
We are ready to start building the linear regression model.
We are going to do that in the next tutorial.
So I can't wait to see you there.
And until then, enjoy machine learning.