The loss function helps algorithms to update model parameters during training through measuring the error, which is an indication of predictive performance. Loss function is usually denoted as follows:
Where L measures the difference between the prediction and the actual value. During the training process, this error is minimized. Different algorithms have different loss functions, and the number of iterations will depend on convergence conditions.
For example, the loss function for k-means minimizes the square distances between a points and closest cluster mean as follows:
You will see detailed implementation in the following section.