[pycon] Task 2

Viewer

  1. D = np.genfromtxt("./iris.csv", delimiter=",",skip_header=1)
  2.  
  3. def pdf_multivariate_gauss(x, mu, cov):
  4.     part1 = 1 / ( ((2* np.pi)**(len(mu)/2)) * (np.linalg.det(cov)**(1/2)) )
  5.     part2 = (-1/2) * ((x-mu).T.dot(np.linalg.inv(cov))).dot((x-mu))
  6.     return float(part1 * np.exp(part2))
  7.  
  8. # add code and markdown cells as needed
  9. D0 = D[D[:,4] == 0]
  10. D0 = D0[:, 0:4]
  11. D1 = D[D[:,4] == 1]
  12. D1 = D1[:, 0:4]
  13. D2 = D[D[:,4] == 2]
  14. D2 = D2[:, 0:4]
  15. mu0 = D0.mean(axis=0)
  16. mu1 = D1.mean(axis=0)
  17. mu2 = D2.mean(axis=0)
  18. cov0 = np.cov(D0.T)
  19. cov1 = np.cov(D1.T)
  20. cov2 = np.cov(D2.T)
  21. p0 = len(D[D[:,4] == 0])/(len(D)-1)
  22. p1 = len(D[D[:,4] == 1])/(len(D)-1)
  23. p2 = len(D[D[:,4] == 2])/(len(D)-1)

Editor

You can edit this paste and save as new:


File Description
  • Task 2
  • Paste Code
  • 01 Mar-2021
  • 690 Bytes
You can Share it: