Implementation cost function in logistic regression in python using numpy

I am implementing the cost function for logistic regression and have a question. The formulation for cost function is $J = -\frac{1}{m}\sum_{i=1}^{m}(y^{(i)}\log(a^{(i)})+(1-y^{(i)})\log(1-a^{(i)}))$

So in python I code the function as follow:

cost = -1/m*np.sum(np.dot(Y.T,np.log(A))+ np.dot((1-Y.T),np.log(1-A))) # m=3

however, if I interchange the order of elements in the np.dot as below:

cost = -1/m * np.sum(np.dot(np.log(A), Y.T) + np.dot(np.log(1-A), (1-Y.T)))

Then the outcomes are different. I don't understand why one code is correct and why the other is not correct. Can someone help? Thank you very much!

Topic cost-function implementation logistic-regression python

Category Data Science

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.