 Have you ever wondered what to do once you've worked meticulously on a machine learning model And you want someone else to be able just to use it while you can pickle that model Let me show you how it's done. First of all, I'm just going to run my Cascaling style sheet to run and create my model I'm just going to use the random forest regressive from model from the ensemble library and scikit-learn and then just the ROC Area under the curve score there my receiver operating characteristic area under the curve score there more importantly though the pickle Import pickle. Let's just run through this model This is not a video about how to create a random forest regressor model But let's have a quick look. It's the second sheet here Which means sheet name equals one of my Microsoft Excel spreadsheet here and if we run that The first five rows of this data frame. We see four numerical variables three categorical variables and my outcome here So I have these seven predictor variables here and one outcome variable I'm going to pop pop off That outcome variable as a vector. It is now gone from my data frame and it lives inside of this computer variable Y Just to make sure there's my data types my seven predictor variables They now three of them are categorical This is a little function that will just extract all the categorical variables from a data frame and just describe them So it found category one, category two, category three as categorical variables 700 rows in each of them we see three unique values two and four unique values and the mode there with a frequency Now I've got to demify this if I want to create a random forest regressor model So I'm going to take category one, category two, category three. I'm going to do a little for loop through all of those I'm going to full NA with missing and I'm going to create this these set of dummy variables and in the end delete these three Columns, so if I look at the result of that, this is what we have perfect ready for use inside of a random forest regressor Model so see the four numerical variables and then this numeric representation through dummy variables So there's a one under cat one a so this would have been an a it would have been a Roman numeral two for cat Two and it would have been an R for cat three. There we go Already to go. Let's run our model There we go. I use random forest regressor Pass all my arguments. I fit my data my outcome variable to the model and we see an area under the curve there of 0.8977 now imagine for a while. I've worked meticulously on this model I've really worked hard on it and this is the best can be and I want to send it to someone else so that they Can just import the data and use the model and this is how we're going to do it We're going to simply pickle our model So I'm going to open a file Now you can see my file name dot PKL the WB argument is for write binary so it's open for writing in binary format and Now I'm just going to use the dump function pickle dot dump pass two arguments the model that we've just created after meticulous hard work and Then the file this reference to the computer variable to the file that is open to be written to in binary format. There we go and We should run this first there we go There we go. It is run and then lastly. We really just want to close that file. Remember always to close that file So we save I'm going to file close here if I go here. We can see that the Pickled file lives here now in the same folder now a colleague or co-worker or someone else wants to use That model that I've worked so hard on. Let's see how they're going to do that import pickle there now what they're going to do is to read the pickle file create this Reference this computer variable that references this file opening of this file I should say in read binary mode. There we go. They create a computer variable called Model which is what I've used there and pickle dot load. So they're going to load the model from this file There we go. And just to show you there's the model So now we're here that we import scikit-learn create the model anything It is the model that was pickled from before just to be sure we can see there there were 13 features The feature importances more importantly now. There's a new in this instance I'm supposed that this is data from a patient, but I'm going to pass values for these 13 Feature variables here predictor variables and we're just going to see what our model predicts. This was a regressor model So there was an 8% chance that this patient would be have a one outcome or successful outcome Remember outcomes are coded as zero and one for the regressor Model so a beautiful way just to save your model in for others to start using the model that you've worked so hard on