In this lecture, we will process our data to make it ready for our linear regression.
Now, as you can see, we have three categorical variables.
And to run linear regression, we need only numeric variable.
So in this lecture, we will convert these three categorical variables into numerical variables.
We are not going to perform a single treatment and outlier treatment since we have already performed
both of these operations in this data already.
Now, let's.
Create another copy of this data.
I'm naming this sheet as pre-process.
Now, first of all, we don't need this serial number of variable.
So I can just go ahead and deliver this.
Now we need to convert this three categorical variables.
And if you see there are three categories in this first type of his rebel.
So overall, we need two additional variables to convert this categorical variable into numerical even
remember, the number of variables you need is equal to number of categories minus one.
So the number of categories is three.
Therefore, we need two variables for converting this type of iStore categorical variable.
Now, let's insert two new columns.
For this horrible.
So type of a story is taking three values, large, medium and small.
We are going to create two variables store, underscore large and store underscore medium.
Store large will take value as one wherever this type of a store variable is large and it will be zero
for type of historical to medium or small.
A spore equal to medium variable will take value one wherever this type of a store is equal to medium
and it will take value zero where the type of stories large or small.
So this is the way in which we are going to convert our type of instant variable to numeric variable.
Known for applying these conditions we can use if a statement, let's first write.
The underscore the large.
And.
The storm underscored.
Medium.
Now, let's try the condition we'll use if a statement so equal to if.
Now, the test we want to perform is that where this value is equal to large?
Remember that these values are case sensitive, so that's why we have kept El Capitan and all the other
characters as Lorqess.
So if this value is large, we want one or else we want zero.
So you can see that for the first role, the type of stories large.
That's why we are getting a story under Scollard as one.
Now, you can expand this formula to other cells just by clicking on this cross icon at the bottom right
corner, so double click on it and it will expand your formula to other cells.
So you can see that for all these rules, we have store type as medium or small.
That's why we are getting zero.
And here they so type is large.
That's why we are getting one.
So our formula is working fine.
Now we can use the similar formula for iStore underscore medium as well.
Now, there is a slight change in formula instead of large, we are looking for value equal to medium.
So this is equal to.
Medium.
Now, if this were a medium we want one or else we want zero.
Now, let's expand this for one or two other, as with.
So you can see that for these two roles, we have tape of a store as medium.
That's why we are getting one here for these two stores, the type of a store is a small.
That's why we are getting zero.
Now, we have accounted for large and medium store, but what about the smallest store?
So small stores are already counted, so wherever the value of astrologist zero and store medium is
zero, that means the store type is small.
So using these two variables, we have converted this categorical variable into numeric variable.
Now, similarly, we have to convert this type of location and security variables as well.
Well, let's move on to type of location with IBN.
For type of location variables, we have two categories, commercial and residential.
This means the number of categories is two.
Therefore, we need to minus one equal to just one variable for converting this categorical variable
into numeric variable.
So just insert a new rule and here we will rate location.
Underscored.
Residential.
So wherever type of location is residential, we want one as output over here and wherever the location
is commercial, we want zero.
So, again, we can use if statement with conviction.
This cell is equal to residential.
Then we want one or else we want zero.
Let's expand this formula to other cells.
So you can see for the first row, the location is commercial.
That's why we are getting zero over here.
And for the next seven to eight rows, the location is residential and we are getting one for all of
this Rose.
You can see that our formula is working fine and we have successfully converted this categorical variable
type of location into this numeric pretty with the last categorical variable, this type.
And we can convert this subject into a numerical variable.
Similarly, as we have done for type of restaurant type of location, so just insert a new column.
Now, again, in Saudi Arabia, also, there are only two categories, that means we need only one variable
to portray the same information here.
I will name the variable as simply underscore micro.
This variable will take value one wherever the city type is, metro, and it will take zero for city
type equal to non Metro.
So, again, we can use if his statement if.
This is called micro.
Then we want one or else we want zero.
You can see that first record was not micro, that's why we are getting zero over, you just expand
the selection.
You can see that for this for Rose the serotypes micro and we are getting one year.
So we have successfully converted all our categorical variables into numeric variable.
Now we can use this data to build our regression model.