In the last lecture, we saw how to create, how to compile and how to screen our classification modern
intensive, locate us.
In this video, we will be and crane a deflation model using get us.
For this, we will be using the very popular regression dataset that is California housing data set.
This dataset is available in a Skillern database library.
The objective here is to predict the prices of homes using eight different independent variables.
So let's get started.
First, we are importing some basic liabilities, such as by undoes and my plot.
Then we are importing tents up, flowing gave us.
And then since this data is available in Skillern dataset, we are also importing California housing
from Escalon big.
And we are saving this database and doing another really well called housing.
I also want to share one small shortcut to access the help of any function.
So if you just click inbetween of any function parenthesis and then hold the ship key and click on tab.
So if you hit ship less there, it will open the help or documentation of that function.
If you hit shift 10 two times, it will expand the documentation.
You can see here this function will return.
Different parameters such as not data.
It will give us the independent variables.
Dot, dot, dot will give us the dependent variable.
And the feature entity will give us the details of features.
Let's just close this.
So if you have any doubt regarding any function, just click between Prentice's and her shift plus.
So I have alluded this set some of the information about this database.
So in this database, there are around 20000 records.
There are eight independent variables.
We have first variable as made in.
This is the medium income in that particular block.
Warehouses located.
Then we have a second variable that is house eight.
This is the median house eight in that block.
Then we have average rooms, which is the average number of rooms.
And then we have average bedrooms for average number of bedrooms.
Next, we have population variable.
That is the block population.
Then we have average occupancy.
That is the average house occupancy.
And then latitude and longitude of that pole's block using this eight independent variables.
We want to predict the value of the house.
The values are in a hundred thousand.
So supposing forward, why would you build these five?
That means the value of their houses.
Five hundred thousand dollars.
So this is our dataset.
We have this eight independent variable and one target variable as space.
If you want some more detail about this dataset, you can click on this documentation link.
This will open the official Escalon documentation of this dataset here.
You will get to know about all the parameters that you can give.
And what are included in this database?
Let's go back.
So this housing is in the form of a dictionary.
We have one you loopier as feature me.
So just look at the feature names first.
You can see these are the eight variable names that we have discussed already.
Now to EXs, the independent data we have to use housing data and to access the independent data set.
We have to use housing target.
So in this line of code, we are splitting our data first into green full and best dataset.
Then we add further dividing this green full dataset in to extreme and X valuation dataset.
We will be using test train straight from Escalon model selection, and then we will use test train,
the split method to divide our data.
We are not giving any additional parameter for test sites.
That's because by default, the test size is 25 percent of the total data.
So 25 percent of the total data that is around 20000 goes will go into test set.
And then the remaining 75 percent will go in to training site.
All of that 75 percent.
Again, 25 percent will go into validation set and less of 75 percent will go into a working site.
Let's run this.
Next step is to process our data and we will be using the standard is scalar from Escala to standardize
our data.
And standardizing, we subtract the mean of each variable from their individual values.
And then we also divide it by the variance because at the end we want all the variables with mean as
zero and their variance as one.
This is a standard procedure to create any machine learning more than the steps here are very simple.
First, we are importing standard scale it from a skill pre processing.
Then we are creating the scalar object using standard scalar method.
Then we are training.
This is Escala Object using Nowhat Extreme Data.
So on our extra data, this is killer will find the values to subtract, as I mean, and to be weighed
as a variance.
Then we will use those values.
Or this is scalar object to standardize a word validation and assets as well.
Just so repeat, we are fitting.
This is scalar object on our training data.
And we are transforming our validation and test set using.
This is scalar object that we have put it on our extreme data.
Fate will be using fate, underscore, transformed, mattered.
And we will be using extreme as parameter to transform.
We will be using dort transform method of this scalar object and we will be using relevant datasets
here.
So let's create a standardized datasets.
We are saving this object in their original name only.
So we are replacing the ordinal extreme with the standardized version of extreme.
Is regional ex validation set in to a standardized version of X validation set?
And same for this site as what it says.
And this if you want some more information on this riskily.
You can always do for two and Skillern documentation.
More standard is scalars.
Next step is to set random seeds.
This is to generate the same result every time we run this modern.
Now, as I said earlier, our initial data set was off or on point, deposing laws or records.
Now let us see the shape of the extended SEC.
Here you can see we have eight columns and around eleven thousand six hundred reports.
You know what?
Extremely desolate.
We should never own five Posehn records in our X test dataset and around 4000 in valuation, say.
Now, let's create the structure for over regulation neural network.
Here we will be first having an input layer.
Then we will be having the first dance layer with party neurons.
Then we want to create second dance layer with another turbin neurons.
And then since this is the immigration problem, we will be having a single output neuron without any
activation function.
A single neuron, since we want a continuous value as our output.
Again, we will be using the sequential EPA.
We are saving this structure or our model as model.
And then for the first, Leot.
We are writing.
Get us dot leered, dot dense.
Here in parenthesis, we have to provide the number of neurons, which is starty.
Then, as discussed in our three lectures, we will be using activation function as the RELU.
And then since this is our first Soudan there, we need to provide the input shape since the number
of independent variables in our data is eight.
We will be using input chip equal to.
You can also use like this input shape.
Do extreme dort shape and then calling the second and so on, elements of over input chip.
This way you don't have to worry about changing this number every time you change your data base.
You can just straight xstream not shift and it will automatically get the number of variables from the
shape attribute of forward extreme object.
So this is the structure of our first dance layer will be cleared.
Second, dense layer in a similar fashion.
We will be using give us dot layer, dot dense.
And then the number of neurons in the parenthesis, which is 30.
And activation function as the RELU.
Similarly, for the output layer, we will be using guitars, dot layard's dance.
And since this aggression problem, we will be using a single neuron without any activation function.
Just run this.
And again, one important thing you can comment using hash symbol inside the cells.
So Biton will execute on this part of the code and will not be executing any code which starts with
Peche as planned for starting the coming.
So now we have created the structure or architecture of what neural network does to conform and view
this structure.
We can call thought somebody might just write Mordred or.
Somebody here, you will get the information about the structure that we have created.
So we have first dense layer with dirt in Iran.
We have second dense, layered with protein neurons.
And lastly, we have a single output layer with one neuron.
This is what we wanted.
The next step should be to come find this Martin.
Again, the combined method works similar for both classification and duration model.
First, we have to mention the loss in classification.
We were using Crosson Groppi.
But Pia, since we are planning regulation, we have to use mean squared error, also known as MASC.
The second parameter is optimizer.
Again, here also we are using as Sudi, so plastic gradient descent.
And here we are also providing the learning rate by default, the value of learning rated zero point
zero one and two genes.
You can just write.
The new value in the parents is.
We have already discussed what is learning English in order to re lecture.
So if you have any doubts, just revisit that lecture.
And then the next parameter that we are passing is metrics.
This is an optional parameter.
In classification, we were using accuracy.
But in regulation, we can use mean absolute error or m a e absolute error is the difference between
the predicted value and the actual value.
Whereas the mean is squared error is the square of that difference.
So we are concluding both mean squared error as a lost function and Emmy as the metrics we additionally
want to calculate.
Again, just remember, if you want to look at the documentation or hell, just click inside any of
the parenthesis and.
And press shiftless tab, you will get this kind of documentation.
And here you can see that by default the learning rate value is 0.01.
So in classification, we did not provided any learning rate.
So the learning rate that was used, there was zero point zero one.
But you can always teach these values according to your need.
Let's run this.
So we have compiled over more than.
The next step, the next step is to screen out more than using screening data.
The method or the process is same.
We are creating another object model underscoring speed for screening.
Then we are using more than not fit and we are passing our training dataset number of box and the validation
dataset that we have created.
Just run this a statement.
Again.
Just like the classification model, you will get the lost value, which is the squared error.
You will get the Emmy you and you mean absolute terror.
And similarly, you will get these two values for your validation set.
That's when.
And you can see that the loss on both training set and relevation set is decreasing with each epoch.
Now we have these values for our training and validation set.
We can also evaluate performance of this train model on our test set.
And we are going to use the same method as fitted with classification model.
We'll call model DOT evaluate.
And then we will pass our training test.
Then this.
You can see on our trained deselect loss is zero point three.
That is masc or squared added and m e e mean absolute error is zero point four four nine three.
Now, just like in classification, we can call modern history, not history, that will give us the
values of all this much crisis in the form of dictionary.
And this year you will get the loss and Emmy on dreaming.
Does it end?
And Relevation Lowson validation me.
The beauty of this is we can load this dictionary on a block just like we did for classification, and
that will show us how we're training.
Loss and reputation loss are changing with each epoch and whether we have achieved the convergence or
not.
This and this.
So you can see we have the loss values and the Emmy win lose photo, well, training and validation
set out on this graph.
And one thing to notice is this graph is still going down, meaning that if we won some more epochs,
this will further decrease the losses and improve the accuracy of our THAN.
So this is the one way to tell whether you have achieved convergence or not or whether you have to increase
your epoch relative or not.
You have to look at this validation, loss and validation Emmy value.
So this the validation loss.
And you can clearly see that it is going down.
So to improve the accuracy, we can read on this called.
Run it for finding more Reeboks.
So just go there.
Now, one important thing about guitars, these guitars have the beats and Bias's value in the memory.
So if you just redone this whole this statement, again, this will not screen the data from Esack.
But it will start training the data from this position.
So if we run this a statement two times that is similar to running a statement with the box.
If we just read on there one more time.
You can see earlier the lost values were.
Around point seven or eight point two for the first Sepo.
And then gradually decreasing.
But now we have started from that 20 plus epoch.
Last same, the lost value on our test set was zero open three zero.
Let's see whether we have improved this lost value or not.
You can see the losses decrease from zero point three to zero point two five.
So what have put this is was correct that the model was not converged in 2012.
There was room of improvement and B, B, then the whole more than 420 more epochs.
That is a total of four epochs.
And we can see this graph.
You can just.
Focus on this reputation loss lane.
Earlier, it was set upon for a long period and this.
There is a slight decrease in valuation loss.
Now you can see that the line is flat turned out.
This means we have achieved the convergence on this model.
So not just with regulation.
If you are running classification model as well.
Just look at this graph to identify whether you have achieved convergence or not.
Now, to predict the values on the new dataset, you can always use, not predict metric.
So your object name and dot predict method.
And then the new dataset.
I don't have any new dataset.
So I'm just creating the sample of those three values of my X dataset.
And considering it as my new dataset and then saving the information in Y pretty good values and using
model lot.
Predict my turn to predict the values that the Fed will use using this model.
That's all for dyslectic in the next lecture.
We will be looking at the functional EPA of get us.
Thank you.