Uniform distribution Example You arrive into a building and are about to take an elevator to the your floor. Once you call the elevator, it will take between 0 and 40 seconds to arrive to you. We will assume that the elevator arrives uniformly between 0 and 40 seconds after you press the button. In this case a = 0 and b = 40. Calculating probabilities From any continuous probability density function we can calculate probabilities by using integration: In our example, to calculate the probability that elevator takes less than 15 seconds to arrive we set d = 15 and c = 0. The correct probability is 15/40. Expected Value The expected value of a uniform distribution is: In our example, the expected value is (40-0)/2 = 20 sec Variance The variance of a uniform distribution is: In our example, the variance is (40-0)^2/12 = 400/3 Bernoulli distribution PMF = [0.4 0.6] Example A simple example can be a single toss of a biased / unbiased coin. In the case of flipping an unbiased or fair coin, the value of p would be 0.5, giving a 50% probability of each outcome. However we must note that the probabilities of success and failure need not be equal all the time, like Bernoulli distribution in the case of a biased coin flip where probability of heads (success) is 0.6 while probability of tails (failure) is 0.4. Lets see this second case: Calculating probabilities We can suppose a total 100 trials with success probability 0.6, we get about 60 successes which is the same to %60 success. Expected Value The expected value of a uniform distribution is: In our example, the expected value is 60% success. Variance The variance of a Bernoulli distribution is: In our example, the variance is 0,6(0,4) = 0,24 Logistic distribution Difference between the normal and logistic density distribution The difference is that the logistic distribution is heavier and it has more area under it because its longer tails. Two parameters define the shape of the distribution: The location parameter (m) tells you where it’s centered on the x-axis. The scale parameter (s) tells you what the spread is. A scale parameter stretches or squeezes a graph. In the CDF, s is a scale parameter proportional to the standard deviation. In [299... # for inline plots in jupyter %matplotlib inline In [300... # import matplotlib import matplotlib.pyplot as plt In [301... # import numpy import numpy as np In [302... # import seaborn import seaborn as sns In [317... # import uniform distribution from scipy.stats import uniform fig, ax = plt subplots(1, 1) # genrating uniform distribution uniform_distribution = uniform rvs(0, 1, 1000) # a= 0, b= 1, size = 1000 # plotting distribution ax hist(uniform_distribution, density = True , histtype = 'stepfilled', alpha = 0.2) # plotting PDF x = np linspace(uniform ppf(0.01),uniform ppf(0.99), 1000) pdf = uniform pdf(x) ax plot(x, pdf, 'r-', lw = 5, alpha = 0.6, label = 'PDF') # Plotting CDF cdf = uniform cdf(x) ax plot(x, cdf, 'k-', lw = 2, label = 'CDF') ax legend(loc = 'best', frameon = False ) plt title('Continuous uniform distribution') plt xlabel('Continous random variable') plt ylabel('Probability') plt show() In [304... # import Bernoulli distribution from scipy.stats import bernoulli In [305... # get probability mass function (PMF) x = [0,1] p = 0.6 print ('PMF = ', bernoulli pmf(x,p)) In [306... # plot the graph for PMF plt bar(x, bernoulli pmf(x,p), label = 'PMF') plt title('Bernoulli PMF') plt xlabel('Discrete random variable') plt ylabel('Probability') plt legend() plt show() In [307... # plot the CDF plt scatter(x, bernoulli cdf(x,p), label = 'CDF') plt title('Bernoulli CDF') plt xlabel('Discrete random variable') plt ylabel('Probability') plt legend() plt show() In [241... # import logistic distribution from scipy.stats import logistic In [318... # we will plot a displot here sns displot(np random normal(loc = 50, scale = 4, size = 500), kind = 'kde', color = 'blue', label = 'normal' ) plt title('Normal PDF') plt xlabel('Continuous random variable') plt ylabel('Probability') # we will plot a displot here sns displot(np random logistic(loc = 1, scale = 3, size = 5), kind = 'kde', color = 'red', label = 'logistic' ) # now we have the plot printed plt title('Logistic PDF') plt xlabel('Continuous random variable') plt ylabel('Probability') plt show() In [344... # display the PDF: x = np linspace(logistic ppf(0.01), logistic ppf(0.99), 100) lg1 = logistic pdf(x, loc = 0, scale = 0.5) lg2 = logistic pdf(x, loc = 0, scale = 1) lg3 = logistic pdf(x, loc = 1, scale = 0.6) lg4 = logistic pdf(x, loc = 1, scale = 1.3) In [345... # plot the graph for PMF: fig, ax = plt subplots(1, 1, figsize = (10,6)) ax plot(x, lg1, color = 'green', ls = '-', label = 'm=0, s=1.0') ax plot(x, lg2, color = 'black', ls = ':', label = 'm=0, s=0.7') ax plot(x, lg3, color = 'red', ls = '--', label = 'm=1, s=1.0') ax plot(x, lg4, color = 'blue', ls = '-.', label = 'm=1, s=0.4') plt title('Logistic PDF') plt xlabel('Continuous random variable') plt ylabel('Probability') plt legend(loc = 5) plt show() In [339... # display the CDF: x = np linspace(logistic ppf(0.01), logistic ppf(0.99), 100) lg1 = logistic cdf(x, loc = 0, scale = 0.5) lg2 = logistic cdf(x, loc = 0, scale = 1) lg3 = logistic cdf(x, loc = 1, scale = 0.6) lg4 = logistic cdf(x, loc = 1, scale = 1.3) In [321... # plot the graph for CDF: fig, ax = plt subplots(1, 1, figsize = (10,6)) ax plot(x, lg1, color = 'green', ls = '-', label = 'm=0, s=1.0') ax plot(x, lg2, color = 'black', ls = ':', label = 'm=0, s=0.7') ax plot(x, lg3, color = 'red', ls = '--', label = 'm=1, s=1.0') ax plot(x, lg4, color = 'blue', ls = '-.', label = 'm=1, s=0.4') plt title('Logistic CDF') plt xlabel('Continuous random variable') plt ylabel('Probability') plt legend(loc = 5) plt show()