‫Welcome back.
‫Let's remind ourselves of what we're covering.
‫So what have we done so far?
‫We've done zero.
‫And end to end psychic loan workflow.
‫And we've done one.
‫Getting the data ready.
‫Now, let's have a look at number two, which is choosing the right estimate slash algorithm for our
‫problems.
‫It's going to create a new heading here to choosing the right estimator slash algorithm for your problem.
‫So psychic learn is very vast, the library.
‫So we need a few ways or let's get a little bit of practice navigating it.
‫Let's write down some things to note is what you should be wary of.
‫As Kalen refers to when I say machine learning models and algorithms as estimators.
‫So this is one of the things you're going to come across in the world of machine learning is that there's
‫many different names for different things.
‫So just keep in mind, if I say machine learning model or if I say algorithm, cyclone calls these estimators,
‫and then within those estimators you have classifiers which are classification models, and then within
‫those estimators is also regresses, which is a regression model.
‫And if we remind ourselves, if we have a classification problem, we have predicting a category.
‫So something is usually one thing or the other, or it could be multiple categories.
‫In our case, we might look at heart disease or not, so one thing or the other.
‫And then again with classification you'll have classifiers which are an estimate or in psychic learn
‫and sometimes you'll see self.
‫So the abbreviation CLF, which is short for classifier used as a classification estimator.
‫So CLF is a very common classification variable name or classification model variable name.
‫And then we also have a regression problem.
‫We're focusing on regression and classification in this module that is predicting a number such as the
‫selling price of a car.
‫Okay.
‫Now let's turn this into markdown.
‫And if you've ever seen a list of different machine learning algorithm model names or estimate as algorithms,
‫etc., you know that there's a fair few of them.
‫So what Psychic Learn have done and if you haven't, that's okay, we're going to explore them.
‫They've created a map, so let's have a look at scalar and machine learning model map and I'll refer
‫to this quite often when I first got started.
‫Now I've got some experience.
‫Now this is going to be very daunting if this is the first time you've seen it.
‫But now that I've got a little bit of experience using all of these algorithms, which is what you'll
‫have by the time we finish these modules, I can sort of think about, okay, for a regression problem,
‫I need to use one of these algorithms for a classification problem.
‫I need to use one of these algorithms for clustering, which is of a form of unsupervised learning.
‫I use these for dimensionality reduction, look into those, but we're going to be focused on classification
‫regression.
‫Two of the major problems in machine learning.
‫If you'd like to look at what these are, I'd refer to the psychic loan documentation.
‫So let's start here.
‫So saying we have some kind of machine learning problem, we're going to go through these blue steps
‫and the arrows here are do we have over 50 samples, yes or no?
‫And if you don't have over 50 samples, well, psychic is telling you to get more data because what's
‫the thing of machine learning is usually if you have more data, your algorithms are going to work better.
‫So if you don't have more than 50 samples, such as 50 rows in an Excel spreadsheet or 50 different
‫examples of people with heart disease and without heart disease, you'll probably want more.
‫But let's let's get a data set so that we can follow this through.
‫The first one we're going to start with is a regression data set.
‫So I might just put this map link in here.
‫So if you're working on a machine learning problem and looking to use, learn and not sure what model
‫you should use, refer to the learn machine learning map.
‫There we go.
‫And of course, very confusing to begin with.
‫But as we get some experience, we'll see how we can use it.
‫So first things first is we'll need a data set.
‫Let's get a regression data set.
‫Hey, 2.1, picking a machine learning model for a regression problem.
‫Again, what's a regression problem?
‫It's predicting a number.
‫Let's use the California housing data set.
‫We might be thinking, Daniel, where are you getting these data sets from?
‫Where are you getting these ideas from?
‫Well, again, psychic loan documentation, ASC loan data sets.
‫So toy data sets.
‫What is a toy data set?
‫Well, it's like a small data set that you can practice on.
‫Now, in an original version of this video, we use the Boston data set.
‫However, that's been deprecated in 1.0, which is the latest version of Psychic Loan as of recording
‫this video.
‫So just keep that in mind.
‫If you're using an older version of psychic loan, the Boston data set is being deprecated.
‫I'll let you read into the documentation as to why that might be.
‫So in saying that we're going to focus on the California housing data set.
‫Do we have housing here?
‫Housing?
‫Where is it here?
‫Boston housing.
‫Deprecated.
‫Huh?
‫Toy data sets.
‫Let's look it up.
‫If in doubt, Google it out.
‫Ask learn California housing.
‫There we go.
‫Data sets.
‫Fetch California housing.
‫Hmm.
‫I wonder why that wasn't in the toy data sense.
‫Maybe it's in data set loading utilities.
‫California.
‫Oh, there we go.
‫Real world data sets.
‫Okay, so there's some toy data sets and then there's real world data sets.
‫We're using a real world data set haha.
‫So here we go.
‫These are all built into cyclone.
‫Now your data set might not necessarily be built into cyclone.
‫Well, it probably isn't.
‫But these are data sets that you can practice on, so that when it comes to working on your own data
‫set, where you go, Hey, I've practiced working on a data set.
‫So in this case we want to predict the here we go.
‫The target variable is the medium house value for California districts expressed in hundreds of thousands
‫of dollars.
‫So hundreds of thousands of dollars.
‫Does it have any code examples?
‫Here's where it links to the function, which we've got up here.
‫Code example doesn't have any code example, but user guide.
‫There we go.
‫Well, it just links us back there.
‫Well, let's see it in action.
‫Hey, why don't we, instead of jumping around the documentation, let's write some code.
‫So let's go get Kelly Fournier housing data set, and we're going to go from SRC, learn dot data sets
‫import.
‫Fetch.
‫California housing and we'll set up a variable called housing equals fetch California housing.
‫This is a function.
‫All we're doing is we just calling this function here.
‫I might link this in there so that we've got it.
‫Let's use a California housing data set.
‫And then if we have a look at what housing looks like, what does it give us?
‫Might take a little while because it has to load a data set from the Internet.
‫So depending on, oh, it didn't show us.
‫Okay, there we go.
‫Beautiful.
‫So we have a dictionary.
‫How do we know that?
‫We've got the dictionary curl there.
‫And then we've got a key called data and an array of all different numbers of values here.
‫We've got the target column.
‫We've got the target names, we've got the feature names.
‫So in our case, we want to use the features to predict the target.
‫So let's have a look.
‫Let's turn this into a data frame so it's a little bit more easier to use and visualize or housing DF
‫equals PD data frame.
‫Remember for data frames we can pass them a dictionary.
‫So in our case we want to use our housing dictionary and the data.
‫So let's remind ourselves of the docstring of DataFrame we want the data is what is the data key of
‫the housing dictionary.
‫And if we go down the index is something else.
‫Columns, something else.
‫So columns.
‫There we go.
‫That's what we want.
‫So what if we just did the data?
‫What does this look like, housing?
‫DF Okay, yeah.
‫So see, we've got one, two, well, eight columns starts from zero.
‫We've got 20,000 samples.
‫This is beautiful, very close to a real world data set 20,000 samples and then we have yeah.
‫So we want, we want some labels here.
‫So this is our features.
‫Features.
‫Let's do that.
‫Let's write this in here.
‫Columns.
‫Equals.
‫We want feature names.
‫What does this look like?
‫Housing DF.
‫Honore.
‫We need housing.
‫Housing.
‫DF Beautiful.
‫Okay.
‫That's what we're trying to do.
‫So target names is med house value.
‫So let's we need we need the house value on there.
‫So let's add a column.
‫We'll go housing.
‫Housing DF and we'll call it.
‫The target name.
‫Med house value.
‫So let's call this equals the housing data frame.
‫So this is going to be our target housing.
‫And if we come back up.
‫Target.
‫Now, this is what you'll have to do with a lot of your own data sets.
‫Again, this one is fairly formatted for us already, but you'll often have to construct it in such
‫a way that it's manipulative or you can manipulate it using something like pandas or psychic learn or
‫numpy or something like that.
‫So now let's have a look at the head.
‫Wonderful.
‫So what we're trying to do here is use these values to predict this value, the med house value.
‫Now, what are these values?
‫Med Inc house age, average rooms, average bedrooms, population occupation, latitude, longitude.
‫Well, let's have a look at the the function.
‫Well, it is a function, but we read more in the user guide.
‫Real world data sets California Housing Data Set.
‫There we go.
‫INC is median income in the block group and a block group is using one row per census block group.
‫So each row in this data set zero one, two, three, four, etc. Up to 20,000 is a block group in California,
‫and a block group is the smallest geographical unit for which the US Census Census Bureau publishes
‫sample data.
‫So it's typically around 603,000 people.
‫So we're trying to use a small area of California and some statistics or some attributes about that
‫area to predict the median house value expressed in thousands, hundreds of thousands of dollars.
‫So in this case, this row zero for whatever group that is in California, at this longitude and latitude,
‫the median house value is 4.5 to 6 times 100,000, which is 452,000, 6000.
‫Something around there.
‫Just times this by 100,000.
‫That's the house value.
‫Now, what I might redo this just to keep our brain sane is change this to target.
‫We just have to remember, oh, and how do we get rid of a column housing df we want to drop made house
‫val do we have in place here in place equals true drop oops.
‫No it doesn't housing.
‫DF ACLs housing df drop and we need axis equals one housing.
‫DF Okay, there we go.
‫Now how might we build an algorithm to use these features to predict this target value?
‫Well, first things first.
‫What do we have to do?
‫Well, I have to split our data first, not to split our data into features and targets, so X and Y.
‫So let's do that.
‫First, I'm just going to put a little statement here.
‫Import algorithm.
‫And now we want set up random scene so we can create the train and test data and random seed is going
‫to be 42 and then we're going to create the data.
‫X is going to be housing DF dot drop.
‫We're going to drop the target value on the axis equals one.
‫We're going to set up Y.
‫So the labels is going to be what the target value which is.
‫Let's put in here what it is.
‫This is median house price in hundreds of thousands.
‫And then we're going to split the data, split into train and test sets.
‫So we want x, train x, test y, train y test equals want train test split.
‫We've seen this function before.
‫X Y test size equals 0.2.
‫This is going to split our data randomly into training and test sets.
‫And now we want to instantiate and fit the model and we want to fit the model on the training set so
‫we can evaluate it later on the test set.
‫Now we don't have a model ready.
‫However, where might we go if we wanted to check where we can use a circuit learn algorithm slash estimator?
‫Well, we'd go to the psychic loan machine learning map.
‫Beautiful.
‫So we're going to start here and we have above 50 samples.
‫Yes.
‫All we predicting category.
‫Are we classifying something?
‫No.
‫Are we predicting a quantity?
‫Yes.
‫Do we have under 100,000 samples?
‫Yes.
‫A few features should be important.
‫I'm not actually sure what this one is.
‫So a few features should be important.
‫So how many features do we have?
‫We have about eight or so.
‫How do we know which ones are going to be important or not important ahead of time?
‫Now, this is where we're going to have to get experimental.
‫Now, all of these green boxes here are psychic learn machine learning models.
‫So if I click on lasso, if I click on Elastic Ridge Regression Ensemble Regresses, all of these are
‫different types of models.
‫So I'm going to close a few of those.
‫You can read up on those if you'd like.
‫But we're going to experiment here because we don't actually know the answer here.
‫Few features should be important.
‫I'm not sure.
‫Ahead of time.
‫Do you know which of these features are going to be most important?
‫I don't.
‫So that's the thing about machine learning, is that ahead of time you might actually know what's valuable
‫and what's not valuable.
‫The best thing to do is what?
‫Experiment, experiment, experiment.
‫So now let's just try something out.
‫Let's jump into regression.
‫Let's just say that, no, all of the features are as important as each other.
‫So ridge regression.
‫What is this?
‫We can read up on what it is.
‫There's a fancy mathematical formula, but let's see it in python code.
‫Again, I say fancy, but that's not taking away from how important this is.
‫The python code is based off that.
‫If you'd like to jump into that, you can.
‫But we're going to focus on writing the code.
‫So we need from scalar an import linear model, linear model dot ridge and then we pass it some data
‫here.
‫Let's see it in action.
‫Hi.
‫So we go here from Skyline Dot linear model in Port Ridge.
‫Again, all we've done is we've gone through this little cheat sheet and gone, okay, we've got above
‫50 samples.
‫We're not predicting a category.
‫We are predicting in quantity.
‫We have under 100,000 samples and we're not sure here.
‫So we're just going to try whatever we've got there.
‫The beautiful thing about machine learning is that you could try these and then compare them later on
‫to see which one performs best and then use that algorithm as your best algorithm.
‫So now that we've got the Ridge model, let's instantiate it.
‫We'll call it Model Equals Ridge.
‫Remember how I said if I call something a model so I could learn often refers to it as an estimate.
‫They're just different semantics.
‫We're going to fit it on the X train y train data that we created up here with the train test split.
‫And now we're going to check the score of the model.
‫On the test set.
‫So model dot score, x test, y test.
‫Let's see how this goes.
‫Oh, okay.
‫It's putting out some sort of value here.
‫Now, what does this value mean to us?
‫Well, not much at the moment.
‫So let's check the docstring of the score.
‫Return the coefficient of determination.
‫What is the coefficient of determination?
‫Let's Google that coefficient of determination.
‫R squared equals one minus reserve its sum of squares residuals.
‫Total sums of squares.
‫Hmm.
‫We've got Wikipedia.
‫Let's try this one.
‫Investopedia.
‫What is the coefficient of determination?
‫The coefficient of determination is a statistical measurement that examines how differences in one variable
‫can be explained by the difference in a second variable when predicting the outcome of a given event.
‫In other words, this coefficient, which is commonly known as R-squared or R-squared, assesses how
‫strong the linear relationship is between two variables and is heavily relied on by researchers when
‫conducting trend analysis.
‫Hmm.
‫Now we're going to dive more into different regression evaluation metrics, but what you should know
‫is that the default regression evaluation metric is for regression models in psychic learn is this R
‫squared value.
‫And so what this is saying here is that it measures the linear relationship between two variables.
‫In our case, we've got a few more than two variables, but essentially it's taking the relationship
‫between these variables.
‫So the features and the target variable and it's saying how predictive, right?
‫Using our current model, how predictive is our is our model given these features.
‫How much is it able to predict the target variable?
‫So we just said a lot there, but just think of this value.
‫The lowest value is zero.
‫The highest value is one.
‫So higher is better.
‫How predictive are these features of this target value?
‫So that's the coefficient of determination.
‫If you'd like to research that into it more.
‫You most welcome to.
‫But we're going to look at different evaluation metrics later on.
‫But for now, saying we have this value.
‫How might we improve that value?
‫It's okay if you're not sure.
‫But let's think about what data we have.
‫How do we improve machine learning models?
‫Well, one way would be to add more data.
‫Another way would be to choose a different model and try it out.
‫So remember I said a lot of this is experimental.
‫We've just tried one of these green boxes.
‫So your challenge for the next video is I'd like you to dive into any one of these green boxes over
‫this side.
‫Lasso elastic net ensemble regresses ridge.
‫We've done Ridge SVR, try it out, see if you can get it to work on our data set and see if you can
‫get it to improve upon our model's current R-squared score.
‫Just write the same code here.
‫The only thing that's going to change is the model that you use, and I'll see you in the next video.
‫We're going to try and improve upon this score.