0% found this document useful (0 votes)
35 views2 pages

8.1 Probability and Statistics 8 - Cumulative Distribution Function

The document discusses cumulative distribution functions and provides an example of calculating the CDF of exam marks data. It generates the probability density function and cumulative distribution function of the marks data, and calculates some cumulative probabilities like the probability of scores below or between certain values.

Uploaded by

luckypooo55
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views2 pages

8.1 Probability and Statistics 8 - Cumulative Distribution Function

The document discusses cumulative distribution functions and provides an example of calculating the CDF of exam marks data. It generates the probability density function and cumulative distribution function of the marks data, and calculates some cumulative probabilities like the probability of scores below or between certain values.

Uploaded by

luckypooo55
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

8.

Cumulative Distribution Function


Cumulative distribution function : A CDF is used to determine the cumulative probability of all values below a value in a
distribution.

The cumulative distribution function is used to evaluate probability as area under the PDF curve.

Example: Cumulative Distributive function


import pandas as pd
import scipy.stats as stats
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt

lst=[60, 61, 62, 63, 64, 65,66,66.12,66.14,66.20,66.25,66.75,66.85,67, 68, 69, 70, 71, 72,73]
# lst=[60, 61, 62, 63, 64, 65, 66, 66.12,66,66,66,66,66, 67, 68, 69, 70, 71, 72, 73]
# lst=[30, 45, 60, 90, 120, 150, 180]

lst=sorted (lst)

df=pd.DataFrame (lst, columns=["Marks"])

df.Marks.describe()
count 20.000000
mean 66.465500
std 3.464768
min 60.000000
25% 64.750000
50% 66.225000
75% 68.250000
max 73.000000
Name: Marks, dtype: float64

# Probability Density function

pd_fx=stats.norm.pdf (lst,loc=np.mean(df ["Marks"]), scale=np.std(df["Marks"]))


plt.plot(lst, pd_fx)
plt.plot(lst, pd_fx,'-o', label='PDF')

# Cumulative Distribution function

cd_fx=stats.norm.cdf (lst,loc=np.mean(df["Marks"]), scale=np.std(df["Marks"]))


plt.plot (lst, cd_fx)
plt.plot (lst, cd_fx,'-o', label='CDF')
plt.xlabel("Random variable values")
plt.ylabel("Probability")
plt.title("PDF and CDF of a Random Variable")
plt.legend()
plt.savefig('pdf_cdf.png')

#plt.hist(lst, density=True) # use this to draw histogram of your data

plt.show()

fx=stats.norm(loc=np.mean(lst), scale=np. std (lst))

print (lst)

a=66

print("\n 1. Cumulative probability of all the values untill",a,"is",fx.cdf(a))

print("\n 2. Cumulative probability of all the values untill mean",np.mean(lst),"is",fx.cdf(np.mean(lst)))

x=64
y=70

print("\n 3. Probability of finding a value between",x, "and",y,"is",fx.cdf(y)-fx.cdf(x))

x=66.14
y=66.25

print("\n 4. Probability of finding a value 66 is the difference of cumulative probabilities \


between value",x,"and",y ,fx.cdf(y)-fx.cdf(x))

[60, 61, 62, 63, 64, 65, 66, 66.12, 66.14, 66.2, 66.25, 66.75, 66.85, 67, 68, 69, 70, 71, 72, 73]

1. Cumulative probability of all the values untill 66 is 0.44518237041070885

2. Cumulative probability of all the values untill mean 66.46549999999999 is 0.5

3. Probability of finding a value between 64 and 70 is 0.6196928963234725

4. Probability of finding a value 66 is the difference of cumulative probabilities between value 66.14 and 66.
25 0.012952527811829428

Loading [MathJax]/jax/output/CommonHTML/fonts/TeX/fontdata.js

You might also like