| Download
Think Stats by Allen B. Downey Think Stats is an introduction to Probability and Statistics for Python programmers.
This is the accompanying code for this book.
Project: Support and Testing
Views: 7115License: GPL3
"""This file contains code used in "Think Stats",1by Allen B. Downey, available from greenteapress.com23Copyright 2014 Allen B. Downey4License: GNU GPLv3 http://www.gnu.org/licenses/gpl.html5"""67import sys89import thinkstats210import thinkplot111213def ReadFile(filename):14"""Reads a list of numbers from a file.1516filename: string1718returns: list of float19"""20fp = open(filename)21data = []22for line in fp:23x = float(line.strip())24data.append(x)25return data262728def main(script, filename='mystery0.dat'):29data = ReadFile(filename)30cdf = thinkstats2.Cdf(data)3132thinkplot.PrePlot(num=6, rows=2, cols=3)33thinkplot.SubPlot(1)34thinkplot.Cdf(cdf, color='C0', label=filename)35thinkplot.Config(title='CDF on linear scale', ylabel='CDF')3637thinkplot.SubPlot(2)38scale = thinkplot.Cdf(cdf, xscale='log', color='C0')39thinkplot.Config(title='CDF on log-x scale', ylabel='CDF', **scale)4041thinkplot.SubPlot(3)42scale = thinkplot.Cdf(cdf, transform='exponential', color='C0')43thinkplot.Config(title='CCDF on log-y scale', ylabel='log CCDF', **scale)4445thinkplot.SubPlot(4)46xs, ys = thinkstats2.NormalProbability(data)47thinkplot.Plot(xs, ys, color='C0')48thinkplot.Config(title='Normal probability plot',49xlabel='random normal', ylabel='data')5051thinkplot.SubPlot(5)52scale = thinkplot.Cdf(cdf, transform='pareto', color='C0')53thinkplot.Config(title='CCDF on log-log scale', ylabel='log CCDF', **scale)5455thinkplot.SubPlot(6)56scale = thinkplot.Cdf(cdf, transform='weibull', color='C0')57thinkplot.Config(title='CCDF on loglog-y log-x scale',58ylabel='log log CCDF', **scale)5960thinkplot.Show(legend=False)616263if __name__ == '__main__':64main(*sys.argv)656667