Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. # Creating Gaussian Plot Function
  2. def gaussianPlotter(vector):
  3. """
  4. Calculates and plots a Gaussian Probability Density Function (PDF)
  5.  
  6. Parameters
  7. ----------
  8. vector : array-like, shape (n_samples, n_features)
  9.  
  10. Returns
  11. -------
  12. output : matplotlib plt.plot()
  13. """
  14. mean = vector.mean()
  15. std_dev = vector.std()
  16. normal_pdf = (1/np.sqrt(2*np.pi*std_dev**2))*np.exp(-((vector.sort_values() - mean)**2)/(2*std_dev**2))
  17. plt.plot(vector.sort_values(), normal_pdf, color= 'red', label= 'Normal PDF')
  18.  
  19. # Creates the figure, title, and labels
  20. # Plots a Frequency distribution along w/ a Kernel Density Estimate
  21. plt.figure(figsize= (10,5))
  22.  
  23. ## Gaussian Kernel is used to estimate a Gaussian PDF
  24. sns.distplot(features_DSH, bins= 10, kde= True, color= '#1f77b4',
  25. kde_kws= {'kernel': 'gau', 'label': 'KDE: Estimated PDF',
  26. 'color': 'black', 'lw': 3})
  27.  
  28. ## Gaussian PDF plotting function
  29. gaussianPlotter(features_DSH)
  30.  
  31. ## Plot Labels
  32. plt.title('Frequency & Probability Distribution of Study Times');
  33. plt.ylabel('Kernel Density Estimate');
  34. plt.xlim(25, 71)
  35. plt.legend(loc= 'best')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement