Learning "Andrew Ng: Machine Learning" Job linear regression matrix and array

Andrew Ng teacher just started learning machine learning, read the first few chapters, looking after class exercises timely to consolidate under their own learning, which is linked Gangster
Andrew Ng job machine learning Python implementation (a): Linear regression
https: // blog.csdn.net/Cowry5/article/details/80174130
when you run this program, bloggers using a matrix, because before I did not come into contact with this function, only learned array, so that I will be the source of a few this line changed

#我写的
X = np.array(X.values)
y = np.array(y.values)
theta = np.array([0,0])
#源程序
#X = np.matrix(X.values)
#y = np.matrix(y.values)
#theta = np.matrix([0,0])

The results of the initial value of the operating results of the first cost function on and Bowen is not the same value twice as big, and then I started to check for errors, suspect may be matrix array and the two are different, I went to tried it .
Here Insert Picture Description
Sure enough, two operating results are not the same, checked the relevant information, posted links to big brother to explain in great detail:
https://blog.csdn.net/autoliuweijie/article/details/51967288
HTTPS: // www.cnblogs.com/keye/p/11195428.html

Finally understand, so the program will be changed to this:

X = np.array(X.values)
y = np.array(y.values)
theta1 = np.array([[0,0]])
theta = np.asmatrix(theta1)

problem solved

Published 25 original articles · won praise 0 · Views 445

Guess you like

Origin blog.csdn.net/qq_45445740/article/details/104011338