Hello and welcome to this art tutorial.
In the previous tutorials we implemented our logistic regression model on Python.
And this time we're going to do it on R.
So the first thing that we need to do is to set a working directory.
Right now I'm on my desktop.
So let's go to the Machine Learning A-Z folder.
Part three classification section logistic regression.
And here we are on the right folder.
So that's the folder to set as working directory.
Let's make sure we have the social network.
CSV file. All good.
So I'm going to click on this more button here to set this folder
as working directory.
And here we go.
Everything is fine.
We're ready to start making the model.
So the first step as usual is to preprocess the data.
And to do this of course we're going to use our data
pre-processing template that we made in part one.
So I'm going to select all this
copy.
And then I'm going to go back to my logistic regression file to paste it here.
All right.
And now we just need to change a few things to preprocess our data.
That's of course the name of the data set here
which is social
network ads.
All right.
And then we need to change another few more things.
But first let's select this line to see what our data set looks like.
So come in and control this.
Enter to execute.
Here we go. The data set is well imported.
Let's click on that.
And here's the data set.
So as a quick reminder this data set
contains informations of users of a social network.
These informations are the user ID the gender, the age and the estimated salary.
And the social network has several business clients.
And these business clients
put ads on the social network for marketing campaigns purposes.
And one of their business clients is a car company who has just launched
its brand new luxury SUV at a ridiculous price.
So this car company put ads of their new SUV products on the social network.
And then the social network gathered some informations about
which users responded positively
to the ad by buying the product
and those who responded negatively by not buying the product.
So that's what the last column is about.
The last column tells for each user if the user but the car
and then it's its one or didn't buy the car and then it's a zero.
All right.
So that's the business problem itself.
And now our mission is to make a logistic regression model
that will try to understand the correlations between information
such as the age and the salary, and the decision of the user to buy.
Yes or no, the SUV.
All right.
So let's go back to our logistic regression model.
And let's see what we need to change next.
So this line is to select the variables we want to train our model with.
So as I just said we're going to train our model
with only the age and the salary.
So that means that we want to predict if the user is going to buy the SUV
based on only the age and the salary.
So here we will need to select the indexes of the columns
we want to take for our model.
So I'm going to remove that as comment.
And let's look at the indexes okay.
So indexes in are sorted one.
So that's 1234 and five.
So we only want to take the indexes three four and five.
So let's do this.
We're going to choose from 3 to 5.
All right.
So now let's select this and execute.
All right.
And now if we go back to our data sets
you can see that we only have our three columns of interest
which are the age the salary and purchased.
Okay.
Now next step.
Next step is to split the data sets into the training set and the test set.
And here what we only need to change is the split ratio.
Or maybe not. But we have 400 observations.
I think a good split would be to have 300 observations
in the training set, and 100 observations in the test set.
And to do this we need to take oh point 75.
That is 75% going to the training set.
That is 300 observations.
Okay.
So let's select this and command or Control plus enter to execute.
Here we go.
Now let's look at our training set and our test set.
All right.
So our training set as you can see has 300 observations.
And the test set has 100 observations listed here.
Perfect.
Now let's go back to our logistic regression
and take care of the next step which is the feature scaling.
So for classification it's better to do feature scaling.
So we're going to do it.
We're going to remove those comments here by pressing
command or control plus shift plus C.
All right.
And now let's check that we have the right indexes.
Here we have indexes two and three.
Here the dependent variable is categorical.
So we will only scale this.
And that's index one and two.
So let's go back to our logistic regression model.
And so here we need to choose 1 to 2.
So let's do it for the four
two. One two
and one two.
All right let's select this command and control plus enter to execute.
And here we go.
Now let's have a look at our training sets.
Yep. The age and the salary are perfectly scaled.
And same for the test set.
Perfect. Perfectly scaled.
All right, so we are done with the data pre-processing phase.
Now our data set is well pre-processed.
So that's the end of this tutorial.
I can't wait to build this logistic regression model
on our data set that is now prepared in the next tutorials.
Until then, enjoy machine learning.