Logistics Regression
- 01:46
Learn how logistic regression is used in Python for classification problems.
Downloads
No associated resources to download.
Glossary
logistic regression PythonTranscript
Logistic regression is the cousin of linear regression, and despite its name is actually used for classification problems, logistic regression can be used to simply predict classes without indicating a confidence level. In this code block, you can see that we're using the logistic regression model, fitting it to a data set, and then displaying a scatter plot with our predictions. As you can see, at about 14% projected return, there's a jump from 100% confidence that the answer is zero or negative to 100% cnce that the answer is one or positive. This isn't a perfect model because ideally we would want our model to tell us how confident it is, and the more we move into that 10 to 15% projected return level, we should be less confident. We can fix that by curving the model with L one and L two regularization, which is the coefficient penalty factor that you learned about when we were talking about regression models. We use that to predict probabilities and represent a confidence level. In this code block, we're simply adding the C element to include a regularization penalty, and when you look at the scatterplot below, you can see that this softens out our predictions and gives us a curve representing the confidence of our predictions. Unlike the linear regression, that first example with the diagonal line cutting across our scatterplot, the logistic regression makes predictions with high confidence when investors are almost certain to decline or almost certain to participate, and low confidence in the middle of our scatterplot. When investors may go either way. That's exactly what you want because now your logistic regression is giving you a good approximation of reality and the relationship that you're trying to model in your data.