How to build a machine learning model in Python from scratch
Key Takeaways
This video demonstrates how to build a machine learning model in Python from scratch using various tools and techniques such as pandas, numpy, scikit-learn, and PyTorch. It covers data preprocessing, feature selection, and model building.
Full Transcript
data science is such a vast field of study and for a beginner breaking into data science it might seem a bit confusing particularly because there are so many topics to learn about and to master and the big question is which one is suitable for each and every learner and the question very much depends on the unique objectives of each individual learners because everyone will want to use data science in a different way perhaps analyzing different types of data whether it be images tabular data audio streaming data and so i think i might have the solution for this particular issue and so when pat publisher reached out to sponsor this video and also provided a copy of this particular book i thought it would be a great opportunity to show you how you could repurpose some of the contents and codes that are provided in a book similar to this one and that you could use it for repurposing your own data science projects and so why reinvent the wheel when you already have a wheel prototype which you could adjust to your own specific liking and also to your own unique project requirements and so in this particular video we're going to focus on feature selection and i'm going to take you on a walk through and also show you how to practically take some of the contents and codes that are presented in chapter four and then repurpose it so that you could use it to your own real world data science project and so without further ado we're starting right now and so before beginning let's take a quick look at the book so the machine learning with pytorch and scikit-learn as the name implies will show you how to use scikit-learn to perform machine learning tasks pytorch for deep learning tasks and so at a high level the book will span a total of 741 pages of content and it will span over 19 chapters so let's have a look at it so in chapter one you're going to learn how computers learned from data and it's going to provide you with the basic terminology and also a roadmap for building a machine learning system it will briefly go through how you can set up python for your machine learning environment and then in chapter two it will take a brief look at some of the basic learning algorithms for classification in chapter three it will take a look at some of the machine learning algorithms or classifiers that are used in psychic learn then it goes to show you how you could build machine learning models using scikit-learn via logistic regression support vector machine and also using some other kernels in support vector machine also how to build a decision tree and also variants such as the random forest it will also cover about k-nearest neighbors as well and then in chapter four which we're going to focus in this particular video it covers some of the important topics of data handling and this includes how to deal with missing data how to handle categorical data because in scikit learn it typically will use numerical values for building up the machine learning model but then your data might contain categorical data such as low medium high for your class label or the various colors like red green blue which could be mapped into ordinal or nominal features it's also going to cover about how to partition data set when you split it into the training and the testing well chapter 5 covers the use of principle component analysis for reducing the dimension of the data chapter six will cover about how to model evaluate and how to perform parameter optimization chapter seven we'll take a look at ensembl learning where you're going to combine the powers of several learners into one meta learner chapter 8 shows you how to perform sentiment analysis and you're going to use the imdb movie data in chapter nine you're going to learn about regression and some of the data set that are used are the ames housing data sets and some other algorithms that are used for regression as well chapter 10 covers clustering analysis chapter 11 is building up artificial neural network models and then in chapter 12 you're going to learn about pytorch and how to use it for various deep learning tasks chapter 13 goes into much deeper details chapter 14 shows you how to use a deep convolutional neural network for classifying images how you could use recurrent neural networks for modeling sequential data chapter 16 will be on transformer for natural language processing and in chapter 17 you're going to be performing generative adversarial network for synthesizing new data so in a nutshell this allows you to learn from the data for example if your data is on t-shirts then it will learn from it and then it will synthesize new t-shirts based on the data that it has learned chapter 18 will be on graph newer net chapter 19 will be on reinforcement learning and so all of this will be covered in more than 740 pages of content and so let's jump to chapter four chapter four is on page 105. okay so i'm going to leave all of this reading to you and we're going to jump over to the code all right so let's minimize this a bit hide the sidebar and then i'm going to spin up a collab notebook which you could do as well and then we could say practice chapter 4. a pointed note is that the book also comes with the github repo for codes of this book and so for simplicity i'm going to just hard code the code from the ebook here into this collab notebook okay and so let's begin just copy and paste some of the contents here from i o import string io in the meantime i'll just hit on connect okay and then we're going to hard code the contents here so you'll notice that it'll have some missing data so we have this three quotations so that we could have the content spanning multiple lines we're just gonna skip the comments here so why don't we pretty much do this first so we're creating a text file and we're assigning the contents to csv data and the text file will be essentially a comma separated value file which is a csv and then in the next step we're going to take the csv data here as an input to the pandas read csv function in order to create a data frame do that df so we're creating a variable to store the data frame and we're using the read csv function to read the contents of the csv data and then we're going to use the string i o to encapsulate that and then let's run the f so that we see the contents and there you go this is the contents of the data frame so you're going to notice here that there are some missing values here and then in this particular block of code we're going to do a summation of the missing values so let's do that let's run this first let's see what happens okay so apparently if we have an empty space it doesn't detect it as a missing value well so we'll do it like this first okay there you go so now we could see that in row one with the index number of one because python counts starting from zero so row index one will have a value of true because it is a missing value because the function here tests whether each individual values here are missing yes or no and if it is missing then it'll be true and if we add the sum to it we're going to get the summation of the missing value for each column so here we see that in column c and d there are one and one missing values go here df.values so if you do that then it'll convert it to a data array okay should we import numpy oh okay take away the parenthesis all right there you go so we have the array so when you're going through the code it would be nice to also comment your code not just have a blank notebook like this and so for those who are breaking into data science or using pandas for the first time and it might seem difficult then it is highly recommended that you also kind of like write notes into your juvenile notebook so here it says identifying missing values in tabular data so we could do that we could document that we add it here click on the text cell and then you could double click on it click on the toggle heading click on bold and then you could type in the contents here identifying missing value and tabular data so i like to make it three hashtag here or hash symbol and then we're going to add another one on top make it one hash symbol and we're just gonna say okay chapter four and you could essentially type in some of the notes that you are taking when you're reading this book because when you're taking notes you're internalizing the contents to be your own and that will help you to digest the contents much better for example you could create something like this here we're going to import or here we're going to create a csv data file now let's create a pandas data frame from the csv data and then i like to use the tick symbol so that it becomes highlighted like that it's slightly highlighted and the font will be a bit different so that it distinguishes itself from the other content and make note that you could also use markdown for example i could use here in italic and this data frame is in italic csv data is using the text symbols and then we're going to say create a csv data file and assigning it to the csv data variable right okay and then here we're going to say let's check the number of missing values in the data frame we can also convert data frame into a numpy array and then we can say using the dot value method on the tf variable see so when you're writing all of this content out it helps you to evaluate what's the purpose of each and individual method or what's the name of the variable or what's the output look like and what's the type of the output so this will help you to internalize the contents as you go through the contents of this particular chapter right and when you're structuring your notes you could make use of the headings and subheadings that the book has like this one we could create a new one new subheading you could bold paste the contents in and then proceed to the next code cell so what does it do when you run it what does it do when you compare it with the df data frame which looks like this and when you apply the drop any function what does it do you see that rows with the index one is deleted rows with index number two is deleted and the only remaining is the one with index zero and so the drop any function will drop all rows that contain at least one missing value so if it has a missing value of at least one in the row it will be dropped and notice here that the input argument is axis equals to zero and so that will mean that you want to apply this particular drop any function on the row because the rows corresponds to the axis equal zero but if you say axis equals to one let's do that what do you notice you'll notice that the columns will be deleted so any columns that have at least one missing value it will be deleted and so therefore column c and d were deleted here so only columns a and b will be kept because it contains no missing data right and you could take notes here you could say here we're going to we're going to drop any rows and then you could say access equals 0 via the drop in a method or function and then you could copy that contents paste it here modify a bit drop any columns right and therefore you have a complete note you can see let's start by seeing the contents of the df variable again the data frame stored into the variable again right okay so i'm going to skip most of the contents here because we're going to focus on the feature selection and so let's have a look here so here they're explaining about the api for psychic learn particularly the estimator api and so the functions or the estimator for example if you're training a model you could create a variable called est for estimator and the estimator variable could contain the name of the machine learning function for example random forest and then what you could do here is that you could essentially fit the model on the x screen and y train data so the estimator here in our case will be the machine learning algorithm for example we typically can name it model or some tutorials we'll name it clf for classifier while i like to name it as model for generic usage which could then be replaced with import arguments indicating the use of other learning algorithms let's say i might change it from random forest to a k-nearest neighbor and then to a logistic regression and so i could keep the name of model variable intact or in other cases you could also name the variable to be an acronym of the machine learning algorithm like for random forest you could name it rf for support vector machine you could name it svm for linear regression you could name it l r okay so the fit function here will allow you to train a machine learning algorithm and that will result in the building of a machine learning model and there are other transform functions that will allow you to transform the data set for example if you want to transform the training data or the test data so here are some of the steps that you could do and it summarizes this in a schematic way for example you could use the training data and then you use the fit function and then you use the transform function and once you use the fit function here you have already trained a model for performing transformation of the data and then you could apply this model on a test data because you have already trained it using the fit function and then the model could be used to transform the test data into a transformed version okay so this is the schematic illustration of the concepts of the estimator in scikit learn so let's have a look at how to handle categorical data and because this is a heading and this are subheadings we're going to modify this a bit you could also add numbers to it as well you could call it 4.1 for section 4.1 and then if you have anything underneath it like a subheading you could call it 4.1.1 which will allow you to easily navigate the contents here you can call this 4.2 and now handling categorical data could be 4.3.3 did we add a dot yeah we did and then handling categorical data and we'd have it we could just have it as a bold text 4.1 and then we could say categorical data encoding with pandas you get bold and then we're just going to copy the code here so when you're starting out the tutorial it's always nice to just hand code the content and whenever you encounter an error it might be due to some mistyping and take a look at the error and when you have a familiar idea of which type of error creates which type of syntax that you will see then over time whenever you encounter a similar syntax output then you'll know that what went wrong and you know how to correct it let's continue typing or typing the contents of this data frame and notice that whenever we use quotation mark it will be a string as the data type and each list here each of this is called like a python list each list will be a single row okay let's have a look at the contents first so what we have just done was create the contents of this particular data frame and then you'll notice that the column names are the index number of the column location and you're gonna notice that we're gonna assign the unique column names in the next line of code let's do it so we're using the dot columns function on the df variable so that we could rename the index number 0 1 2 3 to the respective column label class label let's have a look at the contents again and now you see that the column name has been relabeled can label the column names using the dots column function and signing a corresponding list python list or its corresponding list a column name here we create a data frame let's have a look here mapping ordinal features right so let's create it create a new text cell and then we'll use like this for 0.3.2 make it bold mapping ordinal features so ordinal features will have a respective order meaning that large is bigger than medium extra large is bigger than large and mediums do that size mapping equals and then we're going to create a dictionary using the braces here xl and then we're going to use the colon which will be mapped to the number three and the second value here is l or large which will be mapped to two m we map to one so have a look at it size mapping okay so this is a dictionary and then we're going to apply it here df size before doing that what this will essentially do is it will select the size column which is here and you're going to see the contents which is m l x l and then we're going to apply the map function here in order to map the values from l to b2 from m to b1 from xl to b3 so let's do that first let's say map and then the contents of the size mapping variable which is the dictionary here and then mapping was performed but then what we want to do next is that we want to replace the contents of the columns here by the mapped values so we could do df size and then equal so that we will assign the new mapping values to the df size column which will overwrite the prior content so ml xl will be overwritten by one two three let's do it run it and then have a look at the contents of df again and you'll notice that the content has been replaced to be one two three from mlxl and now we're gonna work on the encoding class label so that will be 4.3.3 we'll make it bold for 3.3 encoding class labels i mentioned already it's nice to type in each line of code manually so that will help you to reinforce the contents here and we're going to create a variable called class mapping and then we're going to do this label idx which is essentially like this label colon and then the valley so we have the key of the dictionary and the value the key and the value for because we're going to do a for loop of this idx label in enumerate it could be like this or you could hit on enter as well to go to a new line because code is quite long and then np unique and then df and then class label and it's a good thing that jupiter notebook created automatically corresponding closing syntax and now we're going to have a look at class mapping and inverse i will look at the error df class labels oh okay i think i typed in this wrong should we class label all right and now it works so you see that class one corresponds or mapped to value of zero class two will be mapped to a value of one and then we could repurpose this code as mentioned here as well so we're going to change size to class label and change size to class label and it's going to be class mapping enter and now you're going to have the class label to be mapped to the values of one and zero okay and then the next part here it will show you how you could reverse from one zero one to become class two class one class two so you could do that by using this block of line of code here so let's annotate this a bit encoding class label so we're going to reverse the mapping of values back to their original categorical labels and create a inv or inverse class mapping with a dictionary value k or key k underscore v and class mapping dot items so yeah we could also use the same names here as well instead of v we could call it idx idx and instead of k we could call it label label to make this inverse work let's do this label and then we're going to replace it with the contents here class label dot map and then we're going to use the inverse class map and we're going to print out the contents of the data frame llc syntax error see what's misspelled the athlete try the network yeah oh okay i have to close the brace here there you go okay so i think and now i should work print out the contents of the data frame all right oh i have to do this again i might need to run this all over again because it was probably overwritten to run the code again from creating the data doing the mapping generating the class label and this should be 101 okay and let's do this all right and so we have reversed from 101 back to its original label right here okay and now it's going to do the same okay so here it shows how to use the label encoder to transform class 2 class 1 class 2 to the array of 1 0 1 without using mapping so instead of using mapping you could use the label encoder okay so you could try that out and i'll leave that out to you and here it's going to do some one hot encoding on the nominal features so nominal features will be green red blue so this one has no ordering so green red and blue will be quite same in terms of the important color not similar to how large is larger than medium or xl is larger than l and medium all right let's see how they do it all right and so let's continue we're going to do the one hot encoding so create a text variable x color size price dot values let's see what is in here all right so we have just created an array of the contents of the data frame of the first three columns color size price without the class label now let's do this create a transformer using the label encoder label encoder would that work so we first have to define it okay we skip that so let's copy that here does it work this would work and now we're going to type x we're going to select all contents of the rows only the first column only the first column column 0 green red blue just here green red blue so all row specified by the colon here zero is the column with the index number zero and now we're going to replace it with the transformed value fit transform and add in the content of first column and replacing it okay i think we have too many closing bracket or not oh okay i think let's put that here okay let's take that out okay it works now let's have a look at x okay we'll put x here and it looks one two zero one two three ten point one twenty five five fifty point three okay it looks the same so here we have just replaced green red blue two one two one two three okay so this is one way of doing it and then we have the one hot encoder way of doing it and then we have the column transformer way of doing it okay so i'll leave that up to you and we could also use get dummies to perform the one hot encoding so in one hot encoding essentially so instead of replacing the colors with the numbers of zero one two it will create a new column for it for example if the column here is called color it will create a new column called color green and if the color is green it will have a value of one like here and if it's any other color it will have a value of zero okay so i'll leave that up to you guys to perform and then let's jump over to the other parts all right so here it's going to read in the wine data and then it's going to do some training and test data splits all right and it's going to perform some scaling of the data and so the fun part that i want to highlight in this tutorial is doing the feature selection okay so we're going to use this wine data get the data go to here that should be the data okay and it downloaded the data so create a new heading here let's call it partition let's name it the same as the book okay we should use three hash symbols and then load into data in pandas and pd and then we're going to say df equals to pd read csv and then the function v and then we're going to have a look at the content all right and it saves here to be header none let's do that heather equals none we don't want the header all right and then there are labels here copy that and then we're going to reformat this let's see if it runs it's okay because we call it df yeah let's call it dfwind and then we're going to rename the columns all right oh okay let's see what happens maybe is this syntax let me add that up here let's do it again oh we've typed in the wrong data frame okay now it works so now the data frame has the columns relabeled and it looks like the one in the book and here is going to do the data split and so it's going to select the x and the y data so this part is the x this part is the y so let's do it so we could say load the wine data from the uc irvine machine learning repo re-label the column names and then we're going to perform the actual data splitting so we're going to use the function here but then we could do it like this which might be easy to read or we could put it on the same line as well let me show you both ways dot values x so we'll look at x so that is the value starting from so we're going to select all rows because we use the colon here so all rows will be used and then we're gonna select starting from column index number one so we're gonna skip the class label it is index number zero and then we're gonna go with index number one which is starting from the second column because we're going to get the data excluding the class label because the class label will be the y variable so for the x we're going to use from alcohol until the end here that is why we're using one colon so starting from first here to the last so this is the second column until the last and let's do y y is equal here right let's print it out here 1 1 2 2 3 which is the first column here one one two two two three and as i mentioned the example here includes both on the same line so you could do it like this as well x y and then we're going to print it separately let's have a look here x y okay so we put x first and then we print y okay and then let's continue with the actual data splitting so actually the actual will be the next step so here we're going to do the separate x and y from the f and we're going to use this to paste here which is where the actual data splitting is occurring and let's type it x train x test y train y test equals to train test splits x comma y test size equal to 0.3 random state is specified to be zero and then stratify is specified to be yes let's train x test y train y test okay so all of it is printed out here and strain x test and then we have y train and the y test arrays all right and so that concludes all of the contents for the data handling all right and so let's continue so here we're going to perform feature scaling so for consistency we're going to keep the name according to the one in the book chapter so we're going to import min map scaler so we're using the normalization approach where each value will be subtracted by the minimum value of the column divided by the range which is the maximum value of a column minus the minimum value of a column let's import it x train normalize mms fit transform x train x tests normalize mms transform x test so remember that we create a model using the fit transform on the training set and once the model is built we're going to apply the model mms dot transform and then using as input argument dx test data let's run it and let's print out the contents of the normalized data and you're going to notice that it will be in the range of 0 and 1. so we could actually display it in a data frame if you like we could say pd data frame and then x train norm dot describe let's see what happens here and then you're gonna see that all have a maximum value of one and all have a minimum value of zero so they will be normalized column wise okay according to this equation let's proceed further and another approach is to perform standardization using the standard scalar function so we're gonna skip this and let's go ahead and use the min max standard scaler so here we're going to perform min max normalization and then we're going to perform standardization so according to the equation here the standardization will perform by using the value minus the mean divided by the standard deviation for each column so therefore the resulting mean value will become zero and the resulting standard deviation will become one so let's run this copy it st dsc standard scalar extreme std equals its tdsc dot fit transform x strain x test std equals stdsc dot transform x test and so let's do the same let's have a look at the data frame x train std and i'm going to describe it so that i get the min and the max so you're going to see here [Music] that the mean will become essentially zero because 6.89 times 10 to the minus 15 would mean that there are several zeros like zero point and then fifteen zero six eight nine so it's essentially zero and the standard deviation is approximately one and that is the standardized value let's continue all right so here are the approaches for performing feature selection by selecting important features because when we build machine learning models we want to be able to extract the important features from the vast number of initial features to start with so i'm going to skip the logistic regression part here so you could go ahead and continue to implement this and take notes as well as in any other linear regression or multiple linear regression you're going to notice that there's the regression coefficient which is provided here in the coeff function and then the intercept of the y-axis is provided here and there are three values because this is a multi-class problem so there are classes one class two class three and so the intercept here corresponds to the classification of class one versus classes two and three the classification of class two versus one and three and also class three versus the other classes one and two and the same there's going to be three lists for the regression coefficient corresponding to each of the three classifications of the multi-class and then let's see okay there's the optimization of the c parameter and then looking at the coefficients so you see that the higher the value more dispersed value are observed all right so i want to show you this part the sequential feature selection algorithm so this is implemented by the authors and let me see if i could go to the github of the book first find the link so and chapter four and this they actually have the jupiter notebook okay let's replace it let's have a look at the notebook okay so you can see that all contents are already in here okay all right so let me copy this let's copy that and then we're gonna replace it here let's see if this works all right it worked so as a fail proof you could go to the github and copy paste the code like here you could just copy and paste it in let me delete this that was the data and we could just delete this and then we could say this is for this is the sequential what's it backward it's the sequential [Music] feature selection algorithm that the authors have implemented and then we're going to run the code so here we apply the sbs feature selection and let's run it all right and he got the plot here so you could also go ahead and try these other cold cells that will dive deeper into the feature selection aspect of this and so in a nutshell this plot will show you the accuracy on the y-axis and on the x-axis you're going to see the various number of features that are used for the model building so it will sequentially take away a feature and then build the model and see how much accuracy the model produces so we can see here that beyond three the model did not improve of course because the accuracy was already at a hundred percent and so three features seem to be optimal for building a robust model here even at 2 you could see a very good accuracy score here and so accuracy is only one way of evaluating the model and there are others like the matthews correlation coefficients and so you could play around with this code you could modify this to other metrics as well but then the score here was using or computed via the calculate score function so let's continue let's have a look here assessing feature importance with random forest let's create it here let's move it down one two three bold assessing feature importance with random forest okay so just go ahead and copy the code so actually we could break down the code into chunks that are comprehendable you could say that we're going to build a random forest model we could just make it bold feature labels can go here because it's not yet used there just because it's used here in the for loop and we're using matplotlib to make the plot right here okay so i guess we have to run this first okay we have trained model and then we're gonna make the plot and so before making the plot we printed out the values so these are the ordered values from highest to lowest here from highest to lowest so the important features are from the left side to the right side so the higher the magnitude the more important feature is to the model and so this one will select the top five so we could go ahead and copy this select the top five features and it's using the select from model and it's gonna select top five from the forest model which was built previously and we're iterating through to print out the top five features here and as can also be seen here they are the top five bars from proline to alcohol from proline to alcohol so you could feel free to use these top five features in a second round of model building meaning that in the second round you would build another set of machine learning models using the top features selected from the initial first model built using random forest so these top five features could then be used by the second model to build the second machine learning model so this concludes chapter four and all of the contents in the book are quite easy to follow and you could just skim through the explanation if you choose to understand what they are about or you could just skim through the book and jump around implement the code and then learn from the error as you type or mistype the code and try to see how to correct the error as i have already shown you sometimes we haven't run a prior cell and it gives us an error output and therefore we have to run it first or maybe we might be misspelling some variable names and it could not detect it because it doesn't exist and so all of this nuances will allow you to become familiar with the various code and syntaxes as well as the errors that might occur and so even if you encounter errors that is a great thing because if you are able to overcome it then it means that the next time around it won't be a challenge for you and the next time around would be a lot easier and so this chapter covers about feature selection and also data handling and there are a total of 19 chapters as i have already mentioned and you could feel free to skim through chapters that you are already familiar with and just go to the topics that interest you and even better is that if you have a data set of your choice let me show you let's say that i go to github dot com slash data professor and i'm going to go to the data so i'm going to show you how we could just repurpose this for another data set so we have the here the delani solubility let me click here okay so they are the solubility data sets for molecules so there are a total of four input features and the corresponds to the molecular properties of molecules and the goal is to perform regression to predict the log s value or the solubility value so why don't i just copy the data link here and then we could just go to the top here find the wine data set and we could just replace the link with our corresponding data so let me just create another section i'll call it solubility data set so let me go up i think it might be better that i just create another notebook and then i'll open it side by side or like that okay and i just paste the respective components there okay so i'll call it as the solubility data set so we're going to typically start by loading in the data set so we're going to import pandas as pd let me find the respective code cell okay right here it's right here and then i could just call it df equals to pd read csv and then the link to the data the f so that i know the contents of the data and the data already comes with the name of the columns because we have it on the first row right here right here and so they are presented here let's see so we don't have to relabel the column names and now we're going to separate the x and the y from the df here so we could just copy this we paste it here and then we will do some modifications so the name of the data frame here is df so i'm going to modify that to df this one to df okay and where is our x values and our y values so our y value will be the last column right here and our x value will be the first column until the column next to the last so in order to make sure that we're selecting the columns properly i like to do this i just copy this this was from the prior example so we want to start from the first column so we just you know delete the numbers and we want to have as the x variable mole log p mole weight non-rotatable bonds and aromatic proportion so let's see if this works right here first four columns so that works so minus one would mean the last column so this is implying that we already have zero to the left so it's going to give you the same result so we want from column with index number of zero until the last column which is minus one which we are not selecting minus one will be the log s column so we're not selecting that so we could just delete zero here it's the same thing and then i'll replace it here and then we're gonna select the last column it should be minus one so let me show you this should be minus one because it is the last column the log s right here log s so let me delete that this is correct so i'm going to change this to minus one and then we have it here so we can have x y and then we're going to create the x and y run it so here we could say [Music] load data let me delete this this is three okay how about we do like this one two three data processing let's call it data pre-processing so here we're going to separate x and y from df or we could just bold it as well and then we're going to perform the data split data split splits fold and then we're gonna copy this paste it here make sure x and y test size we can modify it to 0.2 stratify we don't need to stratify by y because it is the regression so we're going to delete this line right in a state of zero okay let's check to see that data exists okay it exists we could just scroll down a bit okay now for feature scaling we could just say feature scaling [Music] say that we're not going to do normalization but we're just going to do standardization we're just going to copy the code here and we're going to say we're going to scale the features via standardization let's run it let's make sure that they are scaled properly so the mean should be zero and the standard deviation should be one which is correct and now let's do the sequential feature selection so we're gonna make it to three hash symbol we're gonna copy the code here creating the sps feature selection algorithm and we could develop by the authors of or we could just say developed by last name or surname of the first author at l and the book is just recently published so it is 2022 20 22 and then we run the code here and then we're gonna run it here as well so we will apply the sps feature selection and then let's see oh okay is a continuous type okay because before it was a for the accuracy which is the classification so i guess we'll have to modify the above code here but then this is outside the scope of this particular tutorial so i'll leave that as a challenge for those of you who are interested in modifying this code to work for a regression problem let's continue further and let's see this is the random forest so we're going to see build a random force model fit the data extreme y train okay so we have to change this to regressor this is regressor and let's copy this okay and then we have to modify this to be the f feature labels should be like that let's see if that's correct everything except the last column okay that's correct let's see if it works all right it works for this particular model and that was all because we only have four features we will skip this and we will just delete this so you can see here that we've just repurposed the codes mentioned in this particular book into our very own jupiter notebook on another data set which is the solubility data set and so you can feel free to do the same with another data set of your choice other than the solubility data and so links to the machine learning with pytorch and scikit-learn book will be provided in the video description and let me know in the comments which data set are you repurposing the code for in your own data science project and so i love to read them all and see how each and every one of you are adapting the contents and code of the book for your own project thank you for watching until the end of the video if you reached this far please drop a balloon emoji in your comments so that i know who you are and you can support the channel by subscribing to the channel smashing the like button and also hitting on notifications so that you'll be notified of the next video and as always the best way to learn data science is to do data science and please enjoy the journey
Original Description
In this video, you will learn how to build a machine learning model from scratch in Python. Particularly, we will be extracting code examples from Chapter 4 of the Machine Learning with PyTorch and Scikit-Learn book for a step-by-step walkthrough.
📝 Code https://github.com/dataprofessor/machine-learning-model-from-scratch
📖 Get the Book https://amzn.to/35T1tnD
📝 Book GitHub repo https://github.com/rasbt/machine-learning-book/tree/main/ch04
- Join Packt Discord https://discord.gg/39u9HzcA
Support my work:
👪 Join as Channel Member:
https://www.youtube.com/channel/UCV8e2g4IWQqK71bbzGDEI4Q/join
✉️ Newsletter http://newsletter.dataprofessor.org
📖 Join Medium to Read my Blogs https://data-professor.medium.com/membership
☕ Buy me a coffee https://www.buymeacoffee.com/dataprofessor
Recommended Resources
📚 Books https://kit.co/dataprofessor
😎 Taro (Tech Career Mentorship) https://www.jointaro.com/r/dataprofessor/
📜 Google Data Analytics Professional Certificate https://imp.i384100.net/google-data-analytics
🤔 Interview Query https://www.interviewquery.com/?ref=dataprofessor
🖥️ Stock photos, graphics and videos used on this channel https://1.envato.market/c/2346717/628379/4662
Subscribe:
🌟 Coding Professor https://www.youtube.com/channel/UCJzlfIoF8nmWqJIv_iWQVRw?sub_confirmation=1
🌟 Data Professor https://www.youtube.com/dataprofessor?sub_confirmation=1
Disclaimer:
Recommended books and tools are affiliate links that gives me a portion of sales at no cost to you, which will contribute to the improvement of this channel's contents.
#datascience #machinelearning #dataprofessor
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Data Professor · Data Professor · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
How a Biologist became a Data Scientist
Data Professor
WEKA Tutorial #1.1 - How to Build a Data Mining Model from Scratch
Data Professor
WEKA Tutorial #1.2 - How to Build a Data Mining Model from Scratch
Data Professor
WEKA Tutorial #1.3 - How to Build a Data Mining Model from Scratch
Data Professor
Computational Drug Discovery: Machine Learning for Making Sense of Big Data in Drug Discovery
Data Professor
Quotes #1 on Big Data and Data Science
Data Professor
Quotes #2 on Big Data and Data Science
Data Professor
Quotes #3 on Big Data and Data Science
Data Professor
Quotes #4 on Big Data and Data Science
Data Professor
Quotes #5 on Big Data and Data Science
Data Professor
Data Science 101: Starting a Data Science / Data Mining Project
Data Professor
Data Science 101: CRISP-DM - Data Mining / Data Science in 6 Steps
Data Professor
R Programming 101: How to Define Variables
Data Professor
R Programming 101: Read and Write CSV files
Data Professor
Data Science 101: Basic Command-Line for Data Science
Data Professor
Strategies for Learning Data Science in 2020 (Data Science 101)
Data Professor
Building your Data Science Portfolio with GitHub (Data Science 101)
Data Professor
R Programming 101: Setting up R programming environment (R, RStudio and RStudio.cloud)
Data Professor
Exploratory Data Analysis in R: Towards Data Understanding
Data Professor
Exploratory Data Analysis in R: Quick Dive into Data Visualization
Data Professor
Machine Learning in R: Building a Classification Model
Data Professor
Machine Learning in R: Repurpose Machine Learning Code for New Data
Data Professor
Data Science 101: Deploying your Machine Learning Model
Data Professor
Machine Learning in R: Deploy Machine Learning Model using RDS
Data Professor
Data Pre-processing in R: Handling Missing Data
Data Professor
Machine Learning in R: Speed up Model Building with Parallel Computing
Data Professor
Data Science 101: Overview of Machine Learning Model Building Process
Data Professor
Web Apps in R: Building your First Web Application in R | Shiny Tutorial Ep 1
Data Professor
Web Apps in R: Build Interactive Histogram Web Application in R | Shiny Tutorial Ep 2
Data Professor
Web Apps in R: Building Data-Driven Web Application in R | Shiny Tutorial Ep 3
Data Professor
Web Apps in R: Building the Machine Learning Web Application in R | Shiny Tutorial Ep 4
Data Professor
Web Apps in R: Build BMI Calculator web application in R for health monitoring | Shiny Tutorial Ep 5
Data Professor
Machine Learning in R: Building a Linear Regression Model
Data Professor
What programming language to learn for Data Science? R versus Python
Data Professor
How to Become a Data Scientist (Learning Path and Skill Sets Needed)
Data Professor
Using Python in R
Data Professor
Interpretable Machine Learning Models
Data Professor
Making Scatter Plots in R [Data Visualisation in R series]
Data Professor
Machine Learning in Python: Building a Classification Model
Data Professor
Compare Machine Learning Classifiers in Python
Data Professor
Hyperparameter Tuning of Machine Learning Model in Python
Data Professor
Practical Introduction to Google Colab for Data Science
Data Professor
File Handling in Google Colab for Data Science
Data Professor
Pandas for Data Science: Create and Combine DataFrames / Rename Columns
Data Professor
Machine Learning in Python: Building a Linear Regression Model
Data Professor
Machine Learning in Python: Principal Component Analysis (PCA) for Handling High-Dimensional Data
Data Professor
How to Plot an ROC Curve in Python | Machine Learning in Python
Data Professor
Installing conda on Google Colab for Data Science
Data Professor
Use native R on Google Colab for Data Science
Data Professor
How to Save and Download files from Google Colab
Data Professor
Easy Web Scraping in Python using Pandas for Data Science
Data Professor
Data Science for Computational Drug Discovery using Python (Part 1)
Data Professor
Pandas Profiling for Data Science (Quick and Easy Exploratory Data Analysis)
Data Professor
Exploratory Data Analysis in Python using pandas
Data Professor
Quick tour of PyCaret (a low-code machine learning library in Python)
Data Professor
How to Upload Files to Google Colab
Data Professor
How to Install and Use Pandas Profiling on Google Colab
Data Professor
How to Adjust the Style of Pandas DataFrame
Data Professor
How to use Bamboolib for Data Wrangling in Data Science
Data Professor
How to use Pandas Profiling on Kaggle
Data Professor
More on: ML Maths Basics
View skill →Related Reads
📰
📰
📰
📰
Causal Inference in Finance: Moving Beyond “What Happened?” to “What Actually Worked?”
Medium · Data Science
Database Deep Dive Series
Dev.to · Namrata Khorjuwekar
Éclat de l’Avenir Gestion S.A.R.L renforce la clarté des analyses grâce aux rapports intelligents
Dev.to AI
Data Analytics (AI/ML) ROI 101 series: Article 3: Accounting fundamentals for data analytics…
Medium · AI
🎓
Tutor Explanation
DeepCamp AI