Welcome back to the class of our course about the complete introduction to The Science Show in this
class, we are going to talk about another algorithm that is really present inside of machine learning.
And in this case, it would be logistic regression.
So basically what we do today is we are going to work with another tool that is pretty important in
machine learning that is called Eskild.
Basically, Skillern is a machine learning library that will offer you various machine learning tools
that you guys will be able to work with.
So basically, you will have access to all the algorithms.
So logistic regression will be in it.
You will have all the other algorithms that we talked about a little bit before in the class in a more
theoretical way.
All right.
So basically, the first thing that you guys will need to do is import.
What import is killoran inside of your by expeditor?
So that's always simply go on your file right here instead of your settings project and the operator,
click on the plus button right here and simply write down ASCII learn.
So when it's done, it should be this one right here, simply click on install package and you guys
should be able to have it.
So as you can see, I'm having it right here.
Right.
So when it's all done, the next thing that we want to do is really jump into it to jump into what we
are going to create.
So for the purpose of this class, what I decided to do to make it the most simple possible is to work
with confusion, metrics, basically confusion, metrics that will give us well, we'll explain this
more easily our model, and will allow us to know how well how our model is good in terms of predicting
something.
So basically, what I decided to do is create a really basic example.
What I'm talking about example.
What I mean here is let's say someone is looking for a job and this person have what?
It's Emmonak management position job.
And this person needs to have experience in three fields.
And basically, depending on the experience of the person in those three fields, this person will get
a job or not get a job.
And basically, we want to predict the fact that this person will well, the accuracy of our system
to predict if this person will get a job or not get a certain job depending of its experience.
So what I'm planning to do is with pendas, create areas where we are going to store everything well,
basically databases where we are going to create our own data.
So basically you will create your own database in this case.
So what I suggest you do is really use twenty five elements inside of your database.
And from this moment, from this moment, we will create our little program that will be able to predict
if yes or no, our model works fine or well, if it's accurate or not.
So let's start.
So basically the first thing that we need to do is pretty simple.
We need to import the everything that we will need for our well, for our class.
So pretty simple.
We are going to start with Seabourne.
So we'll import Seabourne, as I said.
You also need matplotlib to be able to work with grafs.
Well, live from that five block,
then we'll need also would be Fender's.
We also would need some things from Escalon.
So basically we will import them from as she learned that model.
We want to import train.
This split and we also need logistic regression, since we are going to perform a logistic regression
and show the results inside of a confusion matrix, so we are going to read it down right here.
Here we go.
And finally, the last thing that we will need just correct.
To be sure, it's written correctly.
Look, just the progression, here we go and finally, we'll need metrics so from.
Escape, learn
would need to import metrics.
All right, so right now we have all the elements that we need to be able to create our well, basically
our database.
And so for the database, it's pretty simple.
What I did is, as I said, I created twenty five elements or the elements are already pre created,
so just show them to you.
So basically it's pretty simple.
I have my candidate right here or the person let's call it the person I prefer person.
So basically the person will have experience in finances, management, logistics.
And finally, do the person get work, yes or no?
So it's pretty simple.
Once again, we have our person, number one, and that what we have here is how many years of experience
this person has.
So they said that it could be one year or two years, five years, anything that you want.
All right.
So the first thing that you guys are going to do is create a simple database that looks something like
this.
And then what we'll do is we will simply put all this together and create a data frame where we are
going to store everything.
So when you guys are done, what will do will create is that a frame that we will call data?
And inside of this data, we are going to with the help of vendors.
So basically we are going to refer to pendas.
We're going to create a data frame that will store person.
So basically, all the elements inside of person and basically in our columns, we want to have finance,
management and logistics.
So here we go.
So instead of our columns, we want to have finance
management and.
Here
and finally, logistics.
And what we need also is our get work.
Here we go.
Good work.
All right, so right now we have everything that we need, the next thing we want to do is verify if
everything works fine.
So we'll simply print our little data.
So we print our variable data just to be sure that everything works fine.
All right, so as you can see, it's generating perfectly right here, everything works fine.
So let me just explain the data to you.
As I said here, we have our years of experience for the three, first of them.
So finance, management and logistics and years of experience.
And the next thing that we want to have, it would be zeros or ones.
So basically, one means the person gets the job.
Zero means the person doesn't get the job.
So it's pretty simple to understand.
All right.
So right now that we have everything that works here, it's time to get to the next step, which could
be creating our logistic regression in Python.
So for our logistic regression, what we'll need is a pretty simple we'll need two variables that will
be X and Y.
So basically they will be inside of our graph.
So for our variable X, what we will have is pretty simple, will have the elements, finance, management
and logistic as well.
So what we'll do right now, we'll simply make a reference to person.
So write down a variable person and from person we want to use, in this case, finance.
Management
and finally, logistics.
The second variable that will have to be the variable, why and this let's put it in small letters and
this variable will get worse.
Basically, once again from person.
We want to have get rid of the person, gets work for no right.
So right now we have our model.
The next thing would be creating our test, using the test split function to be able to test everything.
So basically, we are going to decide that what percentage of the database will be used for testing
and which one will be used for training.
So pretty simple.
How exactly do we write this?
Simply write down X.
So put it right here.
X train X this.
Then why train and why this?
All of this would be equal to train this split is what I'm writing right now, is what?
Well, how much I want for my data, how much I want of my data set to be used to test and what percentage
of my data set I want to be to be used for training purposes.
So basically, I'll finish writing and I'll explain everything.
I love X Y, so we'll have our test sites.
So in our case, we want a test site of, let's say, 30 percent.
So this means that zero the three.
So this means that we want what we want to use.
Thirty percent of our data set for testing purposes and the other 70 percent will be used for, well,
training purpose.
And the second one will be random state and this will be equal to zero.
All right, so when it's done so right now, we with this line of code right here, we are able to say
what will be the test split?
So how much would be used for testing purpose and how much would be used for training purposes?
So we have everything that we need right there, right when it's all done.
The next thing is pretty simple is writing our logistic regression model.
So it's pretty simple.
We'll do it down there.
So it's going to be logistic regression.
So in our case, let's call it yeah, let's call it logistic Craig, which would be pretty simple and
logistic.
Craig would be equal to logistic regression since we are applying logistic regression to it.
So this would be available in which we are going to store the functional logistic regression.
All right.
Then the next thing is pretty simple.
We'll call it let's call it L.G., L.R..
It's going to be smaller and more easier to work with.
So we'll have to r, which would be equal to logistic regression, will not have to write down each
time logistic regression.
So we'll have are that fit since we're fitting right now our training of X and Y.
So X thing as well as Y train.
The banks and capital letters.
All right, so right now we have everything that we need.
Real important, not making mistakes.
Right, next thing that we need is we want to predict our well, our question right here.
So why?
And in this case, we'll call it prediction.
We'll be equal to.
In our case, logistic.
That got to so equal to or not that and what I do want to predict the test of X, so in this case,
predict X that test.
So basically right now we have everything that we need to be able to run our model.
Then the next thing that we want to do, since we want to put everything inside of a confusion matrix,
we will create our confusion matrix right now.
So basically our confusion matrix, what will be created with the use of once again, pendas.
So pretty simple.
How exactly do we create our confusion metrics?
We are at first to create our variable, which would be called the math.
So let's call it.
Matt, let's use small letters as well.
All right, so in this case, we'll have confusion, matrix and the confusion matrix would be equal
to in this case.
So we'll have our white test as well as our white prediction.
Then we'll have padrone.
So how how are things in south of our conclusion that in this part of the code we're creating our confusion
metrics?
And as I said.
Here we go.
So right here, as I said, what we'll do is we will give real names to our well, to our heroes.
So pretty simple.
Let's do it right here.
So real names have real
names, so for the first row, we will have right there, let's call it.
I don't know how we can call it, we can call it.
So it's right now.
So basically true results.
So true.
And four columns, since it's everything that will be predicted, let's call it, I don't know.
Let's call it provisions, since this is what will be predicted, so we'll call it a revision.
All right.
So we have everything that we need.
The next thing that we need to do is we are going to use Seabourne to create our confusion metrics right
now.
So pretty simple, isn't that heat map?
So basically, in this case, we're going to use a map to be able to see everything well, to be able
to see it more clearly when our confusion metrics will be generated.
And in this case, we are going to apply our map to our confusion magic, so you'll see it's going to
be something that is pretty cool in this case.
We call it math.
All right, so we have everything that we need and annotation is going to be true.
All right.
So we have everything that we need.
And finally, the last step will simply be printing everything.
So basically, we want to print absolutely everything.
So print.
Actressy.
We hear what happened are accuracy score.
Here will have our white test, so we'll have our white test and that what we have predicted for our
white as well.
So here for our extra square, we'll have our white test, as well as what we have predicted to our
White House for training and predict the battles that are right here.
That's going to be why this.
Also here, we'll have our.
Why train as well as our why?
Predicted.
Here right now, we have everything that we need.
So very important, the really important part of what we have done, doing all this would be correcting
our code, because usually when we write down a huge code like this, it's really important to correct
absolutely everything that we have just done.
All right.
So the last step will simply be writing down Kielty.
That should be able to see everything that we have to do right now is we are going to run everything
to see if it works perfectly.
And if not, we're simply going to correct mistakes inside of our code.
So if we run everything.
OK, we can see that there is a mistake, so zero size error reduction operation if men, which has
not identified so what we'll do right now, we'll simply look at our code and try to find the mistakes
that are inside of it.
What could be the mistakes that usually happen?
So usually the mistakes that happen in those types of code will be basic mistakes.
So I already see some of them.
So basically I can see it right here.
So we have whitelist.
There should be well, we should have wide prediction that is right here.
So we have this mistake right there.
OK, so basically the mistake that we have is pretty simple.
So we have whitest white men in here.
We should have white prediction instead of white trim.
So here will break down what prediction?
And finally.
The other place where we should have wide prediction should be here.
So this is exactly what we will do.
So we'll keep our white list and we are going to write down our white prediction.
All right.
So normally right now, we should have everything that we need.
And if you guys if you guys you have an error inside of your code or whatever, you can simply copy
my code right here.
It should work properly.
All right, so at the end, this is the result that you guys should receive, and this is a perfect
result of usually what you guys showed up.
So here you have your accuracy.
So basically the accuracy of our model is 75 percent.
So we are able to predict at 75 percent how many people will be well, how many people will get the
job and how many people won't get the job.
How exactly does it predict?
Seventy five.
So it's pretty simple.
The calculation of this is the truth.
So basically, what are the what, what the what is the truth of basically the truth that we can see
it this way us and versus the provisions.
So basically here will have our provisions for this provision of a Yes.
Provision of a no.
So here we'll have our true.
Yes.
A true right here.
And basically how we make this calculation, it's pretty simple.
So we are going to make an addition of what are all the provisions that we have made that happened.
So basically, it's going to be this one right here and this one right here versus all the provisions
that we made that basically didn't happen.
So basically, we made mistakes right here and zero mistakes right there.
So it's simply going to be eight plus one.
And this divided by the number of provisions, which would give us 75 percent, which is which makes
pretty much a lot of sense.
So we can see this is how we are performing a a well, this type of regression.
So you can see it's not.
Well, yes, it could be complicated.
But at the end of the day, your goal is really to have this to see how accurate is your model.
So in our case, it's simply going to be nine divided by 12, since we are going to make eight plus
one divided by the well of this.
So basically eight plus three plus one that should give us seventy five percent and seventy five percent
of accuracy is pretty good for this type of model.
So as you can see, this would be the first model that we will create right now.
So the first machine learning model.
So this is the code around it.
So basically I try to make it as simple as possible, but it's pretty normal that you guys have mistakes
in a code that is big like this.
But once again, if you guys still have mistakes, pretty simple.
Just screenshot my code and you can simply retype it and you should have everything that you need.
So that's a first class guys insu out in our next class.