Machine Learning Basics·Machine learning from data to a responsible model

Classification

Predict a class with logistic regression and read probabilities carefully.

Intermediate 15 min read Lesson 5 of 300 Challenge included
What you will be able to do
  • Use predict_proba to inspect confidence.
  • Choose the threshold based on costs.
  • Report precision and recall, not only accuracy.
  • Check class balance before trusting accuracy.

In plain English

Classification predicts a category. Logistic regression outputs a probability that is converted to a class by a threshold. The threshold is a product decision, not a law of nature.

classification.pyPython
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import classification_report

model = LogisticRegression(max_iter=1000).fit(X_train, y_train)
pred = model.predict(X_test)
print(classification_report(y_test, pred))
Your turn

Predict probabilities

Medium

Fit logistic regression and return the probability of the positive class.

PYTHON · starter
model.predict(X_test)
Check your understanding before moving on.
Knowledge checkQuestion 1

Why can accuracy be misleading?

Select an answer to continue
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Next: Evaluation
Lesson 5 of 300 · 0% of course