6
$\begingroup$

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.

$\endgroup$

1 Answer 1

3
$\begingroup$

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:

enter image description here

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. enter image description here

If you manage to find the error or the solution conclusively, please post it here so that we can all learn.

Hope this helps!

$\endgroup$
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.