# How to determine threshold in Sigmoid function

Context:

I picked up data-set from here and tried to run Logistic Regression on it. Since I am not very much aware of MATLAB, I converted "Strings" to "Numbers" with my own using "NUMBERS" software.

What I want to achieve:

After running the LR algorithm when I tried to predict the value of existing data points, I am getting values ranging between 0-1 (as it should be), but since my job it to predict whether it is either 0 (yes) or 1 (no), that means I need to find a cut-off line (threshold) in my prediction (This could probably be done by comparing actual value by predicted value).

Question:

How can I figure out the threshold for predicted result such that result is assumed to be 1 if predicted value > threshold, otherwise 0?

Predicted values can be found here. I am assuming predicted values are correct as cost curve is showing asymptotic nature. I have pushed my work here, you may want to cross-validate and provide me few more key points.

As per Andrew Ng's Course, if you use the sigmoid activation, the outputs represent the probability of either outcome 0 or outcome 1.

So the decision boundary is 0.5

if prediction > 0.5 , the prediction is 1

if prediction <= 0.5 , the prediction in 0

Here's a screenshot from Andrew Ng's slides: I have gone through your code and results. There seems to be something wrong with the implementation as none of your predictions give a value greater than 0.5 .

I couldn't pin down the problem. Some debugging will be needed on your side.

What's paradoxical is that your loss is reducing. I suspect this might be because your data set is unbalanced i.e., you have 221 0s and about 30 1s. This could be the reason for other problems as well.

Consider the wikipedia example, where the values are correctly matching. If you manage to find the error or the solution conclusively, please post it here so that we can all learn.

Hope this helps!

• If data is unbalanced, the OP could use class weights... sklearn logistic regression uses: n_samples / (n_classes * bincount(y)). Sep 1 '17 at 7:58