I am (name) from LearnVern. (8 seconds gap)
You are welcome to a machine learning course.
This tutorial is a continuation of our previous tutorial.
So let’s move ahead.
And today's tutorial we are going to see about Logistic Regression.
So, let's understand this.
Here I will show you logistic regression. (4 seconds gap)
Here, this is Scikit-learn dot org, and this is the documentation of logistic Regression.
You should always refer to the original documents,you will find all the updates and changes here in a very clear and original format. This is a trustworthy place.
Also you can read some related blogs for it.
So, logistic or logit is a classifier though it is named as regression but it is a classifier.
It is a classifier because it gives the output in Categorical form and does not give output in continuous value.
Here you can read the full description, such as it works for binary class but what if we have multiple classes.
For example if we have to find if it is day or night, then this type is binary as it is having 2 classes. This will work.
but, as we saw in the iris dataset where we had 3 species, how will it work for 3 species? if you have more than two classes then we can use this one vs rest scheme or technique for more than 2 classes.
So if this type of situation occurs, then we should basically use this OVR. ok?
Next, is regularisation, which is used for model optimization, where we use L1, L2 regularisation, so we will study this ahead, but here it is applied by default.
Hope you are able to follow.
Let’s see the examples.
Here all the parameters are described,
We will directly scroll down, and go to the example.
Hope you are with me.
Here they have used the same iris example, which first I will explain to you, and then implement it.
See with some lines the entire machine learning course is implemented, and algorithms are implemented.
So, you will enjoy seeing that you are able to implement it with just small pieces of code.
But as you will proceed, a certain level of complexity will also increase.
But till then you will be an expert in these things.
So, let's see from sklearn dot Datasets import load iris.
That means we loaded the iris datasets.
So, to load Datasets , if you remember I had a LReady explained ways during EDA that there are many options to load the data such as ghetup, UCI, keggle, from where you can download and load it.
So,these are different methods.
Now, I require a logistic regression module. From where did I get that? that I received from sklearn dot Linear underscore model.
So, these things you will remember with practice.
So as this is a linear model so we have downloaded it from the sk learn linear model.
And then import logistic regression.
Now let's implement these two things quickly.
So, at first we have to implement from sklearn dot Datasets import load underscore IRIS, iris. (typing)
Second is, from sklearn dot Linear model, at times there can be a mistake so you should always cross check the spelling, so here it is
Underscore linear MODEl, model imports logistic regression, so this is not connected properly, that is the reason it is not giving me suggestions, so we can connect this first LOGISTICS, logistics, REGRESSIONS,regressions.
So, we have imported these two things in the beginning.
Now, after this we want data, so for data there is a shortcut given, earlier we had seen a long way in parts and pieces, here it is given x and y load iris return underscore x underscore y is equal to true.
Hope you are able to understand.
So, let's understand this also
Here data is equal to load underscore iris, so we will try to load the datasets from here.
Now I will do data dot data.
So, here there is data under data dot data, so here there is data given in a numpy (pronunciation: nuhm - pai) array.
See i showed you the data.
And if I do data dot target, then it will display its target or also called the classes such as 0,1,2.
So, this was the method that we had used.
Now, we will go through the method that they have given which is x comma y is equal to load underscore iris return underscore x and underscore y. So if we pass only this much, that is return underscore x and underscore y, so it will give data only in x and y format.
So, here x is generally shown in capital and y in small alphabets. X comma y is equal to, here we will use load iris again and in the bracket you can see it's aLReady showing us suggestion of return, so we will use it, it is by default false, you can see above, over there i will change this into true, and enter.
Now, let's see what we have got in x
So as you can see i will execute this x, so we have received this data.
And what do we have in y, so here we got the targets.
See this is how it came in x and y. Ok?
Hope you are able to understand me.
I will organise this into steps.
So to organise this into steps, the first step is, you aLReady know about it, it is very easy.
So the first step is to import, import the libraries.., so we imported.
The second step is to load the data, so this was the way to load it.
Now, the next step is to create an object, here we have to create a model for machine learning logistic regression.
So, create an object of logistic regression. (typing, 5 seconds gap)
So, to make the object of logistic regression, they have given here CLF, which is a short form of classifier, and you can also write logistic regression as LR.
So, here you can create logistic regression this way.
So, the LR would be created, now in the LR model, if you have to give any parameters in it, then you can give that, and if you don't want then it's up to you.
So, normally we give a random state here, so we are also giving a random state as zero.
So, what is the use of random state, so whenever the algorithm is running, during that time, at the back end a lot of numbers need to be generated.
So, to generate those numbers, let's say I give you a lay man example, I asked you to generate numbers but then you tell me “I am so confused as I am unable to decide from where to begin’’.
So, i told you ok, begin with 1 then, then you took one as base and used your logic and randomly started giving numbers.
So, similarly here I gave a base value as zero and on the basis of zero you can generate any random number.
So every time it will generate a number keeping the base as zero.
So, what is the benefit of it?
It helps to create the same type of number mostly.
As all the calculations are happening at the back end and not Monitored in front of us, this will ensure to have the same number pattern for calculations happening at the back.
So, this is how I have created an object and used a random state equal to zero.
After making the object next step is training,
So train the algorithm, or train the model, how to train it, by using fit function. (typing)
To train, we use a fit function.
let's see the LR dot fit and in this insert X and y.
With this the model will be trained.
ok, it is giving us “stop total number of iterations reached limit”, a warning, but we will not go there now,
So, this is successfully trained.
So, after training next will be 'prediction'.
So, to predict, LR dot predict, we will have to pass a value in predict.
As they have passed the value, we will also pass in the same way.
So, first I will show you how much they have passed, so they have taken 0 to1 rows and all columns.
And for that it has predicted the value over here.
I am also putting the same value. ok.
And the predict function will give a predicted value.
So, it has given us 0,0
Let me cross check, so it's all good.
So, this record over here belongs to zero category.
And this over here also belongs to the zero category.
Now, I will take rows that are in the last, as they are of 2. Right!
I hope you have understood so far.
So, in total there are 150, so I will take 130 and 132.
What is it predicting?
So, it is predicting 2 for them.
This we know because we already know that our first 50 data is zero, next 50 is of 1 and third 50s is of 2.
So, in this way it is giving us predictions.
What is this step?
I will write that this was the step for prediction
PREDICT using PREDICT function.
So, we are using a predict function to do prediction.
After this, Last, one more function that it gives is to find the score.
And to do that, you can see CLF dot score, score is the function over here
LR dot SCORE, this brings out accuracy of the data.
So we will put X and y in this.
This will now give accuracy.
And it is giving us 97.33 percent accuracy, or 0.9733.
So 97.3 is the accuracy.
In this way we implement logistic regression with the help of SKlearn.
We used SK learn library, in that linear model, and with linear model, we used logistics regression.
If you have any problems understanding this then you can watch the video again by replaying it.
We will stop the session here for today,and it's other parts we will cover in the next session.
So, keep learning and remain motivated.
If you have any questions or comments related to this course.
then you can click on the discussion button below this video and post it there.
So, in this way you can discuss this course with many other learners of your kind.
Share a personalized message with your friends.