Do I have to start logistic regression with weights = 0?

I'm confused about logistic regression cost function. What if in some test data is bad prediction? Then one of the terms in sum is equal to infinity and sum of anything with one infinity member is equal to infinity. It means, that the cost function is also equal to infinity. Here is the cost function:

I have an idea and I can't find any proof. The idea is to start with weights equal to zero, then all logarithms have parameters equal to 0.5, then log(0.5) is not infinity and you can run gradient descent or whatever to minimize the cost. Am I right?

• What do you mean "bad prediction"? How can a single prediction lead to infinity? – HelloWorld Feb 19 '17 at 12:00
• I admit I don't really quite understand the question. – HelloWorld Feb 19 '17 at 12:01

By "bad prediction" do you mean e.g. $y^{(i)} = 1$ and $h(x^{(i)}) = 0$? That would indeed lead to an infinite loss – but luckily, for any finite weight vector, $h$ is never going to actually achieve values 0 or 1, and $\log h$ will always be finite.
The only way that $J$ can actually become infinite is if the problem is linearly separable, in which case driving all the predictions to exactly 0 and 1 becomes the optimal solution. This is usually avoided via regularization.