Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why the transpose of y in the Python but not the matlab version? #47

Open
DLotts opened this issue May 13, 2021 · 0 comments
Open

Why the transpose of y in the Python but not the matlab version? #47

DLotts opened this issue May 13, 2021 · 0 comments

Comments

@DLotts
Copy link

DLotts commented May 13, 2021

s = np.power(( X.dot(theta) - np.transpose([y]) ), 2)

Matlab/Octave:

J = (1/(2*m)) *sum( (((X*theta)-y).^2))

Python :

s = np.power(( X.dot(theta) - np.transpose([y]) ), 2)
J = (1.0/(2*m)) * s.sum( axis = 0 )

They look equivalent except the python has that np.transpose([y])
Why is it needed?

BTW, My Octave version of this cost function is the same as yours.

This is probably not a bug, but it is confusing. You've done a nice job of doing the Python version. It would be an improvement to at least comment on that. I really wanted to do the assignment in NumPy, but Ng's tutorial on Matlab was so easy to follow that I just did the Octave version. Now I can compare the syntax. A Tabla Rosa!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant