Logistic regression is borrowed from statistics. You can use this for classification problems. Given an image, is it class 0 or class 1?

The word “logistic regression” is named after its function “the logistic”. You may know this function as the sigmoid function.

## Introduction

### Sigmund function

Logisitic regression uses the sigmund function for classification problems. What is this function exactly?

The sigmund function is:

It’s an s-shaped curve.

Why use the signmund function for prediction? The s-shaped curve is kind of strange, isn’t it?

Classifications in prediction problems are probabilistic. The model shouldn’t be below zero or higher than one, the s-shaped curve helps to create that. Because of the limits, it can be used for binary classification.

## Sigmund function in logistic regression

The function can be used to make predictions.

The variable b0 is the bias and b1 is the coefficient for the single input value (x)
This can be rewritten as

or

To make predictions, you need b0 and b1.

These values are found with the training data.
Initially we set them to zero:

Tensorflow will take care of that.

Then the model (based on formula) is:

Where’s the exponent?

The softmax function does the equivalent of:

## Logistic regression with handwriting recognition

Lets use logistic regression for handwriting recognition. The MNIST datset contains 28x28 images of handwritten numbers. Each of those is flattened to be a 784 size 1-d vector.

The problem is:

• X: image of a handwritten digit
• Y: the digit value
• Recognize the digit in the image

The model:

• logits = X * w + b
• Y_predicted = softmax(logits)
• loss = cross_entropy(Y, Y_predicted)

The same in code:

Loss is sometimes called cost.

The code below runs the logistic regression model on the handwriting set. Surprisingly the accuracy is 91.43% for this model. Simply copy and run!