Calculation frequency:
Given a sequence T:
hist = {}
For x in T:
HIST[X] = Hist.get (x,0) +1
The result is a dictionary that maps the value to its frequency. Divide it by N to convert the frequency into frequencies, which is called normalization:
n = float (len (t))
PMF = {}
For X, freq in Hist.items ():
PMF[X] = freq/n
To draw a histogram:
Vals, Freqs = Hist. Render ()
rectangles = Pyplot.bar (Vals, Freqs)
Pyplot.show ()
To draw the probability mass function:
Using a histogram, you can use Pyplot.bar or myplot.hist. If the values in the PMF are not many, the histogram is more appropriate
Using a line chart, you can use Pyplot.plot or MYPLOT.PMF. If the values in the PMF are larger and smoother, the line chart is more appropriate.
* Percent Variance Chart
Visual display of the two sets of data distribution differences, see the textbook.
From statistical thinking-Programmer's mathematical probability statistics p15-p23
Draw a histogram with Python