Question
I need to make a python program to plot a binominal probability distribution. I have done a lot I need to plot probability mass function
I need to make a python program to plot a binominal probability distribution. I have done a lot
I need to plot probability mass function (pdf) and cumulative distribution function (cdf) I have looked at the documentation for scipy and saw an example:
import numpy as np from scipy.stats import binom import matplotlib.pyplot as plt
fig, ax = plt.subplots(1, 1) # Why is this necessary to get a plot? If i comment away, no output and no error either
n = int(input("How many trials? : ")) #number of trials assigned to variable n, converted to integer. I understand this (made it myself) p = float(input("Enter the probability for succes, decimal between 0 and 1, not including 0 and 1 ")) # probability of success assigned to variable p, converted to float, also OK
# Display the probability mass function (pmf) with the given n and p. I need to be explained some things in the code under
x = np.arange(binom.ppf(0.01, n, p), # The numbers 0.01 and 0.99, what does these numbers refer to? binom.ppf(0.99, n, p)) # What does ppf refer to? ax.plot(x, binom.pmf(x, n, p), 'bo', ms=8, label='binom pmf') # How the plots looks I guess ax.vlines(x, 0, binom.pmf(x, n, p), colors='b', lw=5, alpha=0.5)
Running this I get a nice plot. It's working
Next, I need to do the same with cumulative distribution function (cdf)
Tried simplyto change pmf to cdf,
x = np.arange(binom.ppf(0.01, n, p), binom.ppf(0.99, n, p)) ax.plot(x, binom.cdf(x, n, p), 'bo', ms=8, label='binom pmf') ax.vlines(x, 0, binom.cdf(x, n, p), colors='b', lw=5, alpha=0.5) Running this I get a nice plot which looked correct It's working too. So far so good
I need now (in my assigment) to use numpy.arange(n+1) to make an array to calculate probability "all in one" that is, for all x ; 1,2,3,4...n. Now I am stuck.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started