In: Computer Science
Program in python an example code for the random variable (Bernoulli distribution), where the user informs the data and parameters necessary to generate the cumulative distribution function (CDF.)
from scipy.stats import bernoulli as br
import matplotlib.pyplot as plt
print("give the value's of probability of getting success(0-1): ")
prob = float(input())
#find the statistical values
mean, variance, skewness, kurtosis = br.stats(prob, moments = 'mvsk')
#it will print the mean
print("mean = ", mean)
#it will print the variance
print("Variance = ", variance)
#it will print the Skewnes
print("Skewness = ", skewness)
# it will print the kurtosis
print("kurtosis = ", kurtosis)
output screen:
mean = br.mean(prob)
#get standard deviation
std = br.std(prob)
#plotting the cdf
z = [0, 1]
print("CDF = ", br.cdf(z, prob))
plt.scatter(z, br.cdf(z, prob), label = "CDF",marker='*',color='r')
plt.title("CDF")
plt.xlabel("Data point")
plt.ylabel("probability")
plt.legend()
plt.show()
output screen :
if
you have any doubts regarding this question than feel free to ask
.