Let's kick off the preparation for the logistic regression preparation and this
is all about making sure that we are good to go.
And what does this mean?
It means to prepare the dependent variable.
Dependent variable, as we saw before, our dependent variable is an object and this
cannot happen.
So this is one, another is that we
isolate x and y, and then finally we do train and test split.
And this is what we need to take care of.
So prepare the dependent variable.
So first, let's have a look at our yes, no variable.
Here you go.
And you can see that it's either y or n.
Another thing that we can do is this value count just to make sure that it
only has two values.
It's yes, it's either an n or a y.
And what we'll do is that we'll use the numpy .where and then here.
So when this is yes, then we'll have a one and otherwise we'll have a zero.
So this is the replacement.
And now I just do this data frame.
Yes, no, I'll just put it and replace it into the variable itself.
Control enter.
And this is done.
Then the y equals data frame dot yes, no.
The x equals the data frame dot drop
columns equals and then yes, no.
Another thing that we need to do is the
x, we need to add the constant.
So add constant to the x and let me do
control enter.
And here we get an error.
So module stats models dot API has no attribute at constant.
And that is because it is at underscore constant.
Control enter.
And now, yes, we are done.
Now let's import the train test split function.
So from sklearn dot model selection, we import the train test split.
And we have learned this already.
So I'm going to go a bit quicker now.
I'm going to create the x train, the x test, the y train, and the y test.
Equals, then I use the train test split function.
And then inside I add the inputs, which
are x and y.
We specify the test size, which is
usually 0 .2.
And the random state, this is so that you
get a similar split to mine.
So if you are to do x train dot head,
control enter, then you should see here in the index positions that they are the
same as mine.
And this was it when it comes to the preparation.
Now we are absolutely ready to do our logistic regression.
Until the next video, have fun.