Flashcards
3 MLBEYN Probability
Cards in this deck (39)
- 1Coin is flipped 10000 times. Create countplot of discrete distributions in seaborn (sns)X = np.random.choice(['heads', 'tails'], size=10000, replace=True)
sns.countplot(x=X)
plt.show() - 2Create a distribution from random integers 20 to 30. Repeat this operation in 1000 times. Create countplot in snsY=np.random.randint(20,30,size=10000)
sns.countplot(x=Y)
plt.show()
size=10000 means that it gives the result of 10000 figures - comprising from 20 to 30 (excl) - 3np.random.randint(20,35,size=1) What is the result?Result will be one random figure from the interval 20 to 35 (excl)
- 4np.random.choice([1/2, 1/3], size=10, replace=True) What is the result?Result be array of 10 numbers consisting 0.5 and 0.333
- 5Create an array comprising of 10 random numbers between 0 and 1 representing Bernoulli distr. (so out of zeros and ones) Probability of getting heads(1) make as 3/4(np.random.random(size=10) <= 3/4).astype(int)
- 6Explain this code (np.random.random(size=10) <= 3/4).astype(int)1. So, here np.random.random(size=10) creates an array of 10 random numbers between 0 and 1
2. then condition of <=3/4 returns an array of True and False. So if number is less than 0.75 it gives True and False otherwise
and astype(int) converts it to 0s and 1s - 7Explain np.random.binomial(p=0.5, n=10, size=1) in terms of coin flippingIt returns the result of array consisting of 1 number. This number describes the result of successes (number of heads)
- 8Explain np.random.binomial(p=0.5, n=1,size=10)It returns an array of 10 numbers consisting of 0s and 1s with probability of 0.5.
- 9Explain this np.random.binomial(p=1/3, n=100, size=10000)It will return an array of 10000 numbers between 0 and 100 (excluding). Each number represents number of successes with probability of 1/3
- 10Explain np.random.binomial(p=0.5, n=1,size=10).sum()It will return number of successes (sum of 1s) out of 10 trials
- 11create an array of 1000 numbers consisting of numbers between 20 and 60X = np.random.random(size=1000) * 40+ 20
(0*40+20;1*40+20) - 12What kind of distribution is presented in previous question and show it graphicallyX = np.random.random(size=1000) * 40 + 20
plt.hist(X)
plt.show() - 13Show normal distribution and graph it - sample size 5000 with mean of 2 and std of 3.5X = np.random.normal(size=5000, loc=2, scale=3.5)
plt.hist(X, bins=20)
plt.show() - 14Show lognormal distribution and graph it - sample size 10000 with mean of 0 and std of 0.5X = np.random.lognormal(size=10000, mean=0, sigma=0.5)
plt.hist(X, bins=20)
plt.show() - 15Explain lognormal distributionThis is the distribution of which logarithms of values have normal distributions.
plt.hist(np.log(X), bins=20)
plt.show() - so this distribution is normal - 16Explain what does this calculate stats.binom(p=3/4, n=5).pmf(2)This calculates:
choose (5,2) p^0.75*q^0.25=
5!/2!*3! - 17How else can you write above expression?stats.binom.pmf (p=3/4, n=5, k=2)
- 18Display distribution of pmf of the following binomial probability distribution: 10 trials with 0.3 probabilityx=np.arange(0,11)
P = stats.binom(p=1/3, n=10).pmf(x) - 19Display graph of pdf of normally distributed function (range between -10 and 25 with mean of 5 and std of 3)x = np.linspace(-10,25)
p = stats.norm(loc=5, scale=3).pdf(x)
plt.plot(x, p)
plt.show() - 20Show cdf of above functionx = np.linspace(-10,25)
c = stats.norm(loc=5, scale=3).cdf(x)
plt.plot(x, c)
plt.show() - 21X ~ N(mean=3, std=5) P(2.5 <= X <= 3.5) = ?stats.norm(loc=3, scale=5).cdf(3.5) - stats.norm(loc=3, scale=5).cdf(2.5)
- 22x=np.linspace(0,10,19) y=stats.binom(n=10, p=.2).cdf(x) what is the return of y?This returns array consisiting of probabliities of between 0 and 1 (in total 19 numbers)
- 23x=np.linspace(0,10,19) y=stats.binom(n=10, p=.2).cdf(x) Explain relation of y with the following a=stats.binom(p=0.2, n=10).pmf(n)For example, y[2] = 0.37580964
This equals
stats.binom(p=0.2, n=10).pmf(0)+
stats.binom(p=0.2, n=10).pmf(1)
which means that this is the probability of getting less than or equal to 2 heads out of 10 coin flipping - 24my_cdf = np.vectorize(lambda x: (stats.norm(loc=4, scale=.7).cdf(x) + stats.norm(loc=10, scale=1).cdf(x)) / 2) x = np.linspace(0, 15) c = my_cdf(x) Explain what is happeing above?lambda x - this is just creatting function with an argument and assigning it to my_cdf.
So basically this is def(my_cdf(x)): and then writing ingredients
After that x is givena and my_cdf(x) is assigned to c.
stats.norm(loc=4, scale=.7).cdf(x) +... - this is the form of creating targert cdf
function
np.vectorize turns inside of expression into an array - 25Explain what is written below. u = np.random.random() v = optimize.bisect(lambda x: my_cdf(x) - u, 0, 20)u is uniform distribution of random variables.
optimize.bisect tries to find such x-s that when plugging into cdf will give the result of u.
That is why it soves the question my_cdf-u=0.
bisect may be true for ascending or descending functions - 26write later checking of bisectionwrite later checking of bisection
- 27write later checking of bisectionwrite later checking of bisection
- 28write later checking of bisectionwrite later checking of bisection
- 29checking of bisectionchecking of bisection
- 30Write the formula of BayesP(A|B) = P(B|A )* P(A) / P(B)
- 31P(default)-1% P(predict-default) - 3% P(predict-default|default) - 99% P(default | predict-default) - ?P(default | predict-default) - = 1%*3%/99%=33%
- 32for the likelihood func explanfor the likelihood func explan
- 33for the likelihood func explanfor the likelihood func explan
- 34for the likelihood func explanfor the likelihood func explan
- 35for the likelihood func explanfor the likelihood func explan
- 36for the likelihood func explanfor the likelihood func explan
- 37define experiment for random variable with probability of p, number of trials of n and iterations of Ndef experiment(p,n,N):
return np.random.binomial (n=n, p=p, size=N) - 38Write the function which returns log likelihood of probability mass function (using special.binom)def single_log_likelihood(p,n_heads,n_tails):
n=n_heads+n_tails
return np.log(scipy.special.binom(n,n_heads))*p**n_heads*(1-p)**n_tails - 39Write the def single_log_likelihood(p,n_heads,n_tails): n=n_heads+n_tails return np.log(scipy.special.binom(n,n_heads))*p**n_heads*(1-p)**n_tails using stats packagedef sing-log2(p,n_heads, n_tails):
n=n_heads+n_tails
return np.log(stats.binom(p=p,n=n).pmf(n_heads))
Information
- Description
- Easy DS Flashcards on 3 MLBEYN Probability, created by Archimed Nemes on 06/01/2021.
- Created by
- Archimed Nemes
- Views
- 1
- Rating