GoConqr has a new look! Let us know what you think.

Flashcards

3 MLBEYN Probability

Archimed Nemes DS Easy English 39 cards

Cards in this deck (39)

  1. 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()
  2. 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)
  3. 3np.random.randint(20,35,size=1) What is the result?Result will be one random figure from the interval 20 to 35 (excl)
  4. 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
  5. 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)
  6. 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
  7. 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)
  8. 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.
  9. 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
  10. 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
  11. 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)
  12. 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()
  13. 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()
  14. 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()
  15. 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
  16. 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!
  17. 17How else can you write above expression?stats.binom.pmf (p=3/4, n=5, k=2)
  18. 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)
  19. 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()
  20. 20Show cdf of above functionx = np.linspace(-10,25)
    c = stats.norm(loc=5, scale=3).cdf(x)
    plt.plot(x, c)
    plt.show()
  21. 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)
  22. 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)
  23. 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
  24. 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
  25. 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
  26. 26write later checking of bisectionwrite later checking of bisection
  27. 27write later checking of bisectionwrite later checking of bisection
  28. 28write later checking of bisectionwrite later checking of bisection
  29. 29checking of bisectionchecking of bisection
  30. 30Write the formula of BayesP(A|B) = P(B|A )* P(A) / P(B)
  31. 31P(default)-1% P(predict-default) - 3% P(predict-default|default) - 99% P(default | predict-default) - ?P(default | predict-default) - = 1%*3%/99%=33%
  32. 32for the likelihood func explanfor the likelihood func explan
  33. 33for the likelihood func explanfor the likelihood func explan
  34. 34for the likelihood func explanfor the likelihood func explan
  35. 35for the likelihood func explanfor the likelihood func explan
  36. 36for the likelihood func explanfor the likelihood func explan
  37. 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)
  38. 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
  39. 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

Feedback

What is it about?

What do you think of the new look?

How do you like it?