09.05.2023 Views

pdfcoffee

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 3

Logistic regression is used in classification problems. For example, when looking at

medical data, we can use logistic regression to classify whether a person has cancer

or not. In case the output categorical variable has two or more levels, we can use

multinomial logistic regression. Another common technique used for two or more

output variables is one versus all.

For multiclass logistic regression, the cross-entropy loss function is modified as:

pp

llllllll = ∑ ∑ YY iiii log (YY haaaaiiii )

ii=1

Where K is the total number of classes. You can read more about logistic regression

at https://en.wikipedia.org/wiki/Logistic_regression.

Now that you have some idea about logistic regression, let us see how we can apply

it to any dataset.

Logistic regression on the MNIST dataset

Next, we will use the Estimator classifier available in TensorFlow estimator to

classify handwritten digits. We will be using the MNIST (Modified National

Institute of Standards and Technology) dataset. For those working in the field of

deep learning, MNIST is not new, it is like the ABC of machine learning. It contains

images of handwritten digits and a label for each image, indicating which digit it is.

The label contains a value lying between 0-9 depending upon the handwritten digit.

The classifier Estimator takes in the features and the labels. It converts them to onehot

encoded vectors, that is, we have 10 bits representing the output. Each bit can

have a value of either 0 or 1, and being one-hot means that for each image in the

label Y only 1 bit out of the 10 will have a value of 1, and the rest will be 0s. In the

following, you can see the image of a handwritten numeral 5, along with its one-hot

encoded value [0 0 0 0 0 0 0 0 1 0].

kk

jj=1

[ 103 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!