Why do you don’t use
`cost = cost / - m` outside cycle `for` in the compute_cost_logistic()?

Instead, you multiply every Cost’s element inside cycle ‘for’:

``````for i in range(m):
...
cost +=  - y[i]*np.log(f_wb_i) - (1-y[i])*np.log(1-f_wb_i)
``````

I don’t understand, because in the lesson “Simplified Cost Function for Logistic Regression” I see that

and if I try multiply expression to ‘-’ after calculate cost, like this:

``````for i in range(m):
...
cost +=  y[i]*np.log(f_wb_i) - (1-y[i])*np.log(1-f_wb_i)

total_cost = cost/-m
``````

I get another result by comparison when I multiple to “-” inside cycle `for.`

Hi Tata_P!
I request you to post your queries under specific tags so that you can get help quickly and your post doesn’t get lost in the lot. For example, if the query is regarding some assignment in the MLS, then post it under MLS (Specify course and assignment number too) not in general discussions.
And coming to your question, you are making this silly mistake here so that you are getting a different answer :

`-(1/m)*(y[i]*np.log(f_wb_i) + (1-y[i])*np.log(1-f_wb_i))` is equivalent to `(1/m)*(-y[i]*np.log(f_wb_i) - (1-y[i])*np.log(1-f_wb_i))` ,
not `(y[i]*np.log(f_wb_i) - (1-y[i])*np.log(1-f_wb_i))`. Else, the implementation is the same, so it doesn’t matter if you are multiplying -1 outside or inside.

Regards,
Nithin

Hi, Nithin!