FirstHack Learn
Log in Sign up free
Lessons in this course 0/6 All courses Machine Learning Foundations

AI & DS

Progress0 / 6 lessons
  1. 1. What learning from data means, and when ML is the wrong tool
  2. 2. Supervised vs unsupervised learning
  3. 3. Linear regression from scratch, then with scikit-learn
  4. 4. Classification, logistic regression and the confusion matrix
  5. 5. Overfitting, train/test split and cross-validation
  6. 6. Why accuracy is a bad metric on imbalanced data

Courses › Machine Learning Foundations

Classification, logistic regression and the confusion matrix

Predict a category, then look at the four numbers that describe every mistake.

13 min read · Lesson 4 of 6 · Pro

Why not linear regression for yes or no

You want to predict pass (1) or fail (0). A straight line will happily output 1.4 or -0.2, and neither is a valid answer. It also has no notion of confidence.

Logistic regression fixes this by squeezing the line's output through the sigmoid function:

Python 3
import numpy as np

def sigmoid(z):
    return 1 / (1 + np.exp(-z))

print(sigmoid(np.array([-6, -2, 0, 2, 6])).round(4))
# [0.0025 0.1192 0.5    0.8808 0.9975]

Any input, from minus infinity to plus infinity, comes out between 0 and 1. That output is read as a probability. Above 0.5 you call it class 1, below 0.5 class 0. Despite the name, logistic regression is a classifier.

The rest of this lesson is Pro

The free lessons of Machine Learning Foundations finish what they start — read those first if you have not. This one goes further, and it is part of the paid half.

A pass opens the paid lessons of every course, the mock test papers and the company-wise series. It ends on its own date; nothing renews by itself.

Get a pass — from ₹29 for 7 days

Already bought one? Log in.