Guest User

Untitled

a guest
Nov 17th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. import numpy as np
  2. import pandas as pd
  3. import matplotlib.pyplot as plt
  4. import seaborn as sns
  5. %matplotlib inline
  6.  
  7. human_resources = sns.load_dataset("humanresources")
  8. print(human_resources.head(n=4))
  9.  
  10. #Creating a PointPlot
  11. sns.set(style="whitegrid")
  12.  
  13. g = sns.factorplot(x="time_spend_company", y="satisfaction_level", hue="salary", data=human_resources,
  14. size=5, kind="point", palette="pastel", ci=95, dodge=True, join=False)
  15. g.despine(left=True)
  16. g.set_ylabels("Satisfaction Level")
  17. g.set_xlabels("")
  18. plt.title('Pointplot: Years in the Company against Satisfaction Level')
  19. plt.show()
  20.  
  21. #Employees who have worked between 3-6 years tend to have the lowest satisfaction levels,
  22. #vs those who have been there for <3 years, or more than 6 years.
  23. #Data also indicates that in general, those in the high income salary do not tend to have higher satisfaction levels.
  24. #Contrary to popular belief that money is a primary factor affecting employee job satisfaction!
  25.  
  26. sns.set(style="darkgrid")
  27. cp = sns.factorplot(x="promotion_last_5years", y="satisfaction_level", hue="salary", data=human_resources,
  28. size=5, kind="bar", palette="pastel", ci=95)
  29. cp.despine(left=True)
  30. cp.set_ylabels("Job Satisfaction")
  31. cp.set_xlabels("Promotion in the last 5 years")
  32. plt.title('Barplot: Career progression against Job Satisfaction')
  33. plt.show()
  34.  
  35. #Generally, employees who got promoted in the last 5 years tend to indicate higher job satisfaction.
  36. #This change was however minimal for those in the high salary bracket.
  37. #Further indicating that money is not the primary factor affecting job satisfaction!
  38.  
  39. sns.set(style="darkgrid")
  40. cp = sns.factorplot(x="salary", y="average_monthly_hours", hue="left", data=human_resources,
  41. size=5, kind="bar", palette="pastel", ci=95)
  42. cp.despine(left=True)
  43. cp.set_ylabels("Average Monthly Hours at Work Place")
  44. cp.set_xlabels("Salary Brackets")
  45. plt.title('Barplot: Time spent at work place against Salary')
  46. plt.show()
  47. #Generally people who left in the low and medium income brackets tend to have worked longer hours.
  48. #Except for those in the high salary brackets (once again!). In fact these group of people actually worked shorter hours.
  49.  
  50. # Showing the information in a seaborn facet grid.
  51. sns.set(style="ticks") #Setting the overall aesthetic
  52.  
  53. # Tell seaborn about the structure of our data.
  54. g = sns.FacetGrid(human_resources, row="department", col="salary")
  55. # Name the plot type and the variable to be plotted using the structure.
  56. g.map(plt.hist, "satisfaction_level", color="steelblue", lw=0)
  57. # Moving the plots apart to make room for our titles.
  58. plt.subplots_adjust(top=0.9)
  59. # Making a more informative axis name.
  60. g.set_axis_labels('Satisfaction Levels')
  61. plt.suptitle('Satisfaction Levels by Department and Salary')
  62. # Removing excess lines around the plot.
  63. sns.despine(trim=True)
  64. plt.show()
  65.  
  66. #FacetGrid shows the satisfaction breakdown by department, and salary.
  67. #Sales had the largest number of employees, followed by technical and support staff
  68. #Data shows employees were moderate to adequately satisfied.
  69.  
  70. fig = plt.figure(figsize=(6,4))
  71. ax=sns.kdeplot(human_resources.loc[(human_resources['left'] == 0),'average_monthly_hours'] , color='b',shade=True, label='Stayed')
  72. ax=sns.kdeplot(human_resources.loc[(human_resources['left'] == 1),'average_monthly_hours'] , color='r',shade=True, label='Left')
  73. plt.title('Average monthly hours worked')
  74. #People who left either worked little hours, or worked more than 250 hours.
  75. #Employees who stayed worked an average of 150-250 hours.
Add Comment
Please, Sign In to add comment