Perceptron algorithm
But, in some cases it doesn't work properly.


As you did not provide your data, I can only make a bold assumption.
The perceptron can only classify linear separably data and will not converge for not-linearly separable data. Thus, this could be a reason for the unintended behaviour.

Cheers!