Let us implement the code, so the first thing which we will be doing is equally important in campaign
finance, Liberi.
So often in building the libraries, people read those.
So we have done this earlier also, so we will read the city's history by using Beedie, don't read
CSFI.
And this is the real estate data center, which we will be using.
So using the function, I will be retrieving the top 10 rolls of the data.
So these are the top 10 rolls of the data.
The columns are No.
X1 transactionally x two, housing X three distance to the nearest and station, then X four, which
is number of convenience store X five but just magnitude six, which is wrong with you and Y, which
is the house price of the unit.
So it is self-explanatory that we have these several X values, which is six feature columns or six
attributes using which we want to find out the value by.
So this is the value, which is the target value.
This is the value that you want to predict and these are the values which we already have.
Now, while we will be training the model, we will be providing all of this data to the model to learn
from it, and then we will provide it and unseen data so that the model you can actually predict the
values.
So first of all, we check the summary of this data so we can see the values of the column, so you
can see all of these are numerical.
So we don't really have to apply any data transformations here.
So the values for number is one hundred and forty nine, Foulk.
So the value minimum is one, the maximum value is 14 for the.
Then we have next Gollum's X1, which is transactionally.
So here the value is again.
Similar, so the transaction date has two thousand and twelve 917.
These are in numeric form.
So what we can do is we can transform this transaction date to give three different columns.
That is one with the Second Amendment and third one with the day of the month.
Next, we have housing, so housing is again in a no fly zone, which is perfectly fine, then we have
dist..
Then we have a number of convenience stores, so this is, again, in the new Med. So as you see all
of the columns on a new form, so we don't have to do much to it.
So let's go further.
Let us check how many null values are present, so to remove the null values, we can simply do real
estate, not drop any.
Which will allow us to drop all the null values so you can see that there were no null values, that
this might be four hundred and fourteen rules are in that.
Next, we will check the money, so for the House to mean.
Value we are putting the real estate value, we get the X to house each value from the real estate data
frame and find the meaning of it, then we can simply print the mean age of the house.
So the median house is seventeen point seven one years.
Next, we have mean convenience stores, so the mean number of convenience stores is calculated by the
State of the Union, then the column name, and then we apply the mean function to it.
So we get the mean convenience store us four point zero nine.
Now, let us make up a few blocks out of this data.
So first we will create a regression plot.
So here we are creating a regression plot of the data with X as the X value with the house, each value
with respect, with the comparison to the Y value.
So we are comparing the house each with the value.
So you can see that the data is slightly.
In a straight line, and there is nobody not a very high correlation of the value.
So let us see what is the data so you can see we are finding out the correlation value.
So we are importing stats from sci fi and we are finding, though, we are still pushing and value.
So Pearson Corporation does nothing but the correlation value, so we are running the stock start Pearson.
And we are putting in the extra house each and every house price to it.
So we have found out that the correlation between the house and house price is the person go fishing
villages minus zero point two one.
So you can see the correlation value is negative, which is also visible from the graph.
Because it is going towards the negative direction, but it is not going in a very straight line, it
is not going in a complete diagonal line.
So it shows that the relation relation is a weak relationship and also a.
Low value, so it is not a very strong relationship, so it is a negative zero point one value.
Now next we have a value veges one point five six, which is, again, not a very high P value.
So now we will check again for the extreme cold extremes, the distance to the nearest amortisation
with respect away, so we will find out the correlation value and the p value for this.
Now, here, the correlation value is minus two point six seven, which is, again, not a very high
correlation and the P value is four point sixty, which is also an acceptable value.
Next, we are comparing the export problem with why, so for this, the correlation value is zero point
five seven one, which is, again, not a very high value.
And the value is three point forever, so it is also acceptable.
Next, we have a correlation between the latitude and the house price.
So on comparison, the Confucian correlation coefficient is, again, not very high.
Next, we have the relation between longitude, so the longitude correlation coefficient is not also
very high, we would have removed this column only if this value has been greater than zero point nine,
then only we will remove this particular column.
Now, I have done this one by one.
I have found out the correlation coefficient one by one.
You could have simply applied the Findus profiling for finding out multicore linearity and finding out
the details of the data.
But because we have already done that and we have already learned about this matter.
So I'm showing you a different method here.
Apart from this, you can apply the Ditech function, which we have built in the confirmation class
where we have discussed about the direct function, which would allow us to find out the correlation
Confucians for all the columns and then allow us to remove the columns, which had a very high correlation
coefficient.
So now let's go ahead and apply the linear regression on top of it, so for applying the linear regression,
we will first have to import the model from the model library.
So the library is Escalon.
Escalon Library is a very extensive library, which has a lot of models in it.
So the model is like a regression decision, trees, whatever.
We will be learning, we will be learning it.
I'm using the Skillern implementations of this.
So we are importing linear regression from.
So the first thing which we do is we create an object.
Of the Linnean modern.
And after creating this particular object, we will get the data.
So the data which we have is the x value and the value.
So we will need to have the X values and the right frame separated.
So I'm getting the value of X to house each in my X to data frame.
This is because I want to implement a simple linear regression and I want to implement it on the basis
of just one volume.
As of now, we will see how we implement it for multiple columns, but for now we are implementing it
for just one volume.
When we implemented using the phone column, only one column, then the equation which we will be getting
would be something like Y is equal to a makes policy advice, equal to be done on plus than one X one.
So this is what we are trying to implement as of now.
So this is the X data frame and this is the way that every exit frame will have the X value and everything
will have the Y value, next thing which we do is we train the model.
So to train the model, we simply say Alamdar fit inside it.
We provide the X and Y column to.
We provide only the X and Y column, so based on this X and Y column.
Based on this X and Y column, we will be training our models, so when we run this line of code, the
model trains and learns from the data.
After training and learning from the data, we can use them, don't predict to actually make predictions
on the data.
So I'm giving the column on which I want to make prediction.
So I'm giving the new X values and I can give all the X values.
Also, I can give any X values which are from the same column.
So we have to make sure the quality that we are using is the same here.
Whatever input we have given in the same type of input has to be given in the predict.
If we have given some training detail of X, then the testing data for X two has to be given here.
So the same format would be expected here and then once we do and don't predict, it will predict the
respective values for X and give them back in the Y.
So these are the values which we have predicted.
These are the different values which we have predicted.
Now we have three functions available, three attributes available, which is a limbered intercept,
a lame duck position and a lame duck score.
11. Intercept will provide us the value of the intercept, which is the value of the be done on.
A limbo of confusion will provide the value of the provision, which must be the one in this case.
Remember, the equation which we are generating as of now is why is equal to be done on plus one in
two x one.
So this is the Danoff and this is the one.
And when he you caught we are getting the R squared value, so the score is zero point zero four for.
Now, we will be plotting that, as you will applaud that as you will, but is nothing but just the
values of the data, which we have predicted.
So we are plotting the extra values and the values, and these are the values which we have.
But this is the plot for the scene.
Now we will compare the actual values words versus the predicted values.
So on the basis of.
We are giving the real estate White House price of the unit and we are plotting another distribution
plot of the very highest value.
So in the first one, we are giving the.
Actual values in the second one, we are giving the very highest values, these are two different plots.
This is the first plot and this is the second line which we are plotting in the same figure.
So we have also given the labels so we have the legend, which has great for actual value.
So you can see these are the actual values and these are the certain value.
These are the values which we have predicted in local.
So you can see there is a lot of difference between the actual value and the values.
So the next thing, what we will be doing is we will try to put a model on the basis of all the columns
which we have.
So we will create.
A new data from it with all the required columns that does X one transaction need extra extra X for.
It's five and six.
On the basis of this, we will run the limbered Fichte.
And we will predict the values of Z.
So when we predict the values of Z, we get the new Y and we will bring the plot for the scene.
So now you can see the values are somewhat similar.
The values have improved.
The model has improved.
Now.
Now, the next thing which we will be doing is we will split the data into two different splits.
You remember we discussed about the first method, which is the hold out method, where we split the
data into two parts.
One is the training data and another one is the testing data.
So here we will import the model selection that this segmenter.
So the brain this method will allow us to split the data into two parts.
So in this method.
We provide the Z value, I'm divine value Z value is a new date every which consists of columns one,
two, six.
And why is that?
The definition which contains the values, the actual value values.
And here we have the fist size, which defines what proportion of the an entire data we want to have
as a test data.
So here I'm saying I want to point to as my data, which means I want 30 percent of my data.
Do we estimate data?
So the rest of those 70 percent of data will become my training data.
So I provide the random state, random state to be zettl so that each time and it gives the same type
of split, the values which are given in each state remain the same.
So.
Here I am printing the lightest.
Here you can see the extreme follows.
These are the extreme values.
Based on the split, so when we are making the split, we are giving Zelon way and after the split it
gives for civil X values, which is X training value, the X value on which we have to train, then
the X value on which we want to best, then divide value on which we want to bring and the value on
which we want to test.
So make sure the players which you are using for training are extreme and widely and the fear that you
are using for testing is X and Y.
So here I am comparing the value.
So here I am comparing the values of the real estate problem with the very best value.
So it comes out to be almost similar, so you can see the mood has improved.
Here is the list of the intercepts.
So this is the Intersect.
And these are the Old-Fashioned values with respect to each one.
So for the first volume, this is the Disick for the House.
This is the intercept for extra distance.
This is the intercept forex phone number of convenience stores.
This is the intercept for five latitude.
This is the intercept for six longitude.
This is The Intercept.
Now, these values.
These values are the guiding the linear regression now for that, we will have a look at two variants
of linear regression.
So let us look at those in the next session.