Advertisement
brandblox

Lab_ML(07/04/25)

Apr 7th, 2025
352
1
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.43 KB | None | 1 0
  1. # %%
  2. import matplotlib.pyplot as plt
  3. import seaborn as sns
  4. import numpy as np
  5.  
  6. # %%
  7. yield_apples =[0.895, 0.91, 0.919, 0.926, 0.929, 0.931]
  8. plt.plot(yield_apples)
  9.  
  10. # %%
  11. years = [2010, 2011, 2012, 2013, 2014, 2015]
  12. yield_apples =[0.895, 0.91, 0.919, 0.926, 0.929, 0.931]
  13.  
  14. # %%
  15. plt.plot(years,yield_apples)
  16. plt.xlabel('years')
  17. plt.ylabel('Yield (Tons per hectere)')
  18.  
  19. # %%
  20. years = range(2000, 2012)
  21. apples = [0.895, 0.91, 0.919, 0.929, 0.931, 0.934, 0.936, 0.937, 0.9375, 0.9372, 0.939, 0.940]
  22. oranges = [0.962, 0.941, 0.930, 0.923, 0.918, 0.908, 0.907, 0.904, 0.901, 0.898, 0.9, 0.896]
  23.  
  24.  
  25. # %%
  26. sns.set_style("whitegrid")
  27. plt.plot(years, apples, label='Apples', marker = 'o')
  28. plt.plot(years, oranges, label='Oranges', marker = 'x')
  29. plt.xlabel('Year')
  30. plt.ylabel('Yield')
  31. plt.title('Yield of Apples and Oranges (2000-2011)')
  32. plt.legend()
  33.  
  34. plt.show()
  35.  
  36. # %%
  37. sns.set_style("whitegrid")
  38. plt.figure(figsize=(12,6))
  39. plt.plot(years,oranges,marker = 'o')
  40. plt.title("Yeild of Ornages")
  41.  
  42. # %%
  43. years = range(2000,2006)
  44. apples = [0.35,0.6,0.9,0.8,0.65,0.8]
  45. oranges = [0.4,0.8,0.9,0.7,0.6,0.8]
  46.  
  47. # %%
  48. sns.set_style("whitegrid")
  49. plt.bar(years,oranges)
  50. plt.xlabel('Year')
  51. plt.ylabel('Yield')
  52. plt.title("Crop Yield")
  53.  
  54. # %%
  55. sns.set_style("whitegrid")
  56. plt.bar(years,oranges)
  57. plt.bar(years,apples, bottom=oranges)
  58. plt.xlabel('Year')
  59. plt.ylabel('Yield')
  60. plt.title("Crop Yield")
  61.  
  62. # %%
  63. tips_df = sns.load_dataset("tips")
  64. tips_df
  65.  
  66. # %%
  67. sns.barplot(x='day',y='total_bill', data=tips_df)
  68.  
  69. # %%
  70. sns.barplot(x='day',y='total_bill',hue='sex', data=tips_df)
  71.  
  72. # %%
  73. sns.barplot(x='total_bill',y='day',hue='sex', data=tips_df)
  74.  
  75. # %%
  76. flower_df = sns.load_dataset("iris")
  77. flower_df.sepal_width
  78.  
  79. # %%
  80. plt.title('Distribution of Sepal width')
  81. plt.hist(flower_df.sepal_width)
  82.  
  83. # %%
  84. plt.hist(flower_df.sepal_width, bins=5)
  85.  
  86. # %%
  87. setosa_df = flower_df[flower_df.species == 'setosa']
  88. versicolor_df = flower_df[flower_df.species == 'versicolor']
  89. virginica_df = flower_df[flower_df.species == 'virginica']
  90.  
  91.  
  92. # %%
  93. plt.hist(setosa_df.sepal_width, alpha=0.4, bins=np.arange(2, 5, 0.25), label='Setosa')
  94. plt.hist(versicolor_df.sepal_width, alpha=0.4, bins=np.arange(2, 5, 0.25), label='Versicolor')
  95.  
  96. # %%
  97. plt.title('Distribution of Sepal width')
  98. plt.hist([setosa_df.sepal_width, versicolor_df.sepal_width, virginica_df.sepal_width],
  99.          bins=np.arange(2,5,0.25),
  100.          stacked=True)
  101. plt.legend(['Setosa','Versicolor','Virginica'])
  102.  
  103.  
  104.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement