Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as pl
- import seaborn as sn
- from scipy.stats import binom
- # A manifactures has 12% defects rate in production. The buyer decides to test 20 random pieces and will accept the supplier if there # are 2 or less defectives. What is the probability of getting accepted?
- production = np.random.binomial(20,0.12,1000)
- production
- sn.countplot(x=production)
- sn.set_theme(style = 'darkgrid')
- pl.title("Binomial Probability")
- pl.xlabel("Number of Defectives")
- pl.show()
- exact_two = binom.pmf(2,20,0.12)
- exact_two
- P_0_1_2 = binom.cdf(2,20,0.12)
- P_0_1_2
- more_than_two = 1 - binom.cdf(2,20,0.12)
- more_than_two
- binom.mean(20,0.12)
- binom.std(20,0.12)
- binom.var(20,0.12)
- # Plotting for exact number
- x_ax = np.arange(0,21)
- y_ax = binom.pmf(x_ax,20,0.12)
- sns.barplot(x = x_ax, y = y_ax)
- # Plotting with cumulative func
- y_ax2 = binom.cdf(x_ax,20,0.12)
- sns.barplot(x = x_ax, y= y_ax2)
Add Comment
Please, Sign In to add comment