Hello guys.
So we are going to continue a discussion with respect to Streamlit app.
Uh, now in this video I'll just try to show you and uh, project uh, again a machine learning project.
And just to give you an idea like how easily you'll be able to create any web app with the help of Streamlit.
Okay, I know, uh, you may not have seen any machine learning algorithms yet.
I would suggest at least you have some idea about some of the machine learning algorithms, like Random
Forest and all.
But here in this problem statement, I am going to solve a classification problem statement, right?
So this is just to show you or give you an idea like how to properly develop an end to end project with
the help of Streamlit.
So first of all, I will go ahead and import all this libraries that is Streamlit pandas and sklearn
dot datasets uh and sklearn dot uh learn dot ensemble.
So first of all I need to go ahead and install this sky kit.
Learn.
Okay, so I will just go ahead and, uh, I have to import one very important library that is called
as Sky Kit learn, which is nothing.
But this is the same as sklearn.
So for that I need to go ahead and install this.
So here I will open my terminal and uh I will close this okay.
So let's quickly go ahead and do the pip install uh minus our requirement dot txt.
So here you can see requirement dot txt file is not visible.
The reason is very much simple because I'm inside my Streamlit folder.
So I'll just go ahead and write CD dot dot.
Now let me go ahead and do the installation.
So once I do the installation my scikit learn will get installed.
And then only I will be able to use this sklearn dot datasets and sklearn dot ensemble.
And this is one of the classification algorithm that we are going to use okay.
So it is going to take some time till the entire installation of this particular library happens okay.
And you always have to do this installation in your same environment, uh, where you are working.
Okay.
Now, uh, I'm going to use this load iris data set.
This data set has four important features that is nothing but petal length, sepal length, petal width
and sepal width.
So I'm going to use that.
Um so here let me just go ahead and create one of the function okay.
Now inside this function I have written definition load underscore data.
I'm going to initialize this load iris over here.
This is going to give me my data set inside this iris folder okay.
And then I'm going to convert this into a data frame just by writing PD dot data frame.
And here I have given iris dot data.
And the column name is iris dot feature underscore names okay.
So uh, don't worry if you are not just able to understand this right now, because later on we'll be
having this detailed discussion when we discuss about all the algorithms.
But in short, this is my independent features.
Uh, this is my feature name, right?
All the feature names and this is my data that is available over there.
Okay, then.
Um, this is my target feature.
That is nothing but DF of species that I've actually created, right?
And then we are returning both this information over here.
Okay.
Let me make sure to write, uh, important decorator, which is called as SD dot cache.
And, uh, I'm writing this so that, uh, every time we load this, uh, we should be able to save
this entire data into the cache, and we not each and every time load this from this particular library.
Okay, so here is my let's go ahead and call my DF comma target underscore name.
So this I'm going to call it from my load underscore data.
So I will just go ahead and write load underscore data function okay.
Now uh I'll just give you an idea over here.
Uh how I am going to apply the machine learning algorithm.
So over here we are just going to apply model is equal to a random forest classifier okay.
So I'm going to use this particular model.
And this model will be requiring an input and output feature.
So here in order to train I'll just go ahead and write model dot fit.
And let me just go ahead and write DF dot Ilok which will be uh taking the independent.
This is my all my independent features, and this is my output feature.
Okay.
So basically I'm just going to take in my x axis all my independent features, excluding the last feature.
Okay.
Last feature is my dependent.
So last feature is nothing.
It is the species.
Right.
So this basically becomes my independent feature over here.
And this will basically become my dependent feature over here.
So that is the reason I'm doing model dot fit.
Now, uh, in order to select and make this diagram or make this application interactive, I'm going
to use this st dot slider.
And I'm going to use with respect to sepal length, sepal width, petal length and petal width where
my values will be between min to max right whatever sepal length minimum is them whatever sepal length
maximum is there I will be able to slide it okay.
And uh I will take all these input data, whichever input data I select.
Okay.
I'll take the sepal length, sepal width, petal length and petal width in the form of list.
And then we will do the prediction.
So here in the next step we basically do the prediction.
Okay.
This is just to give you an idea uh what exactly we are doing.
Okay.
And one thing that you really need to see that okay.
It's okay if you don't understand this, but because in the later stages we'll be able to understand
it.
But just I really wanted to show you the power of how an application will look like.
Okay.
So finally we will go ahead and write down all this prediction particular predictions and predictions
pieces.
Okay.
So let's go ahead and execute it.
So in order to execute it again I will just go ahead and open this.
Uh you'll be able to see okay let me just execute this entire application.
So I'll go ahead and write CD 14 Streamlit.
And let me just go ahead and run this Streamlit run classification.py.
So if I go ahead and execute this here, this is how my browser will look like.
See.
So this is getting loaded with respect to the data set that I have.
So it says that hey SD dot cache is deprecated and will be removed soon.
We can use SD dot cache underscore data.
Okay.
So let's go ahead and use this.
Okay.
So I will reload it.
Okay.
Perfect.
Now see right now I have not selected any.
Now let's go ahead and select my sepal length sepal width petal length and petal width.
So here you can see my predicted output is versicolor.
So this is the kind of plant that I'm actually getting right.
Uh if I go ahead and change my sepal width again if I go ahead and change my petal length, if I go
ahead and reduce my petal width.
So see it is showing setosa.
If I go ahead and increase my sepal length it is showing setosa.
If I decrease my petal length.
If I increase my petal width I'm getting virginica.
So how beautifully.
This is just like a machine learning application, which will be in the left hand side just by with
the help of slider.
You're using this, uh, and just by doing this automatically, your machine learning is able to give
this right entire.
Obviously, if you do not understand the machine learning algorithms, don't worry, we will be covering
that.
But the main intention of this particular video is just to show you the power of the Streamlit and show
you that how beautiful this is with respect to showing the predictions, right?
And here I did not write much HTML code at all.
Uh, it was very much easy to probably, uh, display this entire things and, uh, this code that you
see, uh, over here, uh, if we just see step by step, we have used components like slider, we have
created this store cached data so that it it does not every time load this.
Instead it takes the cashier data from there.
With respect to the prediction.
I have this and we are writing that prediction in the screen itself.
Right.
So yes, uh, this was it, uh, from my side.
Uh, I hope you like this particular video.
Um, I will see you all in the next video.
But, uh, this is just an example with respect to the machine learning algorithms and how easily it
will be able to display.
Right.
So yeah, I'll see you all in the next video.
Thank you.