コード例 #1
0
ファイル: relay_soln.py プロジェクト: vaneeshdass/ThinkStat2
def main():
    results = relay.ReadResults()
    speeds = relay.GetSpeeds(results)
    speeds = relay.BinData(speeds, 3, 12, 100)

    # plot the distribution of actual speeds
    pmf = thinkstats2.Pmf(speeds, 'actual speeds')

    # plot the biased distribution seen by the observer
    biased = ObservedPmf(pmf, 7.5, label='observed speeds')

    thinkplot.Pmf(biased)
    thinkplot.Save(root='observed_speeds',
                   title='PMF of running speed',
                   xlabel='speed (mph)',
                   ylabel='PMF')

    cdf = thinkstats2.Cdf(pmf)
    cdf_biased = thinkstats2.Cdf(biased)

    thinkplot.PrePlot(2)
    thinkplot.Cdfs([cdf, cdf_biased])
    thinkplot.Save(root='observed_speeds_cdf',
                   title='CDF of running speed',
                   xlabel='speed (mph)',
                   ylabel='CDF')
コード例 #2
0
def main():
    #cdf, place = total_percentile_rank(results)
    speeds = relay.GetSpeeds(results)
    speed = relay.ConvertPaceToSpeed('6:53')
    cdf = Cdf.MakeCdfFromList(speeds)
    print cdf.Prob(speed),'speed'
    print convert_speeds_to_time(speed),'time'
    myplot.Cdf(cdf)
    myplot.Show()
    
    speeds_old = GetSpeeds_M4049(results)
    cdf_old = Cdf.MakeCdfFromList(speeds_old)
    rank = cdf_old.Prob(speed)
    print rank,'rank', speed,'speed'
    print convert_speeds_to_time(speed),'time'
    myplot.Cdf(cdf_old)
    myplot.Show()
    
    speeds_5059 = GetSpeeds_M5059(results)
    cdf_5059 = Cdf.MakeCdfFromList(speeds_5059)
    future_speed = cdf_5059.Value(rank)
    print future_speed,'speed'
    print convert_speeds_to_time(future_speed),'time'
    myplot.Cdf(cdf_5059)
    myplot.Show()
   
    fspeeds = GetSpeeds_F2039(results)
    cdf_female = Cdf.MakeCdfFromList(fspeeds)
    fspeed = cdf_female.Value(rank)
    print fspeed,'speed'
    print convert_speeds_to_time(fspeed),'time'
    myplot.Cdf(cdf_female)
    myplot.Show()
コード例 #3
0
def main():
    results = relay.ReadResults()
    speeds = relay.GetSpeeds(results)

    # plot the distribution of actual speeds
    pmf = Pmf.MakePmfFromList(speeds, 'actual speeds')

    # myplot.Clf()
    # myplot.Hist(pmf)
    # myplot.Save(root='observed_speeds',
    #             title='PMF of running speed',
    #             xlabel='speed (mph)',
    #             ylabel='probability')

    # plot the biased distribution seen by the observer
    biased = BiasPmf(pmf, 7.5, name='observed speeds')

    myplot.Clf()
    myplot.Hist(biased)
    myplot.Save(root='observed_speeds',
                title='PMF of running speed',
                xlabel='speed (mph)',
                ylabel='probability')

    cdf = Cdf.MakeCdfFromPmf(biased)

    myplot.Clf()
    myplot.Cdf(cdf)
    myplot.show(root='observed_speeds_cdf',
                title='CDF of running speed',
                xlabel='speed (mph)',
                ylabel='cumulative probability')
コード例 #4
0
ファイル: Chapter 3.5.py プロジェクト: loftina/ThinkStats
def main():

    #Exercise 3.5
    results = relay.ReadResults()
    speeds = relay.GetSpeeds(results)
    speedsCdf = Cdf.MakeCdfFromList(speeds, "race speeds")
    mplt.Cdf(speedsCdf)
    mplt.show(title="Race Speed CDF",
              xlabel="speed in mph",
              ylabel="probability")
コード例 #5
0
def main():
    results = relay.ReadResults()
    speeds = relay.GetSpeeds(results)

    # plot the distribution of actual speeds
    cdf = Cdf.MakeCdfFromList(speeds, 'speeds')
    myplot.Cdf(cdf,
               title='CDF of running speed',
               xlabel='speed (mph)',
               ylabel='probability',
               show=True)
コード例 #6
0
def main():
    results = relay.ReadResults()
    speeds = relay.GetSpeeds(results)
    pmf = Pmf.MakePmfFromList(speeds, 'actual speeds')

    observed = BiasPmf(pmf, 7.5, 'observed speeds')
    myplot.Clf()
    myplot.Hist(observed)
    myplot.Show(title='observed speeds',
                xlabel='speed (mph)',
                ylabel='probability')
コード例 #7
0
def main():
    results = relay.ReadResults()
    speeds = relay.GetSpeeds(results)
    pmf = Pmf.MakePmfFromList(speeds, 'speeds')
    pmf = BiasPmf(7,pmf)
    myplot.Hist(pmf)
    #myplot.Show(title='PMF of observed speed',
    #           xlabel='speed (mph)',
    #           ylabel='probability')
    myplot.Save(
                formats=['png'],
                root='runner',
                title='PMF of observed speed',
               xlabel='speed (mph)',
               ylabel='probability')
コード例 #8
0
def main():
    # Exercise 3.1
    d = {
        7: 8,
        12: 8,
        17: 14,
        22: 4,
        27: 6,
        32: 12,
        37: 8,
        42: 3,
        47: 2
    }

    classSizeDean = Pmf.MakePmfFromDict(d, name='Actual')
    print(classSizeDean.Mean())

    classSizeStudent = classSizeDean.Copy(name='Student Perspective')
    for x, _ in classSizeStudent.Items():
        classSizeStudent.Mult(x, x)
    classSizeStudent.Normalize()
    print(classSizeStudent.Mean())

    classSizeUnbaised = UnbiasPmf(classSizeStudent, 'Student Unbiased')
    print(classSizeUnbaised.Mean())

    getValue = itemgetter(0)

    deanPlot = sorted(classSizeDean.Items(), key=getValue)
    studentPlot = sorted(classSizeStudent.Items(), key=getValue)
    plt.plot(zip(*deanPlot)[0], zip(*deanPlot)[1], 'g-', label='Actual')
    plt.plot(zip(*studentPlot)[0], zip(*studentPlot)[1], 'r-', label='Student Perspective')
    plt.legend(loc=4)
    plt.xlabel('Class Size')
    plt.ylabel('Probability')
    plt.show()

    #Exercise 3.2
    results = relay.ReadResults()
    speeds = relay.GetSpeeds(results)
    unbaisedSpeedsPmf = Pmf.MakePmfFromList(speeds, 'speeds')
    biasedSpeedsPmf = BiasPmf(unbaisedSpeedsPmf, 7.5, '7.5 mph biased speeds')

    biasedPlot = sorted(biasedSpeedsPmf.Items(), key=getValue)
    myplot.Pmf(biasedSpeedsPmf)
    myplot.Show(title='7.5mph biased speeds',
                xlabel='speeds (mph)',
                ylabel='probability')
コード例 #9
0
def main():
    results = relay.ReadResults()
    speeds = relay.GetSpeeds(results)
    rankit.MakeNormalPlot(speeds, root='relay_normal', ylabel='Speed (MPH)')
コード例 #10
0
 def __init__(self):
     results = relay.ReadResults()
     speeds = relay.GetSpeeds(results)
     self.speeds = speeds
     self.pmf = Pmf.MakePmfFromList(speeds)
コード例 #11
0
ファイル: ch3-5.py プロジェクト: cbuie/thinkstats
import relay
import Cdf
import Pmf
import myplot

speeds = relay.GetSpeeds(relay.ReadResults())

pmf = Pmf.MakePmfFromList(speeds)
cdf = Cdf.MakeCdfFromList(speeds)

myplot.Pmf(pmf)
myplot.Cdf(cdf)

myplot.Show(title='PMF vs CDF of running speeds',
            xlabel='speed (mph)',
            ylabel='probability')
コード例 #12
0
ファイル: ch4-ex10.py プロジェクト: cbuie/thinkstats
import math
import myplot
import numpy
import relay

results = relay.ReadResults()
speeds = relay.GetSpeeds(results)
xs = sorted(numpy.random.normal(0, 1, len(speeds)))
ys = sorted(speeds)
myplot.Plot(xs, ys)
myplot.Show(title="Normal Plot for Running Speeds")