‫In the last lecture we saw how to create how to combine and how to screen our classification more than
‫intensive look at us in this video.
‫We will be and train a regression model using gave 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 a different independent variables.
‫So let's get started.
‫First we are importing some basic liabilities such as Num by on does and my lib then we are importing
‫tens of flowing gave us and then since this data is available in and school on dataset we are also importing
‫California housing from escalating dataset and we are saving this database and going another way label
‫housing.
‫I also want to share one small shortcut to access the help of any function.
‫So if you just click in between of any function parenthesis and then hold leadership key and click on
‫tab.
‫So if you had ship plus that it will open the help or documentation of that function.
‫If you shift type food banks it will expand their documentation you can see here.
‫This function will return different parameters such as not data.
‫It will give us the independent variables that target will give us the dependent variable and the feature
‫me will give us the details of features let's just close this.
‫So if you have any doubt regarding any function just click between parenthesis and head shift.
‫Let's add so I have alluded listed some of the information about this database.
‫So in this database there are around don't polls and records.
‫There are eight independent variables we have first variable as mad in.
‫This is the medium income in that particular block warehouses located.
‫Then we have a second variable that is House 8.
‫This is the median house each 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 a 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 holds block using this eight
‫independent variables.
‫We want to predict the value of the house.
‫The values are in hundred thousands.
‫So supposing forward why variable is five.
‫That means the value of that houses five hundred thousand dollars so this is our dataset.
‫We have this independent variable and one target variable as base.
‫If you want some more detail about this dataset you can click on this documentation link.
‫This will open the official Eskil on 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 the school back
‫so this housing is in the form of a dictionary and we have one devalued beer as feature name.
‫So just look at the feature names first.
‫You can see these are the variable names that we have discussed already now to access the independent
‫data.
‫We have to use housing data and to access the independent data set.
‫We have to use housing data gate
‫so in this line of code we are splitting our data first in blue green full and best data set then we
‫add further dividing this green full dataset and do X green and x y new addition dataset.
‫We will be using test Green is from Eskil on model selection and then we will use best green display
‫metric 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 goals will go into test set and then the remaining
‫75 percent will go in training site all of that 75 percent again 25 percent will go into validation
‫set and rest of 75 percent will go into our green site.
‫Let's run this
‫next step is to process our data and we will be using the standard is scalable from a scalar 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 zero and their variance as one.
‫This is a standard procedure to create and the machine learning more than the steps here are very simple.
‫First we are importing standard skill it from a skill and processing then we are creating a scalar object
‫using standard scalar method then we are creating this scalar object using what extreme data.
‫So on our extended data this is scalar will find the values to subtract as I mean and to divide as a
‫variance.
‫Then we will use those values or this is scalar object to standardize our validation and as that 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 to take on our extreme data look for it.
‫We will be using it underscore transform method and we will be using extreme as parameter to transform.
‫We will be using dot transform method of this scalar object and we will be using relevant datasets here
‫so let's create a standardised datasets.
‫We are saving this object in their original name only.
‫So we are replacing the ordinal extreme with this standardised version of extreme.
‫Our order is null ex validation set in a standardised version of X in the relation set and same for
‫this site as well.
‫It says this If you want some more information among this the Skilling you can always do to as skill
‫and documentation center disclaimers.
‫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 dataset was off or on point deposing rules or records.
‫Now let us see the shape of the extended asset.
‫Here you can see we have eight columns and don't let thousand six hundred records in our extremely desolate
‫we should never own five puzzling records in our X dataset and around 4000 in valuation say.
‫Now let's create the structure for our regression neural network here.
‫We will be first having an input layer then we will be having the first dense layer with neurons.
‫Then we want to create second dense layer with another 30 neurons.
‫And then since this is a regression 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 layer we are writing gave
‫us dot layer dot dense here in parenthesis.
‫We have to provide the number of neurons which is 30.
‫Then as discussed in our two re lectures we will be using activation function as the loop.
‫And then since this is our first tool on there we need to provide the input shape since the number of
‫independent variables in our data is eight.
‫We will be using good shape equal to.
‫You can also use like this input shape will too extreme dot 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 trade extreme not shape and it will automatically get the number of variables from the
‫shape attribute of our 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 US DOT layer not dance and then the number of neurons in the parenthesis which is 30
‫and activation function as a low similarly for the output layer.
‫We will be using data as Dot players or dance.
‫And since this the regression problem we will be using the single neuron without any activation function
‫just run this.
‫And again one important thing you can come in using hash symbol inside the cells.
‫So python will execute on this part of the code and it will not be executing any code which starts with
‫hash as the loop then for starting the coming.
‫So now we have created the structure or architecture of the word neural network on just look on form
‫and view this structure.
‫We can call thought somebody might have moderated or
‫somebody here you will get the information about the structure that we have created.
‫So we have first dense layer with 13 neuron.
‫We have second dense layer with pretty neurons.
‫And lastly we have a single output layer with one neuron.
‫This is what we want.
‫The next step should be to compile 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 cross entropy but here since we are running regression we have to use means squared added
‫also known as MVC the second parameter is optimizer again.
‫Here also we are using as Zuhdi spastic gradient descent.
‫And here we are also providing the learning rate by default the value of learning rated zero point zero
‫one and two change.
‫You can just write the new value in the parent.
‫This we have already discussed what is learning rate in auditory lecture.
‫So if you have any doubts just read the entire lecture.
‫And then the next.
‫But I think that we are passing these metrics.
‫This is an optional parameter in classification.
‫We are using accuracy but in regression we can use mean absolute.
‫Edit R M E absolute error is the difference between the predicted value and the actual value whereas
‫the mean is squared.
‫Edit is the square of that difference.
‫So we are calculating both mean squared error as a lost function and add me as the metrics we additionally
‫want to calculate.
‫Again just remember if you want to look at the documentation or hell just click inside of the parenthesis
‫and and press shift less 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 0.01.
‫But you can always change these values into your named.
‫Let us run this so we have compiled our more than the next step the next step is to print out more.
‫Using training data the method or the process is same.
‫We are creating and another object model underscoring street for creating.
‫Then we are using model not fit and we are passing our training dataset number of epochs and the validation
‫dataset that we have created.
‫Just this a statement
‫again just like the classification model.
‫You will get the lost value which is the meaning of square data.
‫You will get the end me when you mean absolute error.
‫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 validation set is decreasing with each epoch.
‫Now we have these values for our training and validation set.
‫We can also evaluate performance of this grain model on our test set and we are going to use the same
‫method as we did with classification Martin will call model not evaluate.
‫And then we will pass our training there.
‫I say this then this you can see on our training does the loss is zero point three.
‫That is MFC or mini squared at it and m e e mean absolute error is zero point 4 4 9 3 No.
‫Just in classification we can call model history dot history that will give us the values of all these
‫my crisis in a formal dictionary and this year you will get the loss and add me on training dataset
‫and validation loss and validation and me the beauty of this is we can load this dictionary on a block
‫and just like we did for classification and that will show us how our training loss and regulation loss
‫are changing with each epoch and whether we have achieved the convergence or not.
‫Just this so you can see we have the lost values and the Emmy values for over framing and validation
‫set noted on this graph and one thing to notice is this graph is still going down meaning that if we
‫run some more epochs this will further decrease the losses and improve the accuracy of our more.
‫So this is the one way to tell whether you have achieved convergence or not or whether you have been
‫pleased you are awkwardly or not you have to look at this validation loss and validation Emmy value
‫so this the validation lost and you can clearly see that it is going down so to improve the accuracy
‫we can read on the score to run it for finding more epochs
‫so just go there now one important thing about guitars these guitars have the beats and biases value
‫in the memory.
‫So if you just read on this whole segment again this will not screen the data from Isaak but it will
‫start draining the data from this position.
‫So if we run this a statement bu times that is similar to running this statement for the epochs.
‫If we just read on one more time you can see earlier the lost values were around point seven nought
‫point take for the first sequel and then gradually decreasing.
‫But now we have started from the 20 plus epoch
‫last time the lost value on our test set was 0 1 3 0.
‫Let's see whether we have improved this lost value or not and see the losses decrease from 0 1 3 0 0
‫point to 5.
‫So our hypothesis was correct that the model was not converged in 2012 there was room of improvement
‫and be lead in the whole more than 420 more epochs.
‫That is a total loss for the box
‫and we can see this graph in just focus on this regulation.
‫Lastly earlier it was zero point for all we read and this there is a slight decrease in valuation loss.
‫Now you can see that the line is flattened turned out.
‫This means we have achieved the convergence on this model.
‫So not just with regression.
‫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 credit market.
‫So your object name and not really matter.
‫And then the new dataset.
‫I don't have any new dataset so I am just creating the sample of 4 3 values of my X asset and considering
‫it as my new dataset and then saving the information in y predicted values and using model lot predict
‫my total to predict the values.
‫These are the values using this model.
‫That's all for this lecture in the next lecture.
‫We will be looking at the functional API of get us.
‫Thank you.