Чтобы визуализировать распределение Пуассона с помощью NumPy, вы можете использовать различные методы. Вот несколько примеров кода:
Метод 1: гистограмма
import numpy as np
import matplotlib.pyplot as plt
# Parameters for the Poisson distribution
lambda_val = 5
size = 1000
# Generate random numbers from the Poisson distribution
data = np.random.poisson(lambda_val, size)
# Plotting the histogram
plt.hist(data, bins=20, density=True, alpha=0.7)
plt.xlabel('Values')
plt.ylabel('Frequency')
plt.title('Histogram of Poisson Distribution')
plt.show()
Метод 2: график функции массы вероятности (PMF)
import numpy as np
import matplotlib.pyplot as plt
# Parameters for the Poisson distribution
lambda_val = 5
# Generate x-values
x = np.arange(0, 20)
# Calculate the Poisson PMF for each x-value
pmf = np.exp(-lambda_val) * np.power(lambda_val, x) / np.math.factorial(x)
# Plotting the PMF
plt.plot(x, pmf, 'bo-', linewidth=2)
plt.xlabel('X')
plt.ylabel('Probability')
plt.title('Probability Mass Function of Poisson Distribution')
plt.show()
Метод 3: график кумулятивной функции распределения (CDF)
import numpy as np
import matplotlib.pyplot as plt
# Parameters for the Poisson distribution
lambda_val = 5
# Generate x-values
x = np.arange(0, 20)
# Calculate the Poisson CDF for each x-value
cdf = np.cumsum(np.exp(-lambda_val) * np.power(lambda_val, x) / np.math.factorial(x))
# Plotting the CDF
plt.plot(x, cdf, 'bo-', linewidth=2)
plt.xlabel('X')
plt.ylabel('Cumulative Probability')
plt.title('Cumulative Distribution Function of Poisson Distribution')
plt.show()
Метод 4: ящичная диаграмма
import numpy as np
import matplotlib.pyplot as plt
# Parameters for the Poisson distribution
lambda_val = 5
size = 100
# Generate random numbers from the Poisson distribution
data = np.random.poisson(lambda_val, size)
# Plotting the box plot
plt.boxplot(data)
plt.xlabel('Distribution')
plt.ylabel('Values')
plt.title('Box Plot of Poisson Distribution')
plt.show()