Low-Code Insurance Prediction with PyCaret and Streamlit
Key Takeaways
The video demonstrates how to use PyCaret for low-code machine learning and Streamlit for building a web application to predict insurance charges. It covers training a regression model, fine-tuning the model, and deploying it in a Streamlit application.
Full Transcript
hello everyone welcome to AI anytime channel in today's video we are going to build an extremely application you know for predicting the influence charges so we will utilize a low code machine learning library called Pi carrot you can see I am on the 5 carat documentation website so you can find it here it says an open source low core machine learning library in Python 5 carat has been ah very famous lately because they kind of provide you these low code functionalities they have several classes that they have created and you just use those classes to train or train a machine learning model okay and it works uh out of the box it supports cloud services as well like AWS for example so we are going to use this library today Pi carrot will will also use the data we'll load the data using pi carrot get data function and then then we create a regression model to predict the insurance charges okay and then we'll train the model we'll save that model and then we'll use that model in an instrument application to predict the insurance charges so you can see this is the documentation that they have installation okay if it's little difficult uh to install Pi carrot on Windows okay and sometimes on Linux machines as well because uh till now the pi carat was not updated or upgraded to you know install in Python 3.10 plus versions okay they have recently lost 5 carat 3.0 and now we will we will use this in this video today so let's see I am on my Google collab I'll use collab to you know use this Pi carat library to train the model and then we'll create the stimulate application once we have that model ready okay so let's first install it so fifth install and you have to give this free okay still haven't fully released that I think we're still testing it out you can see it says 5 carat 3.0 RC is now available pip install hyphen iPhone 3 python to try it so let's try that so free I get it it will install it will take real time to install uh this particular library that we have and once we install it we will you know use the gate data function in pi period they have a lot of data available you know you can just load it using the uh functions and you know you can train the model you do not have to load it from outside if you do not have any data available once it is installed we have to restart the runtime we'll get some warnings when the installation is complete so let me meanwhile import the other libraries so we'll need pandas to load the data data frame we also need numpy so input numpy as NP and excuse me and then we need matric.ly so matplotlib dot I plot as PLT we also need let's also do one thing import methodly Mac plot excuse me my plot leap as MPL and then what we need we also need c bone so import C bone as SNS will try to create some kind of data visualization to find out the correlation between the uh the features that will have import Co C bone as SNS now what we can do we can let's first restart the runtime so I have to restart the runtime you can see it's restarting here meanwhile let me just import from PI carrot dot data sets import get data import get data excuse me and then we also need the regression so what I'm going to do I'm going to do 5 carat dot regression and I will import all the modules inside that regression uh class that we have so regression import just do this asterisk okay so the star that we have so what this will do this will basically will import every function that we have inside this regression class okay like you know load model or train or setup all that we need you know we will talk about it once we are you know uh initializing the pi carat environment okay so from PI carrot dot regression Imports so today we are going to you know use the regression model okay but Pi carrot has the capability you know to work with other kind of data and other tasks that we perform like classifications time series forecasting anomalies detection they also provide uh text classification sentiment analytics you know you can go through you can go to their documentation and you can find out all their examples if you come to examples you'll see they have classification tasks they have regression tasks you know based on your text similarities they have text Data as well they have numerical imbalance data they have diabetes data of this P minor data set and they also have other kind of data that you know you can just go and try it out it helps you you know build models faster okay and they have a lot of functions where you can fine tune your model you can evaluate and you can also directly Deploy on cloud services like AWS they also provide this out of the box okay so from PI care dot regression import Asterix and all I'm going to do I'm just going to set uh some parameter here just to get the visualizations so RC params DPI figure or DPI 300 okay so the import has been successful now what we are going to do let's load the data so I'm going to say data equals get data and here I will just pass this string which is insulin so I just need this data so you can see we once we have loaded the data successfully using get data you can find out there are around uh six features and one target charges is our Target column okay it's a it's a health insurance data okay so basically they have some charges based on these features like what the age and sex BMI children smoker okay and the region as well okay Southwest North West and all those regions that we will try to see okay so let's first see data.info to get basic details about the data to find out categorical or missing values and numerical columns you can see we have total of seven columns and there is no null null values available data is complete and you can see we have three categorical column object object of the smoker region and sex BMI is a numerical value okay it's a basal metabolic index and kind of where we try to correlate with obesity and other disorders or parameters that we have right that's how we ah uh find out that approximate value okay so BMI is like based on the uh age and Heights and weight and all those things so we have the six which is of course an object now let's do one thing let's first find out what is the uh how many classes are there in region how many categories sorry how many categories are there in the region so what I'm going to do later region dot Valley count so you can see we have four uh categories in region which is the south east south west north west north east quite balanced they have around very balanced uh among each other we have around 320 plus values the rows for all these four classes okay then we have BMI then we have you know children and children is again a end okay uh smoker yes or no let's see if about smoker as well we have smoker Dot value counts so we have two okay you can see uh only 274 uh people among like among all this uh we have 13 000 right uh here rows okay so we have around 274 people who kind of are smoker okay and what I feel is the charges will be more for them we will try to find out the feature importance with the help of Pi carrot we'd also like to see once we train the model what are the what are all the features that impacts them impacts the model okay then we'll see so now what we can do okay how we have this data now we have to first this is our Target column which is charges we have to predict these values based on this features that column that we have okay so now let's do one thing let's first visualize this so what I'm going to do now I'm going to call it let's call it numeric let's first try to visualize and find out the correlations uh between the data that we have so age VMI and charges smoker go to sns. we'll do a pair plot SNS dot pair plot data and here I what I'm going to do now I'm going to pass numeric the column that I have set above numeric and that you will be all smoking so we'll do a few mapping on smoking that's it so it won't be smoking it will be smoker because our column name is smoker smoke and then we'll just do the plot so PLT dot so we just highlight the differences between you know smokers and non-smokers here because you can also see rice age is correlated with charges you can see it over here we have age and we have charges and people get higher charges you know as they grow older that's how the insurance premiums have also been calculated right and also smoking is a a big impact here okay so if you are a smoker despite of your age you know the charges will be more if you see this right so now what you're going to do we're going to initially initialize the piperate environment okay so in a slice the 5 carat environment and we're going to first set up the pi period where we have to like we use cyclic learn to basically uh do the train test pleat we kind of create this extra and Y train and X test white similarly we will also have a set of option here so what I'm going to do I'm going to have a variable and call it setup and this setup is coming from this this module that we have imported if you see this python regression import asterisk this is what we are doing so we are using one of the function of that class setup and here we will set up our model environment okay that we are going to train so first thing is data so our data is nothing but the data that we have the data variable you see this data that we have where we have the data frame right we have loaded that's the insurance data so data equals to data now the next is Target our Target is nothing but the charges we have this charges as a Target and then we have excuse me then we have train uh then we have train size so let's keep it let's keep it 0.8 that's Target at train size we have 80 and 20 percent as strain and test train size and then we'll have couple of things we can also have a session ID by default also if you don't give any session ID or you can also give yourself an ID section ID so I don't want this system to be launched I am giving a session ID here and then what we can do we can have normalize equal to True okay so we are trying to you know do this pre-processing on top of that data where we want the data to be normalized okay normalize equal to true there are different way of you know normalizing data I think Pi carat u g score will calculate by that way we will see once we are getting the output of it you have min max scalar you have a lot of other things that way you can you know normalize your data for regression task okay so here we are going to train a regression model okay we have to calculate we have to predict a numeric value right so uh we use the regression model will see which model is giving us the best result with the help of compare models that we have in pi carat so here we have data equals to data and we have Target equal to charges and train size equal to 0.8 you have a session ID normalized now let's do one thing let's run this once you run this you will get a set of you know description and value you see we have description and we have value the first is the session ID it kind of provides you this web curve we're running in the runtime environment it provides your session ID we have Target column okay which is charges in this case we have the target type of course regression there are other types also in pi carrot we have classification we have categorical values to predict or you know classify we have we have anomalies we have forecasting so this is Target type is integration in this case we have original data Save which is around 1300 rows right and seven columns that we had and the transform data set another data has been transformed right train and test if you see 80 percent are being you know allocated to train and 20 percent of them are allocated to test that we will test the model right we will evaluate okay then we have numeric features categorical features right two and three and then we have we have done the preprocess which is equal to true we have normalized equal to true so you can all read all this and you can tweak this also if you want to turn it on G P we have to provide this as a parameter GPU equal to true it will use your GPU machine right if you have Cuda or something something installed there okay so use GP equal to false now what we are going to do guys we are going to not uh train this model okay so how do we train the model so first we have to uh find out the best model for us so we have to compare with several other models okay integration model so what I'm going to do now I'm going to do base equal to compare model so it's it's a function inside it's you can compare models it's a function in compare models what I'm going to do I'm going you can sort it so we have a sort parameter you can see over here sort I am going to sort this equal sort equal to rmsc okay this is how I'm going to sort okay so we're going to use rmse here okay let me add an evaluation metric so let's run this first and then we're gonna you can see it's initiated it's also have uh status there which is fitting 10 folds estimator lasso regression now you can you may ask a question that you know why are we going for rnse let me just show you that okay so you can see it's kind of uh uh basically trained model okay first will and then we'll compare it so you can see linear regression lasso regression these different type of regression model then we have elastic net coming in then we'll have uh gradient boost and also this model will be first evaluated among the cells with pi carat compare model function and then use choose uh among these models so if you want to go ahead with you know linear regression or you want to go ahead with you know uh Huber regression or any other model you have to then create the model okay then we'll create model it we pass this model that we have here acronyms ra for Ada or k n and then we train the model with help of some if you want to do force and all we can do that also so here we are sorting it with rmse root mean square error and you can see we have got this gradient boosting regression on top gbr which gives you a rmsc score of around 4700 or something right with the lowest rnse among all other models now it's also giving you some turnaround time that how much time it took you know to train it and then evaluation they said a lot of other evaluation like we have R square we have absolute error we have squared error and all okay let me just tell you that what we mean by rmsc right so you can see imsc is nothing but it's the it's the we have an uh actual value and we have the predicted value right the square root of the average of squared okay so we have this let me just excuse me let me make it little bigger Okay so what I'm going to do now yes so we have here summation and then we have n and then we have I equals to 1. so this is basically your actual value that we have this is your actual value this is your actual value and then this is your predicted value that we have so actual value and predicted values so this is basically the square root square root of the average of squared l this is what rmsc is so we have this actual values and printed values and then we have the squared root you can see the squared root of the average of the squared error this is what rmse is and lower rmsc value means it's better okay for regression okay so you can see that this is what we are doing it over here so if you see we have this gradient boosting regression as rmse of you know 14 700 right and now what we are going to do guys okay and you can evaluate some other metrics as well that we can also evaluate it later also now what I am going to do now I know that okay I have to choose this gradient boosting regression I will just say okay now models equals create model okay I'll just create the model so under the create model equals to create model and I'm going to use this HTM as you can see estimator estimator are nothing but the string which is this we have this acronyms here it's what I'm going to do I'm going to use this gbr which is the string and my fold will be nothing but the painful so I want to create the model and then evaluate it on the 10 fold because you can see fold you can see the documentation of this function which says fold int right so I'm going to roll on the 10 fold and let's now create the model for gradient boosting regression on this data that we have right so you can see the initiate initiated we have a status which is fitting 10 folds and now we have got the result so you can see around 40 of 700 uh of this rmsc which is the mean of this entire that we have received here uh from that now what I'm going to do now let's do one thing so you can also fine tune it if you are not satisfied with the model where you can fine tune this model okay so how do we find it before fine tuning it now let's evaluate this model so I'm gonna do evaluate so evaluate again a model is again a function there so I will use evaluate model and we'll give this model name which is model so you can see first we are getting the pipeline so we have we have the raw data then we have the imputer like we have this computer you can see then we have encoding we are doing it one hot encoding if your categorical classes and then we are getting this gradient boosting regression right so this is one hot encoder for uh tackling the categorical columns then we have a standard scalar and then we have gradient boosting so this is the pipeline the model pipeline that we have we have received the plot we have different you know of how could I put it we have different parameters now that in when we train a model that's called hyper parameter we are not doing it right now we will also find we'll try to fine tune this model with based on some parameters after this but what will I'm more interested in this feature importance okay this is very important so you can see we have this feature in our column right and you can see the most important feature in this entire data set is smoker okay and this is how it works also in real time so if you are smoking the tendency is more the charges will be more right so you can see smoker is the most important feature then we have air also and age and uh smoker was like also age and charges are also correlated okay because when you grow older the charges are more so you can see smoker BMI is very important to you know do this feature importance plot okay to find out what are the important feature and how your features are impacting your model right this is one way now let's do one thing you can also look at this you know a prediction error to find out how best fit the lines are you can see it's we have R square which is around zero point you know eight eight and we have the significantly closer than the identity line okay now let's do one thing what we can do also we can also do brick model so we have this brick model function now let's pass this model so you can see it's also predicting the model okay so we have this column like features H6 BMI children's smoker region and charges and these are all the prediction label and these were the actual level so remember we have this if you go back to this uh here the you have this actual value so your actual value is this in case eight six two point you know eight six two seven and the prediction label is this 9.9198 this prediction level that we have and we are getting this if you do the square root of this average of the square error we will get the rmse for this particular you know this uh prediction that we have so this is the prediction label by R model so if you see in this case is very close right we have four three nine two one as charges and we have forty three thousand nine hundred twenty one you know as prediction labeled very close so this is a prick model that we have done our work and what we can also do we can also fine tune this model so how to how do we find it in this model or let me write it here so fine tuning this I this is a gradient boosting regression we have to select the parameters accordingly different regression models have different parameters that you can tune it so fine tuning this fine tuning model so let's first create a params parameters and then we'll have you know dictionary there you know and then here we can Define few of the things let me just do one thing so first thing is the learning rate okay how fast or how slow you want to train your model you will say that hey we'll have to say the five carat class or the function that this is my learning rate so the first is learning rate and I'll have some learning rate which will be a list let's call it you know 0.01 0.0.02 and then we have 0.05 okay these are my learning rate you can also change it you can tweak these values learning rate and then we have max depth so maximum depth we have around let's keep it to you know one two kind of eight two one two three four five six seven eight here I think it will be a comma okay we are in dictionary so maximum depth and now what next we have something called sub sample so sub sample which is again a list 0.4 to zero point let's give some some samples breaking down that you know we have this feature right the values the rows so 0.4 to 0.6 and 0.7 0.8 excuse me and some sample later now what we have is number of estimators is very important a parameter when you are fine tuning a regression model in number of estimators and then what we can do 500 600 let's keep it till 600 okay so these are my parameters now what I will do I'll use the custom grid okay parameter that we have inside uh the tune function okay so you see this parameter learning rate 0.01 to that and Max step and sub sample and number of students I want to fine tune the model on these parameters okay so let me first run this thing and now I'll use the fine tune uh function so what I'm going to do I'm going to call it tuned model the new variable tune model and then here I'm going to do the tune model so tune model which is a function and here I will write the function of parameters we'll use you can see we have fold we have you know a custom scorer we have custom grid and in this custom grid we'll pass our params variable that we have created above then we have again the optimized so we have to optimize with rmsc not with you know R2 here you can see it's a given as a reference you can also optimize on that so tune model the first thing is the model so you have to craft the model so this is the model that we have earlier right if you see model equal to create model so we have our model pipeline in that model variable so we are giving this model and once we have that model we'll say the optimize let's do this optimize so you want to optimize the rmac score you would like to see if we are getting any Improvement there so optimize and then we have fold again the 10 Folds so model optimize rmsc fold and then we have custom grid and this is where we are passing our you know variable that we have created above all our parameters that we have to tune on okay this learning rate Max their sub sample and number of estimators okay so balance and then now this this is very important so number of iterations you know you want to do okay and that will be suppose if you are giving number uh so it will be number of iteration now suppose if I give 10 iteration okay what this will do this will uh multiply with this fold and this will so what will happen 10 cross then it will be 100 times and now it depends on your computational power if you have very limited computational power you can reduce the number but in this case I will just keep it at around you know 20 as number of iteration so we have model we have optimizing on rmsc score we have 10 fold so fold equal to 10 and then we have custom grid patterns and the number of iteration equal 20. now what we like to do we like to find out if iterating it for 200 times will be going to multiply with force and if my rmsc score is improving or not this is the plan so let's run this so it will take really time you can see it says fitting 10 folds for each of 20 candidates okay and so totaling 200 feet it will it will be total of 200 fits it might take you know up to a minute depending on where we are running it on our CPU on that to one call app do not have much computational power but it takes up to minute so let it let it complete so guys what we what we can do also we can you can also find out this uh on insurance charges prediction stimulate application uh the notebook and the instrument application that we are going to also you know develop shortly you can get all the code on this GitHub repository okay on the AI anytime GitHub repository you can get this insurance charges prediction estimate application so you can see it's still doing it it takes up to a minute I mean more than a minute also so after this let me write the code Okay so save the model so we also save the model after this so we have to create a final model and then to have to save it okay as an insurance model and then we'll you will use that model uh in an HTML application so let me just give you a walk through what we did in this video so we installed it with a hyphen hyphen 3 pipe that is very important if you want to you know use this model on Windows or you know on Ubuntu on the newest python version like 3.10 or more you have to you install this version of Pi carrot which is 3.0 so we have installed this and now we have imported uh the libraries we have uh loaded the data insurance from get data function and we did some kind of pre we also find try to find out some correlations we uh we also did some pre-processing you can see we have created this by current environment where we have the data Target column and the train size and the little bit of pre-processing then we compared several models to on the rmsc code then we created the model gvr and then we have evaluate model and then model and predicted model here right so if you can see it's still running stakehold time meanwhile let me write the code for saving the model okay that you know how we save the model so let's call it a variable called final model now suppose if the model that I have is the final model okay so how I'm going to do I'm going to use the finalize model function so finalize model so you can see in the writing finalized model so finalize model and here I will pass that model uh variable that I have this is the my final model and I like to save it so save model and same model as a functions then let's use this final model variable and just give it a name I'll call it insurance underscore model do not have to give the extension here like we when we use pickle or you know job lead we kind of use the pkl or pkt or this a job leap extensions to save the model Pi carrot does it for you okay so you do not have to use that extension here so you can see incidence models and just let me taking a little time save the model and then what we'll do so guys you know you can also uh this link will also be given in description the pi carrot documentation very powerful Library you know to it's it helps you quickly build and you know evaluate at the you know in beginning to find out which model will make more sense on your data that we have right if you see it's done and we have got a better rmse score if you see 4600 earlier it was if you see this it was around 4700 so we it has decreased now if you if you also tweak little further if you increase the number of iteration to around 50 or 100 and you can also uh tweak with these parameters that we have for this gradient boosting regression model you see this we have learning rate you can tweak the learning rate or number of estimators you might get a better result Okay so what are we going to do let's go ahead with the same model now you can also save this model and create this fine tuning model you can you can also save this fine tune model but I'm just going to use uh the model that we have created on top because the accuracy has not been increased you know drastically or something that okay we have to use the fine tune model we can go ahead with the first model that we train let's save it you can see it says transfer or transformation Pipeline and model successfully saved so again it's just a pipeline you might have used the Cyclone pipeline to you know create the pipeline and train the model so it's also kind of does the same we have Pipeline and you can read out all the steps that inside that pipeline so it has done some inputers right because it has to handle category current ordinal columns that we have and then we did perform the one hot encoding and some normalization and then use the gradient boosting regression model you can see over here right now if I refresh this I'll get a influence model.pk as I told you that you do not have to give the extension uh I credit kind of does it itself so let me just download this so I will download this in my desktop I have a folder called instruments stimulate app that we are going to you know build the app there so now let's do one thing let's take this model and try to you know build a simple streamlit application where end user will you know uh input all these features that we have and we'll then our model will try to predict it other insurance charges okay so let's go back to my desktop I have a folder called insulin streamlined app let me open in terminal let me open vs code so meanwhile I'm opening in vs code what I will do uh first activate my virtual environment so I have a venv virtual environment where I have installed these libraries like stream lead and uh then we have Pi carrot so CDV EnV Y and then we'll go inside bin folder so CD pin and then I will do Source activate to activate that virtual environment you can see I am inside that virtual environment in the right hand side we have to do couple of CD dot dot to go to the main directory so CD dot dot Let Me Now go to vs code let's say this is my folder and I'm going back to my vs code and here you can see that we have requirements so in requirement I have extremely and make sure guys you are installing this version of Pi carat if you want to use this if you want to you know use it you are using it in a Windows or Linux machine and if your python version is more than 3.8 okay or 3.9 you have to use this version of Pi carat okay now let's do one thing let's create an app.pi so I'll just create an app.pi here as you can see I'm creating an app.pi and now here we will start writing our code okay the app that uh that streamlit code so the first thing is we have to do the import so let's import it so I'm going to do import ant SPD because we need to uh convert those input dictionary to data frame and we have to pass it as a data frame right so import Panda that PD and then we have ish import stream lead as St we are importing the assembly and then what we have to do excuse me from pie carat Pi carat dot regression we have to import here two things first is the load model function we are not importing now everything like we did in when we were training the model like we have set up and all evaluate finalize and all those functions here we need only two functions load model and then a predict model so load and predict predict model so these are the Imports that we need okay now what you have to do we have to create a stream it application so if you are not aware about streamlit streamlit is a python Library which helps you integrate models and you can build python applications on web okay so it kind of you know four way sorry so it kind of provides you this very minimalistic you know way of building with uh apps in Python okay so uh data scientist or machine learning Engineers who have very limited knowledge of web Technologies like JavaScript and HTML and CSS stimulate is you know kind of a very famous there in that Community okay kind of it helps you build applications very faster when we have some models we can use extremely you know to visualize it or to integrate that in an UI and you know perform the predictions and kind of uh perform your inferencing on the model that we have that's that's why we use the stimulate and it's indeed very powerful and they have a lot of developments in the stimulate ecosystem in last one year okay so it was also acquired by some other companies you know streamlined so you can see from 5 carat dot regression and we have imported estimate as well now let's do one thing we have to let's set the page a tab that we have to give it some name so what you can do uh I'm calling it hd.set pageconfig and you can read more about streamlit on their documentation they have a very good documentation as well uh you can see I'm giving it a name the paste title and that will be page underscore title and this is going to be my page name so my paste title will be Insurance charges prediction Insurance charges prediction this is my going to be the page title that page that will create in stimulate HD dot set underscore page underscore config this is done now let's load the model so how do we load so let's write a function I'll call it a get model okay let's call it get model and here we'll do one thing you can see I have this model here Insurance model dot PK tablet I want to use this speaker model okay that I have saved so what I'm going to do I'm going to just return I'm going to the return lower model that we have imported on top from 5 carat Auto regression module uh return load model and then I'll just call it insurance Dot pkl so it's dot pkl so I have loaded my model okay now what so once we have the model we have to also uh predict the model right we have to predict basically on top of that on on with the help of that model OKAY on top of our data that will have so we'll have an input dictionary or data frame from the end user and we'll use this model to predict what will be my insurance charges Okay so let's call this predict and you know in this what we're going to do we have our two things one will be model the other will be data so this is going to be that right so let's have a variable called prediction equal to uh predict model we'll use this model dot we know model and then data equals to data you already have model and data equals few data prediction and now let's do one thing return this predictions and then in prediction what I'm going to do we are going to return the label if you see this on on the when we would when we evaluated the model or we we have this label right prediction label okay so this is what we are going to do here so label and then we have this the first so so this is my two functions get model and predict so in predict we are having this model and the data right so this is what we are doing so now what next now now we'll write the stimulate uh code before that let's get this model in a variable and what we can do we do not have to load the model every time we are you know testing or inferencing it you know in the runtime so what I'm going to do I'm going to do hd.cache I'm going to use this decorator St dot cache which you know that stimulate provides okay and I can also do one thing I can also do allow output mutation equal to true so we can allow output the mutation allow output notation equals to true so if I am changing the input and I am trying to you know in the same runtime trying to predict it should not load the model every time okay so if you don't cache get model now let's write the estimate code so how do we write the estimate code so it's a SD dot let's first give a title of the app so I'm going to call it incidence charges prediction that's it insulin charges position this is going to be the title of the page that we have right instance now now we need some input parameters okay uh that we have and we have to take some input box or some how we're going to take the input from end user so we'll use the form so what I'm going to do form equals HD dot form let's okay dot form and then Charles yes this is also my this target you also like charges we have form HTTP form and we have this feature okay if you come on this streaml we have this ah 6 BMI we have two now create this input structure that we have to create with streamlit so end user can interact with the application or they can fill the values or form and then we predict uh the labels basically that insurance charges so now let's do form the first thing is age for a is what we're going to have we are going to have um number input because we are going to as has this as a number input so number input form DOT number input and here let's give it a label so call it Edge and then here we'll have two things minimum value and maximum value and then we also have a default value so minimum values would be 1 excuse me and maximum value equals to let's keep it 100 as age and now we have a value also so value equals to 25 this is my default value so H and now what we're going to do we're going to have 6 also so 6 uh we can have this radio button for six because we only have male and female right so form dot radio and then let's give it a label and then here we'll have two things we'll have either male or female so mail and female this is what I'm going to have to male and female let's do one thing let's run this code and first see if you are able to get any response from hitting leader okay so what we are doing what we have done so far guys we have imported these libraries okay and then we have created two functions gate model and predict and we are loading the model Insurance Dot pkl and then we have this predict function where we predict with the help of the model and our data the data frame that will have and we are you kind of creating applications we have couple of uh input box so far now let's run this let me save how do we run extreme bit application for extremely run Android file it saves no such file or directory Insurance pkl.pk let me go back ah you can see I have this insurance pkl it should be only Insurance model here so model let's see dot cache is depreciated please use one of the extremely command http.cash resources okay we'll make the changes missing submit button so you can see this is this is okay so far so we have this insurance charges prediction and we have this form right you see this form that we have you know charges and that's why we are getting the submit button uh warning here and we have age which is uh this as default and 25 and then you increase or decrease it and then we have male or female S6 now what we're going to do let's write the others so six form dot radio and now we have BMI so BMI equal to form within that form because if you see we have created this variable called form and within that form we are going to take this several input from the end user so form BMI let's have this as a number input as well and then in this let's give it a BMI we have mean value let's keep it 10 the next value as 50. which is too much for a BMI you know for a healthy person uh if even for healthy healthy is like around you know between 20 uh of between I think 12 and 24 or something okay maximum value 50 means it's second to kind of have no surpass the Obesity States okay for a person so and value so let's keep it value as you know what we can keep as value so so for Value we can keep is 20. which is a very standard BMI so value and the BMI so we have eight we have six we have BMI so far okay and let me have a children so children here is a variable so form dot slider another different way of you know uh taking the input from the user we have sliders we have number inputs we have radio and also you can do we also have check box we have text input so you can read this through in the documentation form dot slider and inform dot slider what you're going to have we are going to give it a label children good and in children that we are going to have mean value equal to 0 and the max value equal to 10 and then we have a value so let's value equal to excuse me value equal to 0 default value so children so we have the slider for children okay as a data input so form dot slider children mean value max value and value then we have what else we have let me just go back to this we have smoker and region okay let me go back here BMI children and then we have Regional list so let's call it region list and for that region list what we have let's first create a list we have to create a list okay for the region we have so we had South East and what we had we had South we had South East North West let's keep it in the same honors same manner so we have South West South West North West and then we have South East and then we have North we I think these were our let me just confirm it once so if you go to Value counts we have South East Southwest North West North East okay so Northwest South East and Northeast okay good so this is the regional lift that we have okay now what we're going to do guys we have to first let's have a drop down so region equals to form dot uh drop selection we can have this selection and in selection what we're going to have we're going to have region and then region list the variable that we have regionalist now we have region so we have one feature left which is smoker so for that we're going to have let's call it if form dot check box okay here we can have this check box you know for a smoker so for smoker and what we can do we can do is smoker and we can have this CS and then else smoker equal to no so this is for smoking okay smoker cannot find if else so now what we're going to do guys we are going to have this predict button the warning that we got right click button and you predict button what we're going to write form dot forms uh form dot form submit button and here will have this predict now here I have to make some changes okay if you see this southwest North West South Eastern Northwest let me go back to this you can see this is all lower okay we do not have you know in capital and this goes for smoking as well okay the smoker so what we can do we can uh when we are you know creating this input dictionary okay let's create this text that will take the input from end user this will be in depth first is age age is okay age is same that we have age and then we have six six is also okay so 6 and then we have so we have six if you see here we have male and female which is like a caps okay but in the data that we have when we train okay it was not caps but so what we have to do we can also do lower here okay so it will basically the string that we are taking the value from the individual it will make it lower Okay so it will not be in calf we have this caps right M and F right so here it will make it lower and same will do it for a smoker as well and the region okay so not for smoker smoker is good for this region that we have Southwest where you can see the first letter is capital so we have age we have six and then we have B uh BMI so BMI is okay as BMI you can see BMI is fine and then we have children children is also good so here you can see children as it is but we have to make some changes in regionalists smoker let's keep it smoker smoker and then smoker and then region so region your it will be region dot lower now we do not need this comma region dot lower now what we have to do now we have this input dictionary okay now we have to convert this in an input data kind of a data frame so let's call it input EF and now we're going to use PD dot data frame input dictionary it will be a list inside of bdot dataframe function so it will be released and now we will get this input DF okay uh input DF let me just do one thing input the yes let me go back okay and now here I'm going to write the code guys so now let's do if predict we have this button right so let's it hit the predict button so if you are hitting this predict button the course would now the model should get utilized so output and then we have this function but with the function name of the model that we have created which is predict so it will be only predict so predict and here we are passing that you know model and this input DF that we have you know converted that dictionary to data frame when we are getting the a value from the end user so we have output equal to predict model and then input DF and then what we're going to do let's have this the result in a state of message which is HD dot success extremely provides several status messages options like warnings info errors success will use success and here we'll write the predicted the predicted uh charges are excuse me complete charges are and it will be in dollar the value because once we have the data and then we have this now let's do one thing not this we have to let's have only tilt ah two decimal values okay so what we can do to f and then here we have to do the format format and then here is your output this will be this format output now what we can do so let's run this let's run this to see if we are able to you know get the response so what we did in this we let me just see one so we have a gate model a return load mod or instance models predict and then model gate model if she remote title we have this created this feature list input dictionary and then we have converted data frame it like okay now let's run this selection is not a valid extremely extremely command okay let me go back ah it's not selection it's called select box sorry form dot select box yeah so now you can see we have this let me just remove the cache for now okay hd.cash now let's see what it does okay we have to use AC dot resources Insurance charges prediction app now here which is age we have this q6 BMI children region and the smoker okay now we have to fill this value so let me just show you one of the examples so age so if you keep this age as 32 and this is the first feature and then we have female so we have two classes there male and female in this column then we have BMI now let's increase the children to you know you can increase it decrease it you can see you know you can increase it to five with so basically this is a slider okay you can expect slide it so let's keep it as two and then the region I'm okay with it so we have four classes in the categories in the region Southwest north west north east south east right vision and a smoker so you see this this is where we got the prediction level right once on the once we train the model and collab now we have used the same model that insurance model here in the streamlit application and now we have like to predict it so if I am a smoker let's select as a smoker okay so this is basically a selection box like a check box where you are selecting it based on this feature I would like to you know my model to predict uh the insurance charges and we have this stimulate application where we are doing it right so now let's predict you can see the printed charges are around 24 340 US dollar rate in in this case so this is how you build like you know a simple application you have a model you want to not test it out and you want to create an UI and you can deploy it you can share that with your you know friends and to anybody like you want to save okay so what we did in this video guys we have used this insurance model dot pkl that we used Pi Cara to train it on the insurance Health Insurance data and we created this estimate application so you'll find the code here on the GitHub repository now you can also extend it okay and let me know your thoughts or if you have any feedback on this particular video okay if you are facing any challenges you know creating or running this program you can just uh comment that in the comment box and I'll be happy to help okay and you can also uh do a pull request if you want to you know uh make some changes if you want to improve uh this model further okay you can also do it from here so this is what we have for today guys in this video if you if you are liking the content uh please like this video and please subscribe the channel if you haven't subscribed yet and please share this video and Channel with your friends and peer thank you so much for watching this video see you in the next video
Original Description
In this video, I show you how to use the low-code python library PyCaret to train a regression model for predicting insurance charges. I demonstrate how to make predictions in a Streamlit application, which is a great tool for building ML-powered web apps. You will see how easy it is to create a full end-to-end solution, starting with training the model to making predictions in a web application. Whether you're a beginner or an experienced data scientist, this video is for you. Enjoy the ride!
GitHub Link: https://github.com/AIAnytime/Insurance-Charges-Prediction-Streamlit-Application
Streamlit Documentation: https://docs.streamlit.io/
PyCaret Documentation: https://pycaret.gitbook.io/docs/learn-pycaret/examples
#streamlit #coding #python
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from AI Anytime · AI Anytime · 14 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
▶
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
Spelling and Grammar Checking Streamlit App: Building Docker Image
AI Anytime
Spelling and Grammar Checking Streamlit App: Docker Image and Docker Hub
AI Anytime
Image Caption Generator: Google Colab and Hugging Face
AI Anytime
Low Code/No Code AI Platform Teachable Machine: Brain MRI Image Classification
AI Anytime
Low Code/No Code AI Platform Teachable Machine: Testing the Model
AI Anytime
Low Code/No Code AI Platform: Streamlit App for Brain MRI Image Classification
AI Anytime
Readme Generator Streamlit App using ChatGPT
AI Anytime
Generate Minutes of Meeting (MoM) from Video using ChatGPT: AI as an API
AI Anytime
The Great AI Showdown: ChatGPT vs ChatSonic 🔥
AI Anytime
Generating Transcripts and News Article with Whisper, GPT-3.5, ChatGPT and Streamlit
AI Anytime
Toxicity Classifier using Machine Learning and NLP
AI Anytime
Toxicity Classifier API using FastAPI
AI Anytime
Toxicity Classifier Streamlit App
AI Anytime
Low-Code Insurance Prediction with PyCaret and Streamlit
AI Anytime
Deploy Streamlit Python Application for Free
AI Anytime
GPT3 Powered Text Analytics App
AI Anytime
AI Image Generation Streamlit App
AI Anytime
Streamlit and txtai: Building an Abstractive Summarization App in Python
AI Anytime
Building a Topic Modeling and Labeling app with Streamlit
AI Anytime
The Art of AI: Exploring Midjourney, Dall-E, and Lexica
AI Anytime
Exploring the latest Large Language Models (LLaMA and Alpaca)
AI Anytime
Comparing LLMs like GPT-X, LLaMA, and Alpaca: Analyzing the Perplexity Score
AI Anytime
GPT-3 powered Q&A App using Langchain, GPT-Index, and Gradio
AI Anytime
All things #ai . Latest and greatest in AI. #tech #python #chatgpt #youtubeshorts #shorts #gpt3
AI Anytime
Text-to-Video Generation using a Generative AI Model
AI Anytime
#ai brand name generator. #artificialintelligence #tech #shorts #youtubeshorts #youtube #chatgpt
AI Anytime
Talking AGI with Sam Altman: A Deepfake Showcase
AI Anytime
A conversation with ChatGPT creator Sam Altman. #tech #technology #ai #shorts #viral
AI Anytime
Get to Know Anthropic's Claude: The Ultimate ChatGPT Competitor
AI Anytime
#shorts #chatgpt #python #datascience #tech #coding
AI Anytime
Recipe Generator App from Cooking Videos using Whisper and ChatGPT
AI Anytime
Segment Anything Model by Meta AI: An Image Segmentation Model
AI Anytime
One of the best #ai #books based on #tensorflow. #tech #coding #shorts #chatgpt #machinelearning
AI Anytime
Music Generation using Mubert #ai . #music #shorts #youtubeshorts #chatgpt #generativeai
AI Anytime
Image to Text Prompt: Reverse Engineering AI Image Generation
AI Anytime
Image Generation for #ramadan using #ai. #midjourney #chatgpt #shorts #youtubeshorts #islam
AI Anytime
How to build an AI-ready organization: Cultivating a Data-Driven Culture
AI Anytime
Midjourney: Generate AI-powered Images
AI Anytime
Getting Started with Graphs: A Beginner's Guide (Part 1 of GNN Series)
AI Anytime
Build India's First ChatGPT like App for Politics: BJP-GPT
AI Anytime
Meet BJP-GPT.... @AIAnytime #bjp #news #shorts #tech #chatgpt #ai #youtubeshorts #coding #video
AI Anytime
ChatPDF... #chatgpt for PDF files. #ai #generativeai #shorts #youtubeshorts #coding #tech #ai
AI Anytime
Free AI Image Generation #ai #chatgpt #coding #tech #shorts #youtubeshorts #shortvideo #generativeai
AI Anytime
Transform old photos into Vibrant Memories with Deoldify AI: Build a Streamlit App
AI Anytime
Open Assistant: The Real Open-sourced LLM
AI Anytime
Thanks to @YannicKilcherand team for the open sourced LLM Open Assistant. #ai #shorts #tech
AI Anytime
Search Engine for AI generated images. #ai #tech #technology #generativeai #chatgpt #shorts #video
AI Anytime
Generative AI Video Platform "Synthesia" #shorts #youtubeshorts #ai #tech #chatgpt #generativeai
AI Anytime
Text to speech Voice AI platform. #shorts #youtubeshorts #ai #tech #technology #python #coding
AI Anytime
Create Amazing Videos with ChatGPT and Pictory: Free AI-powered Video Creation
AI Anytime
Want to create beautiful video using #chatgpt and #pictory ? Watch the tutorial on channel. #ai
AI Anytime
Animate your photos using AI. Bring old family photos to life. #ai #tech #shorts #shortvideo #coding
AI Anytime
Create a PDF Search and Summarization Tool in less than 100 Lines of Code: GPT-Index and Streamlit
AI Anytime
Text to Video Generation using Videocrafter: Intuitive Math behind Latent Diffusion Model
AI Anytime
Gamma AI: Create presentation PPT easily with #ai . #chatgpt #shorts #shortvideo #tech #coding
AI Anytime
Tripnotes: Free AI tools for your trip planning. #ai #chatgpt #shorts #youtubeshorts #video
AI Anytime
Meet Bark (New Text to Speech Model): Clone Any Voice to Generate Music and Speech
AI Anytime
Fliki: The free AI video creation tool. #ai #shorts #shortvideo #youtubeshorts #chatgpt #tech #news
AI Anytime
Ask Anything Tool: Chat with Your Video using ChatGPT, MiniGPT4, and StableLM
AI Anytime
HuggingChat: Open Source ChatGPT (Interface and Model)
AI Anytime
More on: ML Pipelines
View skill →
🎓
Tutor Explanation
DeepCamp AI