Working with Probability Distributions
Sveip for å vise menyen
Understanding probability distributions is essential for analyzing and interpreting data in statistics. A probability distribution describes how the values of a random variable are distributed – the likelihood of each possible outcome. Three of the most common distributions you will encounter are the normal, binomial, and uniform distributions.
The normal distribution is a continuous, bell-shaped curve that is symmetric around its mean. It is defined by two parameters: the mean (μ) and the standard deviation (σ). Many natural phenomena, such as human heights or measurement errors, follow a normal distribution. The mean determines the center of the distribution, while the standard deviation controls the spread.
The binomial distribution is a discrete distribution that models the number of successes in a fixed number of independent trials, each with the same probability of success. It is defined by two parameters: the number of trials (n) and the probability of success (p). Tossing a coin several times and counting the number of heads is a classic example of a binomial distribution.
The uniform distribution is the simplest probability distribution, where all outcomes in a given range are equally likely. The continuous version is defined by two parameters: the lower bound (a) and the upper bound (b). Rolling a fair die or generating a random number between 0 and 1 are examples of uniform distributions.
Each of these distributions helps you model different types of random processes and understand the likelihood of various outcomes.
12345678910111213141516171819202122232425262728293031323334import numpy as np import matplotlib.pyplot as plt # Set random seed for reproducibility np.random.seed(42) # Generate samples normal_samples = np.random.normal(loc=0, scale=1, size=1000) # mean=0, std=1 binomial_samples = np.random.binomial(n=10, p=0.5, size=1000) # 10 trials, p=0.5 uniform_samples = np.random.uniform(low=0, high=1, size=1000) # between 0 and 1 # Plotting fig, axs = plt.subplots(1, 3, figsize=(15, 4)) # Normal distribution axs[0].hist(normal_samples, bins=30, color='skyblue', edgecolor='black', density=True) axs[0].set_title('Normal Distribution\n(mean=0, std=1)') axs[0].set_xlabel('Value') axs[0].set_ylabel('Density') # Binomial distribution axs[1].hist(binomial_samples, bins=np.arange(-0.5, 11.5, 1), color='salmon', edgecolor='black', density=True) axs[1].set_title('Binomial Distribution\n(n=10, p=0.5)') axs[1].set_xlabel('Number of Successes') axs[1].set_ylabel('Probability') # Uniform distribution axs[2].hist(uniform_samples, bins=30, color='lightgreen', edgecolor='black', density=True) axs[2].set_title('Uniform Distribution\n(low=0, high=1)') axs[2].set_xlabel('Value') axs[2].set_ylabel('Density') plt.tight_layout() plt.show()
Takk for tilbakemeldingene dine!
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår