# Parameter of the Bernoulli distributionp =0.4# Probability of success (1)# Possible values of the Bernoulli random variablex = [0, 1]# Calculation of probability mass functionpmf_values = bernoulli.pmf(x, p)# Creating the plotbar_width =0.3x_pos = np.array([0, 0.6]) # Adjust these values to change the spacingplt.bar(x_pos, pmf_values, width=bar_width, color='blue', alpha=0.7, label='Bernoulli Distribution')# Setting labels and titleplt.title(f'Bernoulli Distribution (p = {p:.2f})')plt.xlabel('Value')plt.ylabel('Probability Mass')plt.xticks(x_pos, ['0', '1']) # Set x-ticks at bar positionsplt.legend()plt.grid(True, axis='y', linestyle='--', alpha=0.7) # Adds horizontal grid to improve readability# Set x-axis limits to focus on the barsplt.xlim(-0.2, 0.8)plt.show()
Binomial distribution
# Binomial Distributionn =4# Number of trialsp =0.5# Probability of successx = np.arange(0, n+1)# Calculate PMFpmf_values = binom.pmf(x, n, p)# Create the plotbar_width =0.8plt.bar(x, pmf_values, width=bar_width, color='blue', alpha=0.7, label='Binomial Distribution')# Set labels and titleplt.title(f'Binomial Distribution (n={n}, p={p})')plt.xlabel('Number of Successes')plt.ylabel('Probability')# Set x-ticks to integersplt.xticks(x)# Add legend and gridplt.legend()plt.grid(True, axis='y', linestyle='--', alpha=0.7)# Adjust x-axis limits for better appearanceplt.xlim(-0.5, n+0.5)plt.show()
Poisson distribution
# Poisson Distributionlam =5# Rate or mean number of eventsx = np.arange(0, 20)# Calculate PMFpmf_values = poisson.pmf(x, lam)# Create the plotbar_width =0.8plt.bar(x, pmf_values, width=bar_width, color='blue', alpha=0.7, label='Poisson Distribution')# Set labels and titleplt.title(f'Poisson Distribution (λ = {lam})')plt.xlabel('Number of Events')plt.ylabel('Probability')# Set x-ticksplt.xticks(np.arange(0, 20, 2)) # Set x-ticks every 2 units for better readability# Add legend and gridplt.legend()plt.grid(True, axis='y', linestyle='--', alpha=0.7)# Adjust x-axis limits for better appearanceplt.xlim(-0.5, 19.5)plt.show()
Uniform distribution
# Uniform Distributiona =0# Lower boundb =10# Upper bound# Generate x valuesx = np.linspace(a-1, b+1, 1000)# Calculate PDFpdf_values = uniform.pdf(x, loc=a, scale=b-a)# Create the plotplt.figure(figsize=(10, 6))plt.plot(x, pdf_values, color='blue', linewidth=2, label='Uniform Distribution')# Fill the area under the curve within the boundsplt.fill_between(x, pdf_values, where=((x >= a) & (x <= b)), color='blue', alpha=0.3)# Set labels and titleplt.title(f'Uniform Distribution (a={a}, b={b})')plt.xlabel('Value')plt.ylabel('Probability Density')# Add legend and gridplt.legend()plt.grid(True, linestyle='--', alpha=0.7)# Set axis limitsplt.xlim(a-1, b+1)plt.ylim(0, uniform.pdf(a, loc=a, scale=b-a) *1.1)# Add vertical lines at boundsplt.axvline(x=a, color='gray', linestyle='--')plt.axvline(x=b, color='gray', linestyle='--')plt.show()
Chi square distribution
# Set range for degrees of freedomdegrees_of_freedom =range(1, 11)# Create a range of x values for plottingx = np.linspace(0, 20, 1000)# Plot chi-squared distributions for each degree of freedomplt.figure(figsize=(10, 6))for k in degrees_of_freedom: plt.plot(x, chi2.pdf(x, k), label=f'df = {k}')plt.title('Chi-Squared Distributions for Degrees of Freedom from 1 to 10')plt.xlabel('Value')plt.ylabel('Probability Density')plt.legend(title='Degrees of Freedom')plt.grid(True)plt.show()
t distribution vs normal distribution
# Set up a range for x values to cover enough area for both distributionsx_range = np.linspace(-5, 5, 1000)# Compute the probability density functions for a t-distribution with 10 degrees of freedom and a normal distributiont_distribution = t.pdf(x_range, df=10)normal_distribution = norm.pdf(x_range)# Plot both distributions for comparisonplt.figure(figsize=(10, 6))plt.plot(x_range, t_distribution, label='Student\\'s t-distribution, df=10')plt.plot(x_range, normal_distribution, label='Normal distribution')plt.title('Comparison of Student\\'s t-Distribution and Normal Distribution')plt.xlabel('Value')plt.ylabel('Probability Density')plt.legend()plt.grid(True)plt.show()
Sigmoid function
# Define the sigmoid functiondefsigmoid(x):return1/ (1+ np.exp(-x))# Set up a range for x values to display the sigmoid curvex_values = np.linspace(-10, 10, 400)# Compute the sigmoid function for these x valuessigmoid_values = sigmoid(x_values)# Plot the sigmoid functionplt.figure(figsize=(10, 6))plt.plot(x_values, sigmoid_values, label='Sigmoid Function', color='blue')plt.title('Sigmoid Function')plt.xlabel('x')plt.ylabel('S(x)')plt.grid(True)plt.ylim(-0.1, 1.1) # Extend y-axis to show the asymptotic behavior clearlyplt.axhline(y=0, color='black',linewidth=0.5)plt.axhline(y=1, color='black',linewidth=0.5)plt.axvline(x=0, color='black',linewidth=0.5)plt.show()
You cannot copy content of this page
Manage Consent
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional
Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.