Skip to content

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

@DLotts

Description

@DLotts

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions