Key Concepts

Review core concepts you need to learn to master this subject

Scikit-Learn Logistic Regression Implementation

Scikit-Learn has a Logistic Regression implementation that fits a model to a set of training data and can classify new or test data points into their respective classes. All important parameters can be specified, as the norm used in penalizations and the solver used in optimization.

Logistic Regression
Lesson 1 of 1
  1. 1
    When an email lands in your inbox, how does your email service know whether it’s real or spam? This evaluation is made billions of times per day, and one possible method is logistic regression. _…
  2. 2
    With the data from Codecademy University, we want to predict whether each student will pass their final exam. Recall that in linear regression, we fit a line of the following form to the data: y =…
  3. 3
    We saw that predicted outcomes from a linear regression model range from negative to positive infinity. These predictions don’t really make sense for a classification problem. Step in _**logistic r…
  4. 4
    So far, we’ve learned that the equation for a logistic regression model looks like this: ln(\frac{p}{1-p}) = b_{0} + b_{1}x_{1} + b_{2}x_{2} +\cdots + b_{n}x_{n} Note that we’ve replaced y wit…
  5. 5
    Let’s return to the logistic regression equation and demonstrate how this works by fitting a model in sklearn. The equation is: ln(\frac{p}{1-p}) = b_{0} + b_{1}x_{1} + b_{2}x_{2} +\cdots + b_{n}x…
  6. 6
    Now that we’ve learned a little bit about how logistic regression works, let’s fit a model using [sklearn](http://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.h…
  7. 7
    Using a trained model, we can predict whether new datapoints belong to the positive class (the group labeled as 1) using the .predict() method. The input is a matrix of features and the output is a…
  8. 8
    As we’ve seen, logistic regression is used to predict the probability of group membership. Once we have this probability, we need to make a decision about what class a datapoint belongs to. This is…
  9. 9
    When we fit a machine learning model, we need some way to evaluate it. Often, we do this by splitting our data into training and test datasets. We use the training data to fit the model; then we us…
  10. 10
    Once we have a confusion matrix, there are a few different statistics we can use to summarize the four values in the matrix. These include accuracy, precision, recall, and F1 score. We won’t go int…
  11. 11
    Congratulations! You just learned how a logistic regression model works and how to fit one to a dataset. Here are some of the things you learned: * Logistic regression is used to perform binary cla…

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo