You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

nn_3.py 1.2 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. %matplotlib nbagg
  2. from sklearn.metrics import accuracy_score
  3. import matplotlib.pyplot as plt
  4. import matplotlib.animation as animation
  5. fig = plt.figure()
  6. imgs = []
  7. y_true = np.array(nn.y).astype(float)
  8. # back-propagation
  9. def backpropagation(n, X, y):
  10. for i in range(n.n_epoch):
  11. # forward to calculate each node's output
  12. forward(n, X)
  13. # print loss, accuracy
  14. L = np.sum((n.z2 - y)**2)
  15. y_pred = np.zeros(nn.z2.shape[0])
  16. y_pred[np.where(nn.z2[:,0]<nn.z2[:,1])] = 1
  17. acc = accuracy_score(y_true, y_pred)
  18. print("epoch [%4d] L = %f, acc = %f" % (i, L, acc))
  19. # calc weights update
  20. d2 = n.z2*(1-n.z2)*(y - n.z2)
  21. d1 = n.z1*(1-n.z1)*(np.dot(d2, n.W2.T))
  22. # update weights
  23. n.W2 += n.epsilon * np.dot(n.z1.T, d2)
  24. n.b2 += n.epsilon * np.sum(d2, axis=0)
  25. n.W1 += n.epsilon * np.dot(X.T, d1)
  26. n.b1 += n.epsilon * np.sum(d1, axis=0)
  27. # plot animation
  28. #img = plt.scatter(X[:, 0], X[:, 1], c=y_pred, cmap=plt.cm.Spectral)
  29. #imgs.append(img)
  30. nn.n_epoch = 2000
  31. backpropagation(nn, X, t)
  32. #ani = animation.ArtistAnimation(fig, imgs)
  33. #plt.show()

机器学习越来越多应用到飞行器、机器人等领域,其目的是利用计算机实现类似人类的智能,从而实现装备的智能化与无人化。本课程旨在引导学生掌握机器学习的基本知识、典型方法与技术,通过具体的应用案例激发学生对该学科的兴趣,鼓励学生能够从人工智能的角度来分析、解决飞行器、机器人所面临的问题和挑战。本课程主要内容包括Python编程基础,机器学习模型,无监督学习、监督学习、深度学习基础知识与实现,并学习如何利用机器学习解决实际问题,从而全面提升自我的《综合能力》。