Advertisement
mirosh111000

Мат_Стат_Мірошниченко_СР№2.1

Sep 18th, 2024
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.89 KB | None | 0 0
  1. import numpy as np
  2. import pandas as pd
  3. import scipy.stats as stats
  4. import matplotlib.pyplot as plt
  5. from IPython.display import Latex
  6.  
  7. data = [3.31, 1.15, 2.44, 0.82, 1.50, 2.53, 2.18, 3.20,
  8.         2.85, 2.27, 1.97, 0.98, 3.51, 2.42, 2.09, 2.83,
  9.         2.76, 0.18, 1.61, 2.21, 2.33, 3.06, 1.70, 2.44,
  10.         1.82, 3.02, 3.63, 1.52, 2.01, 2.17, 2.63, 1.94,
  11.         2.49, 2.31, 2.37, 1.03, 2.06, 0.67, 2.79, 2.42,
  12.         2.95, 0.45, 1.20, 1.61, 2.35, 1.73, 0.82, 1.10,
  13.         1.94, 2.14, 2.28, 2.54, 1.85, 2.40, 1.94, 1.30,
  14.         1.62, 2.03, 2.00, 2.70, 2.33, 2.86, 3.26, 1.71,
  15.         2.70, 2.96, 2.89, 0.73, 1.01, 1.85, 2.79, 3.10,
  16.         2.42, 3.12, 2.43, 1.85, 1.21, 1.53, 2.95, 1.22]
  17.  
  18. desc_stats = pd.DataFrame(columns=['Valid N', 'Mean', 'Min', 'Max', 'Std.Dev.', 'Skewness', 'Kurtosis'], index=['Value'])
  19. desc_stats.loc['Value'] = [len(data), np.mean(data), min(data), max(data), np.std(data), stats.skew(data), stats.kurtosis(data)]
  20. print(desc_stats)
  21.  
  22.  
  23. counts, bin_edges, _ = plt.hist(data, bins=10, edgecolor='black')
  24. plt.xticks(ticks=bin_edges, rotation=45, ha='right')
  25. plt.title('Гістограма')
  26. plt.xlabel('Інтервали')
  27. plt.ylabel('Частота')
  28. plt.show()
  29.  
  30. # Розрахунок ймовірності для інтервалу P(1.22 < X < 1.84)
  31. mean = np.mean(data)
  32. std_dev = np.std(data)
  33.  
  34. # Функція нормального розподілу
  35. prob_1_22 = stats.norm.cdf(1.84, mean, std_dev) - stats.norm.cdf(1.22, mean, std_dev)
  36. display(Latex(f"Ймовірність $P(1.22 < X < 1.84): {round(prob_1_22*100, 2)}$%"))
  37.  
  38. lower_bound = mean*0.9
  39. upper_bound = mean*1.1
  40.  
  41. prob_lower = stats.norm.cdf(lower_bound, mean, std_dev)
  42. prob_upper = stats.norm.cdf(upper_bound, mean, std_dev)
  43.  
  44. probability = prob_upper - prob_lower
  45. percentage = probability * 100
  46.  
  47. display(Latex(f"Випуск придатної продукції: ${round(percentage, 2)}$%"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement