Skip to content

Ch04 "Doing the Work Yourself": typo in code #6

Description

@nobutoba

I'm having fun reading your book and found a small typo (the code does not acctually appear in your GitHub repo, though).

In fact, the function open_rate_with_factor_change defined on p.123 does not work as expected. One way to fix this is to change the following code:

    num_opened = np.zeros(len(period_rng))
    for prd in range(0, len(period_rng), 2): 
        try:
            n, p = NUM_EMAILS_SENT_WEEKLY, np.random.uniform(0,
                                                             1)
            num_opened[prd: (prd + 2)] = np.random.binomial(n, p,
                                                            2)
            p = max(min(1, p * fac), 0)
        except:
            num_opened[prd] = np.random.binomial(n, p, 1)

into something like:

    num_opened = np.zeros(len(period_rng))
    n, p = NUM_EMAILS_SENT_WEEKLY, np.random.uniform(0,
                                                     1)
    for prd in range(0, len(period_rng), 2): 
        try:
            num_opened[prd: (prd + 2)] = np.random.binomial(n, p,
                                                            2)
            p = max(min(1, p * fac), 0)
        except:
            num_opened[prd] = np.random.binomial(n, p, 1)

The point here is that random sampling of the probability p should occur outside of the for loop, in order for the increasing or decreasing of email open rate acctually takes place.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions