Why is the logistic regression cost function scaled by the number of examples? I sometimes see that the cost function, along with the regularizer is divided by 1/2m where m is the number of examples. When we are trying to find the minimum of the cost, why does scaling by this amount matter? It doesn't affect where the minimum is. Example:

 A: I think @soufanom had a good answer. I will try to add on.
In general, there are two reasons to have a constant in loss function.


*

*The first reason is to have a simpler notation later. For example, you can have a loss function $f(y,\hat y)=\frac 1 2(y-\hat y)^2$, take the derivative respect to $y$, you will not have the annoying term $2$.

*The second reason is trying to "normalize" the loss value on number of data points. For example, (let us think about the regression now), suppose you have $10$ data points, and for each data point, you made $1.0$ error, e.g., the ground truth is $3.5$, and your prediction is $2.5$, etc.. Then, your loss for the entire data set is $10.0$. On the other hand, if you have $100$ data points. you still have $1.0$ error for each estimation. Then your loss for entire data is $100$. This does not make too much sense because two models are equal, but applied on different data. If you normalize the loss by number of data (divide the total loss by number of data), then the loss values in above examples will be identical.
A: Building further on the answer by @hxd1011:
Suppose we had a set model -- parameters and all fixed. We would look at the Mean Squared Error as our measure of error.
$MSE =  \frac{1}{m}\sum_{i=1}^m (h_\theta(x^{(i)}) - y^{(i)})^2$
When we regularize using some function of our parameters we add a parameter of the form $\lambda \sum_{j=1}^n f(\theta_j)$ in your case $f(x) = x^2$, but this is a more general concept.
If you don't scale that regularization by your sample size -- then for a given $\lambda$, as $m \rightarrow \infty$, the regularization becomes meaningless. By adding that scaling, we gain two things.


*

*The scale of $\lambda$ becomes stable for different sample sizes. (i.e. you can get a sense of 'how much' you are regularizing) In some contexts (live model updating) this is crucial. 

*This is closely related to the mean loss on our predictions. While that may seem initially less useful than a concept like MSE, if we are regularizing, then it is a desirable feature. 
