‫So the beautiful thing is now that our data has no missing values and has turned all into numeric values.
‫We should be able to build a machine learning model.
‫So let's do that.
‫We've instantiated one way back up here as model, way back when this we started the modelling section
‫far out.
‫We've covered a fair bit of ground here.
‫It should be proud.
‫Modeling.
‫Wonderful.
‫We're going to do basically the exact same thing.
‫So let's build a machine learning model.
‫We could copy this, but we're just going to ride it out again.
‫We'll leave a bit of communication to ourselves.
‫So now that all of our data is numeric, as well as our data frame has no missing values, we should
‫be able to build a machine learning model.
‫Wonderful.
‫So remember what our goal is.
‫It's to find patterns in the data to predict the sale price.
‫So that's what we'll have to do.
‫Let's have a look df temp dot head.
‫One last look at our data before we model it.
‫So we need to drop the sale price column.
‫So that we can build a machine learning model that takes in all of the other columns except for sale.
‫Price finds the patterns and then tries to predict sale price.
‫So what I'm going to do, I'm going to set up a little timer magic.
‫And if you haven't seen this before, the percentage percentage sign that's a Jupyter Notebook magic
‫function.
‫You can search out for a whole bunch of these.
‫But what this is going to do is basically just calculate how much time this particular cell takes to
‫run.
‫And I'm going to do it on my computer, which is a MacBook Pro.
‫How many rows do we have?
‫We have 400,000 or something.
‫Rows.
‫This may take a little while.
‫In previous examples, when we've worked with less data, our machine learning models have been pretty
‫quick, right?
‫Because it's only have to sort through a couple of hundred rows.
‫But this is 412,000.
‫I mean, of course, there are much bigger data sets, but we're starting to get up there.
‫Right?
‫We're in the hundreds of thousands of samples instantiate model.
‫So what this time thing is going to do is because it's our goal as a as a data scientist, as a machine
‫learning engineer, is to do as many experiments as fast as possible.
‫If you're training models on all of the data all the time, it's going to take a fairly long time.
‫So I'm just going to demonstrate how long it takes for my personal computer to use a baseline random
‫forest regression model to find all the patterns in all 412,000 rows.
‫So don't worry, you're not going to have to sit there and watch it run.
‫Once we kick it off, I'll pause the video and then come back and show you how long it took.
‫The ways of thinking I want you to start thinking about is when you're doing experiments, start to
‫think to yourself, How can I reduce the amount of time it takes between my experiments?
‫The reason being is because you're not always trying to do the right thing.
‫You're trying to figure out what's wrong, what doesn't work.
‫So that's the rationale between trying to speed up your time between experiments.
‫And as I type that, as I talk, what we're doing here is we're just instantiating a random forest model.
‫We're going to put random state equals to 42 there.
‫Random state equals 42.
‫That way our results would be reproducible.
‫So this is all we're doing.
‫We've imported the random forest regressive class because we're working on a regression problem.
‫We're setting end jobs to equal negative one because this is a fairly large data set for what we've
‫been working with for now.
‫So I want to use all of the cause of my computer and I want random state to equal 42.
‫So our results are reproducible and I'm going to fit the model to the data.
‫So this is our X and this is our Y.
‫Remember, we're trying to predict sale price based on all our other columns except for sale price.
‫So when I kick this off.
‫This will take a few minutes, but I'm going to pause the video.
‫And because we've got the little magic function time here, we can see how long it takes.
‫So get ready to time.
‫Travel in 3 to 1.
‫All right, we're back.
‫That was pretty quick.
‫Hey.
‫So.
‫Our model is finished.
‫And it says here that the wall time was 6 minutes and 58 seconds.
‫So it took about 7 minutes to go through.
‫412,700 rows was actually pretty good, right.
‫Think about how quickly you could look at that.
‫How long would it take you to go through 412,000 different examples?
‫You didn't have to wait for that time because I sped it up.
‫But if you were to run this on your computer, it may take longer.
‫It may take less time depending on what sort of computer you have.
‫I'm running this on a 13 inch MacBook Pro, I think from about 2016 or something like that.
‫I'm not even exactly sure how much computing power mine has, but it's a laptop, so maybe not as much
‫as a desktop anyway.
‫But you can imagine as these numbers of rows started to really get up high, this could start to take
‫a long time.
‫If our goal as machine learning engineers, if our goal as data scientist is to reduce the amount of
‫time between experiments, we're going to have to be pretty nifty when we try out different models and
‫we work on different data because waiting 7 minutes every time, even if this number was higher for
‫a cell to run, that's going to slow us down a fair bit.
‫So we'll see a little trick soon of how we can improve this.
‫But why don't we score the model so see how our model did.
‫If it's gone over 412,000 rows, surely it's found something, some patterns in here.
‫So we're going to score it on just the exact same data that it was trained on.
‫So we'll copy this.
‫And now remember for a regression algorithm.
‫The default score value here is going to be return the coefficient of determination, which is the r
‫squared.
‫Now, if you need a refresher on what R squared is, you can go what is co efficient of determination.
‫But in other words, it's a score that can go up to one.
‫It's zero if all your model does is predict the mean of the sale price column and it can go to negative
‫infinity if your model is absolute terrible.
‫So we're looking for a value that's close to one.
‫So again, this might take a little while because the model has to compute the score of how it did across
‫412,000 rows.
‫Boehme 0.98.
‫Wow.
‫If the maximum is 0.987, so closer to 0.99.
‫So if the maximum is 1.0, does that mean our random forest or aggressor has almost found a perfect
‫pattern for finding predicting the sale price based on other columns in the data frame?
‫Not so fast.
‫I want you to think about before we get into the next video where we're going to cover it.
‫Why is this metric not reliable?
‫Right.
‫So if we have a look here, we fitted the model on this data and then we've evaluated it on the same
‫data.
‫Why doesn't this metric hold much water?
‫Have a think about it.
‫We'll talk about it in the next video.